public function to(string $type): HandlerInterface
    {
        $type = $this->normalizeType($type);

        if (isset($this->handlers[$type])) {
            $key = $type;
        } elseif ($type === 'integer|float' || $type === 'float|integer') {
            $key = 'number';
        } elseif (strpos($type, '|') !== false) {
            $key = 'multiple';
        } elseif (substr($type, -2) === '[]' || is_a($type, Traversable::class, true)) {
            $key = 'array';
        } else {
            $key = 'object';
        }

        if (!isset($this->handlers[$key])) {
            throw new OutOfBoundsException("Unable to find handler to cast to '$type'");
        }

        return $this->handlers[$key]->forType($type);
    }
public function to(string $type): HandlerInterface
    {
        $type = $this->normalizeType($type);

        if (isset($this->handlers[$type])) {
            $key = $type;
        } elseif ($type === 'integer|float' || $type === 'float|integer') {
            $key = 'number';
        } elseif (strpos($type, '|') !== false) {
            $key = 'multiple';
        } elseif (substr($type, -2) === '[]' || is_a($type, Traversable::class, true)) {
            $key = 'array';
        } else {
            $key = 'object';
        }

        if (!isset($this->handlers[$key])) {
            throw new OutOfBoundsException("Unable to find handler to cast to '$type'");
        }

        return $this->handlers[$key]->forType($type);
    }
public function to ( string $ type ) : HandlerInterface { $ type = $ this -> normalizeType ( $ type ) ; if ( isset ( $ this -> handlers [ $ type ] ) ) { $ key = $ type ; } elseif ( $ type === 'integer|float' || $ type === 'float|integer' ) { $ key = 'number' ; } elseif ( strpos ( $ type , '|' ) !== false ) { $ key = 'multiple' ; } elseif ( substr ( $ type , - 2 ) === '[]' || is_a ( $ type , Traversable :: class , true ) ) { $ key = 'array' ; } else { $ key = 'object' ; } if ( ! isset ( $ this -> handlers [ $ key ] ) ) { throw new OutOfBoundsException ( "Unable to find handler to cast to '$type'" ) ; } return $ this -> handlers [ $ key ] -> forType ( $ type ) ; }
Get the handler for a type

@param string $type
@return HandlerInterface
@throws OutOfBoundsException
Get the handler for a type