Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[OptionsResolver] Introduce ability to deprecate options, allowed types and values#27277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[OptionsResolver] Introduce ability to deprecate options, allowed types and values#27277
Uh oh!
There was an error while loading.Please reload this page.
Conversation
381c953 to3b7280eCompareyceruto commentedMay 15, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
3b7280e to981c2bfComparero0NL commentedMay 16, 2018
The "Deprecating allowed values" is kinda the same example as "Deprecating allowed types".. no? |
yceruto commentedMay 16, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, same approach: a closure function that returns a string or not depending on the given value. However in "Deprecating allowed values" example you aren't deprecating the value type at all but just a range. |
0e6ff64 tob47b6b7Compareb47b6b7 toe112140CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e112140 tobbed8b3Compareyceruto commentedMay 30, 2018
@fabpot comments addressed, very appreciated your review, thanks. |
bbed8b3 to9beb4abCompareyceruto commentedMay 30, 2018
I just changed the exception classhere |
9beb4ab tof8746ceComparenicolas-grekas commentedJun 19, 2018
Thank you@yceruto. |
…ns, allowed types and values (yceruto)This PR was merged into the 4.2-dev branch.Discussion----------[OptionsResolver] Introduce ability to deprecate options, allowed types and values| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#27216| License | MIT| Doc PR |symfony/symfony-docs#9859**Deprecating an option**```php$resolver = (new OptionsResolver()) ->setDefined(['foo', 'bar']) ->setDeprecated('foo');$resolver->resolve(['foo' => 'baz']); // PHP Deprecated: The option "foo" is deprecated.```With custom message:```php$resolver = (new OptionsResolver()) ->setDefined('foo') ->setDefault('bar', function (Options $options) { return $options['foo']; }) ->setDeprecated('foo', 'The option "foo" is deprecated, use "bar" option instead.');$resolver->resolve(['foo' => 'baz']); // PHP Deprecated: The option "foo" is deprecated, use "bar" option instead.$resolver->resolve(['bar' => 'baz']); // OK.```**Deprecating allowed types**```php$resolver = (new OptionsResolver()) ->setDefault('type', null) ->setAllowedTypes('type', ['null', 'string', FormTypeInterface::class]) ->setDeprecated('type', function ($value) { if ($value instanceof FormTypeInterface) { return sprintf('Passing an instance of "%s" to option "type" is deprecated, pass its FQCN instead.', FormTypeInterface::class); } });$resolver->resolve(['type' => new ChoiceType()]); // PHP Deprecated: Passing an instance of "Symfony\Component\Form\FormTypeInterface" to option "type" is deprecated, pass its FQCN instead.$resolver->resolve(['type' => ChoiceType::class]); // OK.```The closure is invoked when `resolve()` is called. The closure must return a string (the deprecation message) or an empty string to ignore the option deprecation.Multiple types and normalizer:```php$resolver = (new OptionsResolver()) ->setDefault('percent', 0.0) ->setAllowedTypes('percent', ['null', 'int', 'float']) ->setDeprecated('percent', function ($value) { if (null === $value) { return 'Passing "null" to option "percent" is deprecated, pass a float number instead.'; } if (is_int($value)) { return sprintf('Passing an integer "%d" to option "percent" is deprecated, pass a float number instead.', $value); } }) ->setNormalizer('percent', function (Options $options, $value) { return (float) $value; });$resolver->resolve(['percent' => null]); // PHP Deprecated: Passing "null" to option "percent" is deprecated, pass a float number instead.$resolver->resolve(['percent' => 20]); // PHP Deprecated: Passing an integer "20" to option "percent" is deprecated, pass a float number instead.$resolver->resolve(['percent' => 20.0]); // OK.```The parameter passed to the closure is the value of the option after validating it and before normalizing it.**Deprecating allowed values**```php$resolver = (new OptionsResolver()) ->setDefault('percent', 0.0) ->setAllowedTypes('percent', 'float') ->setDeprecated('percent', function ($value) { if ($value < 0) { return 'Passing a number less than 0 to option "percent" is deprecated.'; } });$resolver->resolve(['percent' => -50.0]); // PHP Deprecated: Passing a number less than 0 to option "percent" is deprecated.```Commits-------f8746ce Add ability to deprecate options
This PR was merged into the master branch.Discussion----------[OptionsResolver] Document setDeprecated methodDocumenting featuresymfony/symfony#27277.Commits-------afa5e54 Document setDeprecated method from OptionsResolver component
…tion on debug:form command (yceruto)This PR was merged into the 4.2-dev branch.Discussion----------[Form][OptionsResolver] Show deprecated options definition on debug:form command| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Next move aftersymfony/symfony#27277.It will look like this:Use `--show-deprecated` option to show form types with deprecated options (example):Use `--show-deprecated` option to show deprecated options of the given form type (example):Deprecated option (example):Commits-------87c209d741 Show deprecated options definition on debug:form command
…tion on debug:form command (yceruto)This PR was merged into the 4.2-dev branch.Discussion----------[Form][OptionsResolver] Show deprecated options definition on debug:form command| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Next move aftersymfony/symfony#27277.It will look like this:Use `--show-deprecated` option to show form types with deprecated options (example):Use `--show-deprecated` option to show deprecated options of the given form type (example):Deprecated option (example):Commits-------87c209d741 Show deprecated options definition on debug:form command
…tion on debug:form command (yceruto)This PR was merged into the 4.2-dev branch.Discussion----------[Form][OptionsResolver] Show deprecated options definition on debug:form command| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Next move after#27277.It will look like this:Use `--show-deprecated` option to show form types with deprecated options (example):Use `--show-deprecated` option to show deprecated options of the given form type (example):Deprecated option (example):Commits-------87c209d Show deprecated options definition on debug:form command
Uh oh!
There was an error while loading.Please reload this page.
Deprecating an option
With custom message:
Deprecating allowed types
The closure is invoked when
resolve()is called. The closure must return a string (the deprecation message) or an empty string to ignore the option deprecation.Multiple types and normalizer:
The parameter passed to the closure is the value of the option after validating it and before normalizing it.
Deprecating allowed values