0 follower

Final Class Yiisoft\Input\Http\RequestInputParametersResolver

InheritanceYiisoft\Input\Http\RequestInputParametersResolver
ImplementsYiisoft\Middleware\Dispatcher\ParametersResolverInterface

Resolves request input parameters.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Hydrator\HydratorInterface $hydrator, boolean $throwInputValidationException false )
$hydrator \Yiisoft\Hydrator\HydratorInterface

The hydrator to use.

$throwInputValidationException boolean

Whether to throw an exception if input validation fails.

                public function __construct(
    private HydratorInterface $hydrator,
    private bool $throwInputValidationException = false,
) {
}

            
resolve() public method

public Yiisoft\Input\Http\RequestInputInterface[] resolve ( ReflectionParameter[] $parameters, \Psr\Http\Message\ServerRequestInterface $request )
$parameters ReflectionParameter[]

The parameters to resolve.

$request \Psr\Http\Message\ServerRequestInterface

The request to get input from.

return Yiisoft\Input\Http\RequestInputInterface[]

The resolved parameters.

throws Yiisoft\Input\Http\InputValidationException

If input validation fails.

                public function resolve(array $parameters, ServerRequestInterface $request): array
{
    $result = [];
    foreach ($parameters as $parameter) {
        $type = $parameter->getType();
        if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) {
            continue;
        }
        $class = $type->getName();
        $reflectionClass = new ReflectionClass($class);
        if (
            $reflectionClass->isInstantiable()
            && $reflectionClass->implementsInterface(RequestInputInterface::class)
        ) {
            /** @psalm-var class-string<RequestInputInterface> $class */
            $value = $this->hydrator->create($class);
            $this->processValidation($value);
            $result[$parameter->getName()] = $value;
        }
    }
    return $result;
}