Use handler to cast to type.

@param string $type
@return static
@throws LogicException if handler can't be used
508745
public function forType(string $type): HandlerInterface
    {
        if ($type !== $this->getType()) {
            throw new LogicException("Unable to use " . get_class($this) . " to cast to $type");
        }
        
        return $this;
    }
1257531
private static function getTyped($type)
    {
        if (!isset(static::$types[$type])) {
            static::$types[$type] = new self($type);
        }

        return static::$types[$type];
    }
833973
public function setType(string $type = self::TYPE_HIDDEN): InputInterface
    {
        $this->type = $type;

        return $this;
    }
947670
public function expect($type)
    {
        $node = $this->current();
        if (!$this->is($type)) {
            if (is_array($type)) {
                $type = implode(' or ', $type);
            }
            $actual = sprintf('<%s:%s>', $node->getType(), $node->getValue());
            throw new \LogicException(sprintf('Syntax Error: %s expected %s given', $type, $actual));
        }
        $this->next();

        return $node;
    }
779471
public function setObjectType($type)
    {
        if (!is_null($type)) {
            $type = (string) $type;
        }

        $this->objectType = $type;
        return $this;
    }
880387
public static function input(string $type)
    {
        $self = self::$input[$type] ?? new self;

        self::$input[$type] = $self;

        switch (strtoupper($type)) {
            case 'GET':
            case 'POST':
                $self->params = filter_input_array(constant('INPUT_' . $type)) ?? [];
                break;
            case 'PUT':
            case 'DELETE':
                $self->params = self::getParsedInput();
                break;
        }

        return function ($key = null) use ($self) {
            $self->key = $key;

            return $self;
        };
    }
950441
public function setType($type)
    {
        if (!in_array($type, self::TYPES)) {
            throw new \InvalidArgumentException("bad type {$type}");
        }
        $this->type = $type;

        return $this;
    }
179406
private function executeTraits($type)
    {
        if (empty($this->usedTraits))
        {
            return;
        }

        switch ($type)
        {
            case 'prolog':
                $type = 'Prolog';
            break;

            case 'main':
                $type = 'Main';
            break;

            default:
                $type = 'Epilog';
            break;
        }

        foreach ($this->usedTraits as $trait => $name)
        {
            $method = 'execute'.$type.$name;

            if (method_exists($trait, $method))
            {
                $this->$method();
            }
        }
    }
71482
public function setType($type = null)
    {
        $type = $this->calculateTypeValue($type);

        if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
            throw new Exception\InvalidArgumentException('Unknown type');
        }

        $this->options['type'] = $type;

        return $this;
    }
1197765
protected function getHandler()
    {
        $handler = resolve($this->type->handler);
        if (!$handler instanceof ContentTypeHandler) {
            throw new DomainException("Type: $this->type can't be handled");
        }
        return $handler;
    }
297663
public function setType($type)
    {
        if ($type === null) {
            $type = self::TYPE_UNDEFINED;
        }

        $this->type = $type;

        return $this;
    }
308580
private function getHandler($type)
    {
        if (!isset(self::$typeHandlers[$type])) {
            throw new Exception("Unsupported PDO param type - " . $type);
        }

        return self::$typeHandlers[$type];
    }
792774
public function setType($type)
    {
        if(is_array($type) === true) {
            $type    = $type[key($type)];
        }

        $this->types = array_flip($this->types);
        if (isset($this->types[$type]) === true) {

            $this->widget = $type;

        }

        return $this;
    }
203064
public function withType(string $type): self
    {
        $this->type = UserPermissionEnum::ensureValid($type);
        return $this;
    }
1192430
public function getHandlerForType(string $type) : HandlerInterface
    {
        if ($this->hasHandlerForType($type)) {
            return $this->handlers[$type];
        }

        throw DataTypeException::handlerNotFound($type);
    }
1046660
public function setType($key, $type)
    {
        $args = func_get_args();
        $type = array_pop($args);

        if (!($type instanceof Validator))
            $type = new Validator($type);

        if ($this->types->has($args))
        {
            $old_type = $this->types->get($args); 
            if ($old_type != $type)
                throw new \LogicException("Duplicate key: " . WF::str($args));
        }
        else
        {
            $args[] = $type;
            $this->types->set($args, null);
        }
        return $this;
    }
56445
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);
    }