class OptionsResolverWrapper extends OptionsResolver
$this | setDefault(string $option, mixed $value) Sets the default value of a given option. | from OptionsResolver |
$this | setDefaults(array $defaults) Sets a list of default values. | from OptionsResolver |
bool | hasDefault(string $option) Returns whether a default value is set for an option. | from OptionsResolver |
$this | setRequired(string|string[] $optionNames) Marks one or more options as required. | from OptionsResolver |
bool | isRequired(string $option) Returns whether an option is required. | from OptionsResolver |
string[] | getRequiredOptions() Returns the names of all required options. | from OptionsResolver |
bool | isMissing(string $option) Returns whether an option is missing a default value. | from OptionsResolver |
string[] | getMissingOptions() Returns the names of all options missing a default value. | from OptionsResolver |
$this | setDefined(string|string[] $optionNames) Defines a valid option name. | from OptionsResolver |
bool | isDefined(string $option) Returns whether an option is defined. | from OptionsResolver |
string[] | getDefinedOptions() Returns the names of all defined options. | from OptionsResolver |
$this | setNormalizer(string $option, Closure $normalizer) Sets the normalizer for an option. | |
$this | setAllowedValues(string $option, mixed $allowedValues) Sets allowed values for an option. | |
$this | addAllowedValues(string $option, mixed $allowedValues) Adds allowed values for an option. | |
$this | setAllowedTypes(string $option, string|string[] $allowedTypes) Sets allowed types for an option. | |
$this | addAllowedTypes(string $option, string|string[] $allowedTypes) Adds allowed types for an option. | |
$this | remove(string|string[] $optionNames) Removes the option with the given name. | from OptionsResolver |
$this | clear() Removes all options. | from OptionsResolver |
array | resolve(array $options = array()) Merges options with the default values stored in the container and validates them. | |
mixed | offsetGet(string $option) Returns the resolved value of an option. | from OptionsResolver |
bool | offsetExists(string $option) Returns whether a resolved option with the given name exists. | from OptionsResolver |
offsetSet($option, $value) Not supported. | from OptionsResolver | |
offsetUnset($option) Not supported. | from OptionsResolver | |
int | count() Returns the number of set options. | from OptionsResolver |
getUndefinedOptions() |
Sets the default value of a given option.
If the default value should be set based on other options, you can pass a closure with the following signature:
function (Options $options) {
// ...
}
The closure will be evaluated when {@link resolve()} is called. The closure has access to the resolved values of other options through the passed {@link Options} instance:
function (Options $options) {
if (isset($options['port'])) {
// ...
}
}
If you want to access the previously set default value, add a second argument to the closure's signature:
$options->setDefault('name', 'Default Name');
$options->setDefault('name', function (Options $options, $previousValue) {
// 'Default Name' === $previousValue
});
This is mostly useful if the configuration of the {@link Options} object is spread across different locations of your code, such as base and sub-classes.
string | $option | The name of the option |
mixed | $value | The default value of the option |
$this |
AccessException | If called from a lazy option or normalizer |
Sets a list of default values.
array | $defaults | The default values to set |
$this |
AccessException | If called from a lazy option or normalizer |
Returns whether a default value is set for an option.
Returns true if {@link setDefault()} was called for this option. An option is also considered set if it was set to null.
string | $option | The option name |
bool | Whether a default value is set |
Marks one or more options as required.
string|string[] | $optionNames | One or more option names |
$this |
AccessException | If called from a lazy option or normalizer |
Returns whether an option is required.
An option is required if it was passed to {@link setRequired()}.
string | $option | The name of the option |
bool | Whether the option is required |
Returns the names of all required options.
string[] | The names of the required options |
isRequired() |
Returns whether an option is missing a default value.
An option is missing if it was passed to {@link setRequired()}, but not to {@link setDefault()}. This option must be passed explicitly to {@link resolve()}, otherwise an exception will be thrown.
string | $option | The name of the option |
bool | Whether the option is missing |
Returns the names of all options missing a default value.
string[] | The names of the missing options |
isMissing() |
Defines a valid option name.
Defines an option name without setting a default value. The option will be accepted when passed to {@link resolve()}. When not passed, the option will not be included in the resolved options.
string|string[] | $optionNames | One or more option names |
$this |
AccessException | If called from a lazy option or normalizer |
Returns whether an option is defined.
Returns true for any option passed to {@link setDefault()}, {@link setRequired()} or {@link setDefined()}.
string | $option | The option name |
bool | Whether the option is defined |
Returns the names of all defined options.
string[] | The names of the defined options |
isDefined() |
Sets the normalizer for an option.
The normalizer should be a closure with the following signature:
function (Options $options, $value) {
// ...
}
The closure is invoked when {@link resolve()} is called. The closure has access to the resolved values of other options through the passed {@link Options} instance.
The second parameter passed to the closure is the value of the option.
The resolved option value is set to the return value of the closure.
string | $option | The option name |
Closure | $normalizer | The normalizer |
$this |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Sets allowed values for an option.
Instead of passing values, you may also pass a closures with the following signature:
function ($value) {
// return true or false
}
The closure receives the value as argument and should return true to accept the value and false to reject the value.
string | $option | The option name |
mixed | $allowedValues | One or more acceptable values/closures |
$this |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Adds allowed values for an option.
The values are merged with the allowed values defined previously.
Instead of passing values, you may also pass a closures with the following signature:
function ($value) {
// return true or false
}
The closure receives the value as argument and should return true to accept the value and false to reject the value.
string | $option | The option name |
mixed | $allowedValues | One or more acceptable values/closures |
$this |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Sets allowed types for an option.
Any type for which a corresponding is_
string | $option | The option name |
string|string[] | $allowedTypes | One or more accepted types |
$this |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Adds allowed types for an option.
The types are merged with the allowed types defined previously.
Any type for which a corresponding is_
string | $option | The option name |
string|string[] | $allowedTypes | One or more accepted types |
$this |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Removes the option with the given name.
Undefined options are ignored.
string|string[] | $optionNames | One or more option names |
$this |
AccessException | If called from a lazy option or normalizer |
Removes all options.
$this |
AccessException | If called from a lazy option or normalizer |
Merges options with the default values stored in the container and validates them.
Exceptions are thrown if:
array | $options | A map of option names to values |
array | The merged and validated options |
UndefinedOptionsException | If an option name is undefined |
InvalidOptionsException | If an option doesn't fulfill the specified validation rules |
MissingOptionsException | If a required option is missing |
OptionDefinitionException | If there is a cyclic dependency between lazy options and/or normalizers |
NoSuchOptionException | If a lazy option reads an unavailable option |
AccessException | If called from a lazy option or normalizer |
Returns the resolved value of an option.
string | $option | The option name |
mixed | The option value |
AccessException | If accessing this method outside of {@link resolve()} |
NoSuchOptionException | If the option is not set |
InvalidOptionsException | If the option doesn't fulfill the specified validation rules |
OptionDefinitionException | If there is a cyclic dependency between lazy options and/or normalizers |
Returns whether a resolved option with the given name exists.
string | $option | The option name |
bool | Whether the option is set |
AccessException | If accessing this method outside of {@link resolve()} |
\ArrayAccess::offsetExists() |
Not supported.
$option | ||
$value |
AccessException |
Not supported.
$option |
AccessException |
Returns the number of set options.
This may be only a subset of the defined options.
int | Number of options |
AccessException | If accessing this method outside of {@link resolve()} |
\Countable::count() |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Form/Util/OptionsResolverWrapper.html