public function setDefault($option, $value)
    {
        // Setting is not possible once resolving starts, because then lazy
        // options could manipulate the state of the object, leading to
        // inconsistent results.
        if ($this->locked) {
            throw new AccessException('Default values cannot be set from a lazy option or normalizer.');
        }

        // If an option is a closure that should be evaluated lazily, store it
        // in the "lazy" property.
        if ($value instanceof \Closure) {
            $reflClosure = new \ReflectionFunction($value);
            $params = $reflClosure->getParameters();

            if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && Options::class === $class->name) {
                // Initialize the option if no previous value exists
                if (!isset($this->defaults[$option])) {
                    $this->defaults[$option] = null;
                }

                // Ignore previous lazy options if the closure has no second parameter
                if (!isset($this->lazy[$option]) || !isset($params[1])) {
                    $this->lazy[$option] = [];
                }

                // Store closure for later evaluation
                $this->lazy[$option][] = $value;
                $this->defined[$option] = true;

                // Make sure the option is processed and is not nested anymore
                unset($this->resolved[$option], $this->nested[$option]);

                return $this;
            }

            if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && self::class === $class->name && (!isset($params[1]) || (null !== ($class = $params[1]->getClass()) && Options::class === $class->name))) {
                // Store closure for later evaluation
                $this->nested[$option][] = $value;
                $this->defaults[$option] = [];
                $this->defined[$option] = true;

                // Make sure the option is processed and is not lazy anymore
                unset($this->resolved[$option], $this->lazy[$option]);

                return $this;
            }
        }

        // This option is not lazy nor nested anymore
        unset($this->lazy[$option], $this->nested[$option]);

        // Yet undefined options can be marked as resolved, because we only need
        // to resolve options with lazy closures, normalizers or validation
        // rules, none of which can exist for undefined options
        // If the option was resolved before, update the resolved value
        if (!isset($this->defined[$option]) || \array_key_exists($option, $this->resolved)) {
            $this->resolved[$option] = $value;
        }

        $this->defaults[$option] = $value;
        $this->defined[$option] = true;

        return $this;
    }
public function setDefault($option, $value)
    {
        // Setting is not possible once resolving starts, because then lazy
        // options could manipulate the state of the object, leading to
        // inconsistent results.
        if ($this->locked) {
            throw new AccessException('Default values cannot be set from a lazy option or normalizer.');
        }

        // If an option is a closure that should be evaluated lazily, store it
        // in the "lazy" property.
        if ($value instanceof \Closure) {
            $reflClosure = new \ReflectionFunction($value);
            $params = $reflClosure->getParameters();

            if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && Options::class === $class->name) {
                // Initialize the option if no previous value exists
                if (!isset($this->defaults[$option])) {
                    $this->defaults[$option] = null;
                }

                // Ignore previous lazy options if the closure has no second parameter
                if (!isset($this->lazy[$option]) || !isset($params[1])) {
                    $this->lazy[$option] = [];
                }

                // Store closure for later evaluation
                $this->lazy[$option][] = $value;
                $this->defined[$option] = true;

                // Make sure the option is processed and is not nested anymore
                unset($this->resolved[$option], $this->nested[$option]);

                return $this;
            }

            if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && self::class === $class->name && (!isset($params[1]) || (null !== ($class = $params[1]->getClass()) && Options::class === $class->name))) {
                // Store closure for later evaluation
                $this->nested[$option][] = $value;
                $this->defaults[$option] = [];
                $this->defined[$option] = true;

                // Make sure the option is processed and is not lazy anymore
                unset($this->resolved[$option], $this->lazy[$option]);

                return $this;
            }
        }

        // This option is not lazy nor nested anymore
        unset($this->lazy[$option], $this->nested[$option]);

        // Yet undefined options can be marked as resolved, because we only need
        // to resolve options with lazy closures, normalizers or validation
        // rules, none of which can exist for undefined options
        // If the option was resolved before, update the resolved value
        if (!isset($this->defined[$option]) || \array_key_exists($option, $this->resolved)) {
            $this->resolved[$option] = $value;
        }

        $this->defaults[$option] = $value;
        $this->defined[$option] = true;

        return $this;
    }
public function setDefault ( $ option , $ value ) { // Setting is not possible once resolving starts, because then lazy // options could manipulate the state of the object, leading to // inconsistent results. if ( $ this -> locked ) { throw new AccessException ( 'Default values cannot be set from a lazy option or normalizer.' ) ; } // If an option is a closure that should be evaluated lazily, store it // in the "lazy" property. if ( $ value instanceof \ Closure ) { $ reflClosure = new \ ReflectionFunction ( $ value ) ; $ params = $ reflClosure -> getParameters ( ) ; if ( isset ( $ params [ 0 ] ) && null !== ( $ class = $ params [ 0 ] -> getClass ( ) ) && Options :: class === $ class -> name ) { // Initialize the option if no previous value exists if ( ! isset ( $ this -> defaults [ $ option ] ) ) { $ this -> defaults [ $ option ] = null ; } // Ignore previous lazy options if the closure has no second parameter if ( ! isset ( $ this -> lazy [ $ option ] ) || ! isset ( $ params [ 1 ] ) ) { $ this -> lazy [ $ option ] = [ ] ; } // Store closure for later evaluation $ this -> lazy [ $ option ] [ ] = $ value ; $ this -> defined [ $ option ] = true ; // Make sure the option is processed and is not nested anymore unset ( $ this -> resolved [ $ option ] , $ this -> nested [ $ option ] ) ; return $ this ; } if ( isset ( $ params [ 0 ] ) && null !== ( $ class = $ params [ 0 ] -> getClass ( ) ) && self :: class === $ class -> name && ( ! isset ( $ params [ 1 ] ) || ( null !== ( $ class = $ params [ 1 ] -> getClass ( ) ) && Options :: class === $ class -> name ) ) ) { // Store closure for later evaluation $ this -> nested [ $ option ] [ ] = $ value ; $ this -> defaults [ $ option ] = [ ] ; $ this -> defined [ $ option ] = true ; // Make sure the option is processed and is not lazy anymore unset ( $ this -> resolved [ $ option ] , $ this -> lazy [ $ option ] ) ; return $ this ; } } // This option is not lazy nor nested anymore unset ( $ this -> lazy [ $ option ] , $ this -> nested [ $ option ] ) ; // Yet undefined options can be marked as resolved, because we only need // to resolve options with lazy closures, normalizers or validation // rules, none of which can exist for undefined options // If the option was resolved before, update the resolved value if ( ! isset ( $ this -> defined [ $ option ] ) || \ array_key_exists ( $ option , $ this -> resolved ) ) { $ this -> resolved [ $ option ] = $ value ; } $ this -> defaults [ $ option ] = $ value ; $ this -> defined [ $ option ] = true ; return $ this ; }
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.

If you want to define nested options, you can pass a closure with the
following signature:

$options->setDefault('database', function (OptionsResolver $resolver) {
$resolver->setDefined(['dbname', 'host', 'port', 'user', 'pass']);
}

To get access to the parent options, add a second argument to the closure's
signature:

function (OptionsResolver $resolver, Options $parent) {
// 'default' === $parent['connection']
}

@param string $option The name of the option
@param mixed  $value  The default value of the option

@return $this

@throws AccessException If called from a lazy option or normalizer
Sets the default value of a given option .