-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
FeatureGood first issueIdeal for your first contribution! (some Symfony experience may be required)Ideal for your first contribution! (some Symfony experience may be required)OptionsResolverRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Description
Description
When we want to configure an option in OptionsResolver, we have a code like this one:
$optionsResolver
->setDefined('foo')
->setAllowedTypes('foo', ['string'])
->setAllowedValues('foo', ['bar', 'baz'])
->setRequired('foo');
We have to duplicate option name and call 4 or 5 methods for each option to configure.
With only one option, it's readable, but when we have more options it's difficult to read.
Can we add a method with most used configurations?
$optionsResolver = new OptionsResolver();
# Configure a required option
$optionsResolver->configureRequiredOption('foo', ['string'], ['bar', 'baz']);
# Equivalent to call original OptionsResolver methods:
$optionsResolver
->setDefined('foo')
->setAllowedTypes('foo', ['string'])
->setAllowedValues('foo', ['bar', 'baz'])
->setRequired('foo');
Example
I don't know if I can add a link here, my bad if it's not allowed.
I've done it in a public repository:
https://github.com/steevanb/symfony-options-resolver
fancyweb, zmitic, cybernet and alamirault
Metadata
Metadata
Assignees
Labels
FeatureGood first issueIdeal for your first contribution! (some Symfony experience may be required)Ideal for your first contribution! (some Symfony experience may be required)OptionsResolverRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)