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;
    }