\Symfony\Component\OptionsResolverOptionsResolverInterface

Summary

Methods
Constants
setDefaults()
replaceDefaults()
setOptional()
setRequired()
setAllowedValues()
addAllowedValues()
setAllowedTypes()
addAllowedTypes()
setNormalizers()
isKnown()
isRequired()
resolve()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

setDefaults()

setDefaults(array  $defaultValues) : $this

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

Returns

$this

replaceDefaults()

replaceDefaults(array  $defaultValues) : $this

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

Returns

$this

setOptional()

setOptional(array  $optionNames) : $this

Sets optional options.

This method declares valid option names without setting default values for them. If these options are not passed to \Symfony\Component\OptionsResolver\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 \Symfony\Component\OptionsResolver\resolve() would trigger an exception for unknown options.

Parameters

array $optionNames

A list of option names

Returns

$this

setRequired()

setRequired(array  $optionNames) : $this

Sets required options.

If these options are not passed to \Symfony\Component\OptionsResolver\resolve() and no default has been set for them, an exception will be thrown.

Parameters

array $optionNames

A list of option names

Returns

$this

setAllowedValues()

setAllowedValues(array  $allowedValues) : $this

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

Throws

\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException

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

Returns

$this

addAllowedValues()

addAllowedValues(array  $allowedValues) : $this

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

Throws

\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException

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

Returns

$this

setAllowedTypes()

setAllowedTypes(array  $allowedTypes) : $this

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

Throws

\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException

if an option has not been defined for which an allowed type is set

Returns

$this

addAllowedTypes()

addAllowedTypes(array  $allowedTypes) : $this

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

Throws

\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException

if an option has not been defined for which an allowed type is set

Returns

$this

setNormalizers()

setNormalizers(array  $normalizers) : $this

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

Returns

$this

isKnown()

isKnown(string  $option) : boolean

Returns whether an option is known.

An option is known if it has been passed to either \Symfony\Component\OptionsResolver\setDefaults(), \Symfony\Component\OptionsResolver\setRequired() or \Symfony\Component\OptionsResolver\setOptional() before.

Parameters

string $option

The name of the option

Returns

boolean —

Whether the option is known

isRequired()

isRequired(string  $option) : boolean

Returns whether an option is required.

An option is required if it has been passed to \Symfony\Component\OptionsResolver\setRequired(), but not to \Symfony\Component\OptionsResolver\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

Returns

boolean —

Whether the option is required

resolve()

resolve(array  $options = array()) : array

Returns the combination of the default and the passed options.

Parameters

array $options

The custom option values

Throws

\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException

if any of the passed options has not been defined or does not contain an allowed value

\Symfony\Component\OptionsResolver\Exception\MissingOptionsException

if a required option is missing

\Symfony\Component\OptionsResolver\Exception\OptionDefinitionException

if a cyclic dependency is detected between two lazy options

Returns

array —

A list of options and their values