OptionsResolver setDefault(string $option, mixed $value)
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.
Please login to continue.