public function setCast($option, $type)
    {
        /* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */
        if (! $this->isDefined($option)) {
            throw new UndefinedOptionsException(
                sprintf(
                    'The option "%s" does not exist. Defined options are: "%s".',
                    $option,
                    implode('", "', $this->getDefinedOptions())
                )
            );
        }

        /* Check if a closure was passed as argument. */
        if ($type instanceof \Closure) {
            $refClosure = new \ReflectionFunction($type);

            /* The closure must have exactly one parameter, and it should be required. */
            if (2 !== $refClosure->getNumberOfParameters() + $refClosure->getNumberOfRequiredParameters()) {
                throw new InvalidArgumentException(
                    'The given closure must define exactly one required parameter (the value to cast).'
                );
            }
            $this->casts[$option] = $type;

            return $this;
        }

        /* Ensure that a valid type to cast to is given. */
        if (! in_array($type, $this->validCastTypes)) {
            throw new InvalidArgumentException(
                sprintf(
                    'The type cast "%s" does not exist. Defined type casts are: "%s".',
                    $type,
                    implode('", "', $this->validCastTypes)
                )
            );
        }

        /* Add the type cast. */
        $this->casts[$option] = $type;

        return $this;
    }
public function setCast($option, $type)
    {
        /* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */
        if (! $this->isDefined($option)) {
            throw new UndefinedOptionsException(
                sprintf(
                    'The option "%s" does not exist. Defined options are: "%s".',
                    $option,
                    implode('", "', $this->getDefinedOptions())
                )
            );
        }

        /* Check if a closure was passed as argument. */
        if ($type instanceof \Closure) {
            $refClosure = new \ReflectionFunction($type);

            /* The closure must have exactly one parameter, and it should be required. */
            if (2 !== $refClosure->getNumberOfParameters() + $refClosure->getNumberOfRequiredParameters()) {
                throw new InvalidArgumentException(
                    'The given closure must define exactly one required parameter (the value to cast).'
                );
            }
            $this->casts[$option] = $type;

            return $this;
        }

        /* Ensure that a valid type to cast to is given. */
        if (! in_array($type, $this->validCastTypes)) {
            throw new InvalidArgumentException(
                sprintf(
                    'The type cast "%s" does not exist. Defined type casts are: "%s".',
                    $type,
                    implode('", "', $this->validCastTypes)
                )
            );
        }

        /* Add the type cast. */
        $this->casts[$option] = $type;

        return $this;
    }
public function setCast ( $ option , $ type ) { /* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */ if ( ! $ this -> isDefined ( $ option ) ) { throw new UndefinedOptionsException ( sprintf ( 'The option "%s" does not exist. Defined options are: "%s".' , $ option , implode ( '", "' , $ this -> getDefinedOptions ( ) ) ) ) ; } /* Check if a closure was passed as argument. */ if ( $ type instanceof \ Closure ) { $ refClosure = new \ ReflectionFunction ( $ type ) ; /* The closure must have exactly one parameter, and it should be required. */ if ( 2 !== $ refClosure -> getNumberOfParameters ( ) + $ refClosure -> getNumberOfRequiredParameters ( ) ) { throw new InvalidArgumentException ( 'The given closure must define exactly one required parameter (the value to cast).' ) ; } $ this -> casts [ $ option ] = $ type ; return $ this ; } /* Ensure that a valid type to cast to is given. */ if ( ! in_array ( $ type , $ this -> validCastTypes ) ) { throw new InvalidArgumentException ( sprintf ( 'The type cast "%s" does not exist. Defined type casts are: "%s".' , $ type , implode ( '", "' , $ this -> validCastTypes ) ) ) ; } /* Add the type cast. */ $ this -> casts [ $ option ] = $ type ; return $ this ; }
Sets a cast for a specific option. The given option will be cast to the given type before any validation, if
possible.

@param string          $option Option name.
@param string|\Closure $type   Type to cast the option to or a closure to be lazily evaluated.

@return OptionsResolver Returns itself.

@throws UndefinedOptionsException
@throws InvalidArgumentException
Sets a cast for a specific option . The given option will be cast to the given type before any validation if possible .