interface OptionsResolverInterface

deprecated since version 2.6, to be removed in 3.0. Use {@link OptionsResolver} instead.

Methods

setDefaults(array $defaultValues)

Sets default option values.

replaceDefaults(array $defaultValues)

Replaces default option values.

setOptional(array $optionNames)

Sets optional options.

setRequired(array $optionNames)

Sets required options.

setAllowedValues(array $allowedValues)

Sets allowed values for a list of options.

addAllowedValues(array $allowedValues)

Adds allowed values for a list of options.

setAllowedTypes(array $allowedTypes)

Sets allowed types for a list of options.

addAllowedTypes(array $allowedTypes)

Adds allowed types for a list of options.

setNormalizers(array $normalizers)

Sets normalizers that are applied on resolved options.

bool
isKnown(string $option)

Returns whether an option is known.

bool
isRequired(string $option)

Returns whether an option is required.

array
resolve(array $options = array())

Returns the combination of the default and the passed options.

Details

at line line 48
OptionsResolverInterface setDefaults(array $defaultValues)

Sets default option values.

The options can either be values of any types or closures that evaluate the option value lazily. These closures must have one of the following signatures:

function (Options $options) function (Options $options, $value)

The second parameter passed to the closure is the previously set default value, in case you are overwriting an existing default value.

The closures should return the lazily created option value.

Parameters

array $defaultValues A list of option names as keys and default values or closures as values.

Return Value

OptionsResolverInterface The resolver instance.

at line line 63
OptionsResolverInterface replaceDefaults(array $defaultValues)

Replaces default option values.

Old defaults are erased, which means that closures passed here cannot access the previous default value. This may be useful to improve performance if the previous default value is calculated by an expensive closure.

Parameters

array $defaultValues A list of option names as keys and default values or closures as values.

Return Value

OptionsResolverInterface The resolver instance.

at line line 78
OptionsResolverInterface setOptional(array $optionNames)

Sets optional options.

This method declares valid option names without setting default values for them. If these options are not passed to {@link resolve()} and no default has been set for them, they will be missing in the final options array. This can be helpful if you want to determine whether an option has been set or not because otherwise {@link resolve()} would trigger an exception for unknown options.

Parameters

array $optionNames A list of option names.

Return Value

OptionsResolverInterface The resolver instance.

at line line 90
OptionsResolverInterface setRequired(array $optionNames)

Sets required options.

If these options are not passed to {@link resolve()} and no default has been set for them, an exception will be thrown.

Parameters

array $optionNames A list of option names.

Return Value

OptionsResolverInterface The resolver instance.

at line line 105
OptionsResolverInterface setAllowedValues(array $allowedValues)

Sets allowed values for a list of options.

Parameters

array $allowedValues A list of option names as keys and arrays with values acceptable for that option as values.

Return Value

OptionsResolverInterface The resolver instance.

Exceptions

InvalidOptionsException If an option has not been defined (see {@link isKnown()}) for which an allowed value is set.

at line line 122
OptionsResolverInterface addAllowedValues(array $allowedValues)

Adds allowed values for a list of options.

The values are merged with the allowed values defined previously.

Parameters

array $allowedValues A list of option names as keys and arrays with values acceptable for that option as values.

Return Value

OptionsResolverInterface The resolver instance.

Exceptions

InvalidOptionsException If an option has not been defined (see {@link isKnown()}) for which an allowed value is set.

at line line 135
OptionsResolverInterface setAllowedTypes(array $allowedTypes)

Sets allowed types for a list of options.

Parameters

array $allowedTypes A list of option names as keys and type names passed as string or array as values.

Return Value

OptionsResolverInterface The resolver instance.

Exceptions

InvalidOptionsException If an option has not been defined for which an allowed type is set.

at line line 150
OptionsResolverInterface addAllowedTypes(array $allowedTypes)

Adds allowed types for a list of options.

The types are merged with the allowed types defined previously.

Parameters

array $allowedTypes A list of option names as keys and type names passed as string or array as values.

Return Value

OptionsResolverInterface The resolver instance.

Exceptions

InvalidOptionsException If an option has not been defined for which an allowed type is set.

at line line 170
OptionsResolverInterface setNormalizers(array $normalizers)

Sets normalizers that are applied on resolved options.

The normalizers should be closures with the following signature:

function (Options $options, $value)

The second parameter passed to the closure is the value of the option.

The closure should return the normalized value.

Parameters

array $normalizers An array of closures.

Return Value

OptionsResolverInterface The resolver instance.

at line line 182
bool isKnown(string $option)

Returns whether an option is known.

An option is known if it has been passed to either {@link setDefaults()}, {@link setRequired()} or {@link setOptional()} before.

Parameters

string $option The name of the option.

Return Value

bool Whether the option is known.

at line line 195
bool isRequired(string $option)

Returns whether an option is required.

An option is required if it has been passed to {@link setRequired()}, but not to {@link setDefaults()}. That is, the option has been declared as required and no default value has been set.

Parameters

string $option The name of the option.

Return Value

bool Whether the option is required.

at line line 211
array resolve(array $options = array())

Returns the combination of the default and the passed options.

Parameters

array $options The custom option values.

Return Value

array A list of options and their values.

Exceptions

InvalidOptionsException If any of the passed options has not been defined or does not contain an allowed value.
MissingOptionsException If a required option is missing.
OptionDefinitionException If a cyclic dependency is detected between two lazy options.