Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 208032f

Browse files
committed
[OptionsResolver] Merged Options class into OptionsResolver
1 parent 453882c commit 208032f

15 files changed

+2846
-1026
lines changed

UPGRADE-2.6.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,184 @@ HttpFoundation
128128
- You would need to migrate the table manually if you want to keep session information of your users.
129129
- You could use `PdoSessionHandler::createTable` to initialize a correctly defined table depending on
130130
the used database vendor.
131+
132+
OptionsResolver
133+
---------------
134+
135+
* The "array" type hint was removed from the `OptionsResolverInterface` methods
136+
`setRequired()`, `setAllowedValues()`, `addAllowedValues()`,
137+
`setAllowedTypes()` and `addAllowedTypes()`. You must remove the type hint
138+
from your implementations.
139+
140+
* The interface `OptionsResolverInterface` was deprecated, since
141+
`OptionsResolver` instances are not supposed to be shared between classes.
142+
You should type hint against `OptionsResolver` instead.
143+
144+
Before:
145+
146+
```php
147+
protected function configureOptions(OptionsResolverInterface $resolver)
148+
{
149+
// ...
150+
}
151+
```
152+
153+
After:
154+
155+
```php
156+
protected function configureOptions(OptionsResolver $resolver)
157+
{
158+
// ...
159+
}
160+
```
161+
162+
* `OptionsResolver::isRequired()` now returns `true` if a required option has
163+
a default value set. The new method `isMissing()` exhibits the old
164+
functionality of `isRequired()`.
165+
166+
Before:
167+
168+
```php
169+
$resolver->setRequired(array('port'));
170+
171+
$resolver->isRequired('port');
172+
// => true
173+
174+
$resolver->setDefaults(array('port' => 25));
175+
176+
$resolver->isRequired('port');
177+
// => false
178+
```
179+
180+
After:
181+
182+
```php
183+
$resolver->setRequired(array('port'));
184+
185+
$resolver->isRequired('port');
186+
// => true
187+
$resolver->isMissing('port');
188+
// => true
189+
190+
$resolver->setDefaults(array('port' => 25));
191+
192+
$resolver->isRequired('port');
193+
// => true
194+
$resolver->isMissing('port');
195+
// => false
196+
```
197+
198+
* `OptionsResolver::replaceDefaults()` was deprecated. Use `clear()` and
199+
`setDefaults()` instead.
200+
201+
Before:
202+
203+
```php
204+
$resolver->replaceDefaults(array(
205+
'port' => 25,
206+
));
207+
```
208+
209+
After:
210+
211+
```php
212+
$resolver->clear();
213+
$resolver->setDefaults(array(
214+
'port' => 25,
215+
));
216+
```
217+
218+
* `OptionsResolver::setOptional()` was deprecated. Use `setDefined()` instead.
219+
220+
Before:
221+
222+
```php
223+
$resolver->setOptional(array('port'));
224+
```
225+
226+
After:
227+
228+
```php
229+
$resolver->setDefined('port');
230+
```
231+
232+
* `OptionsResolver::isKnown()` was deprecated. Use `isDefined()` instead.
233+
234+
Before:
235+
236+
```php
237+
if ($resolver->isKnown('port')) {
238+
// ...
239+
}
240+
```
241+
242+
After:
243+
244+
```php
245+
if ($resolver->isDefined('port')) {
246+
// ...
247+
}
248+
```
249+
250+
* The methods `setAllowedValues()`, `addAllowedValues()`, `setAllowedTypes()`
251+
and `addAllowedTypes()` were changed to modify one option at a time instead
252+
of batch processing options. The old API exists for backwards compatibility,
253+
but will be removed in Symfony 3.0.
254+
255+
Before:
256+
257+
```php
258+
$resolver->setAllowedValues(array(
259+
'method' => array('POST', 'GET'),
260+
));
261+
```
262+
263+
After:
264+
265+
```php
266+
$resolver->setAllowedValues('method', array('POST', 'GET'));
267+
```
268+
269+
* The class `Options` was merged into `OptionsResolver`. If you instantiated
270+
this class manually, you should instantiate `OptionsResolver` now.
271+
`Options` is now a marker interface implemented by `OptionsResolver`.
272+
273+
Before:
274+
275+
```php
276+
$options = new Options();
277+
```
278+
279+
After:
280+
281+
```php
282+
$resolver = new OptionsResolver();
283+
```
284+
285+
* Normalizers for defined but unset options are not executed anymore. If you
286+
want to have them executed, you should define a default value.
287+
288+
Before:
289+
290+
```php
291+
$resolver->setOptional(array('port'));
292+
$resolver->setNormalizers(array(
293+
'port' => function ($options, $value) {
294+
// return normalized value
295+
}
296+
));
297+
298+
$options = $resolver->resolve($options);
299+
```
300+
301+
Before:
302+
303+
```php
304+
$resolver->setDefault('port', null);
305+
$resolver->setNormalizer('port', function ($options, $value) {
306+
// return normalized value
307+
});
308+
309+
$options = $resolver->resolve($options);
310+
```
311+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CHANGELOG
2+
=========
3+
4+
2.6.0
5+
-----
6+
7+
* deprecated OptionsResolverInterface
8+
* [BC BREAK] removed "array" type hint from OptionsResolverInterface methods
9+
setRequired(), setAllowedValues(), addAllowedValues(), setAllowedTypes() and
10+
addAllowedTypes()
11+
* added OptionsResolver::setDefault()
12+
* added OptionsResolver::hasDefault()
13+
* added OptionsResolver::setNormalizer()
14+
* added OptionsResolver::hasNormalizer()
15+
* added OptionsResolver::getNormalizedOptions()
16+
* added OptionsResolver::isRequired()
17+
* added OptionsResolver::getRequiredOptions()
18+
* added OptionsResolver::isMissing()
19+
* added OptionsResolver::getMissingOptions()
20+
* added OptionsResolver::setDefined()
21+
* added OptionsResolver::isDefined()
22+
* added OptionsResolver::getDefinedOptions()
23+
* added OptionsResolver::remove()
24+
* added OptionsResolver::clear()
25+
* deprecated OptionsResolver::replaceDefaults()
26+
* deprecated OptionsResolver::setOptional() in favor of setDefined()
27+
* deprecated OptionsResolver::isKnown() in favor of isDefined()
28+
* [BC BREAK] OptionsResolver::isRequired() returns true now if a required
29+
option has a default value set
30+
* [BC BREAK] merged Options into OptionsResolver and turned Options into an
31+
interface
32+
* deprecated Options::overload() (now in OptionsResolver)
33+
* deprecated Options::set() (now in OptionsResolver)
34+
* deprecated Options::get() (now in OptionsResolver)
35+
* deprecated Options::has() (now in OptionsResolver)
36+
* deprecated Options::replace() (now in OptionsResolver)
37+
* [BC BREAK] Options::get() (now in OptionsResolver) can only be used within
38+
lazy option/normalizer closures now
39+
* [BC BREAK] removed Traversable interface from Options since using within
40+
lazy option/normalizer closures resulted in exceptions
41+
* [BC BREAK] removed Options::all() since using within lazy option/normalizer
42+
closures resulted in exceptions
43+
* [BC BREAK] OptionDefinitionException now extends LogicException instead of
44+
RuntimeException
45+
* [BC BREAK] normalizers are not executed anymore for unset options
46+
* normalizers are executed after validating the options now
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\OptionsResolver\Exception;
13+
14+
/**
15+
* Thrown when trying to read an option outside of or write it inside of
16+
* {@link Options::resolve()}.
17+
*
18+
* @author Bernhard Schussek <[email protected]>
19+
*/
20+
class AccessException extends \LogicException implements ExceptionInterface
21+
{
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\OptionsResolver\Exception;
13+
14+
/**
15+
* Thrown when an argument is invalid.
16+
*
17+
* @author Bernhard Schussek <[email protected]>
18+
*/
19+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/OptionsResolver/Exception/InvalidOptionsException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\OptionsResolver\Exception;
1313

1414
/**
15-
* Exception thrown when an invalid option is passed.
15+
* Thrown when the value of an option does not match its validation rules.
16+
*
17+
* You should make sure a valid value is passed to the option.
1618
*
1719
* @author Bernhard Schussek <[email protected]>
1820
*/
19-
class InvalidOptionsException extends \InvalidArgumentException implements ExceptionInterface
21+
class InvalidOptionsException extends InvalidArgumentException
2022
{
2123
}

src/Symfony/Component/OptionsResolver/Exception/MissingOptionsException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
/**
1515
* Exception thrown when a required option is missing.
1616
*
17+
* Add the option to the passed options array.
18+
*
1719
* @author Bernhard Schussek <[email protected]>
1820
*/
19-
class MissingOptionsException extends \InvalidArgumentException implements ExceptionInterface
21+
class MissingOptionsException extends InvalidArgumentException
2022
{
2123
}

src/Symfony/Component/OptionsResolver/Exception/OptionDefinitionException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace Symfony\Component\OptionsResolver\Exception;
1313

1414
/**
15-
* Thrown when an option definition is invalid.
15+
* Thrown when two lazy options have a cyclic dependency.
1616
*
1717
* @author Bernhard Schussek <[email protected]>
1818
*/
19-
class OptionDefinitionException extends \RuntimeException implements ExceptionInterface
19+
class OptionDefinitionException extends \LogicException implements ExceptionInterface
2020
{
2121
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\OptionsResolver\Exception;
13+
14+
/**
15+
* Exception thrown when an undefined option is passed.
16+
*
17+
* You should remove the options in question from your code or define them
18+
* beforehand.
19+
*
20+
* @author Bernhard Schussek <[email protected]>
21+
*/
22+
class UndefinedOptionsException extends InvalidArgumentException
23+
{
24+
}

0 commit comments

Comments
 (0)