Final Class Yiisoft\Input\Http\RequestInputParametersResolver
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resolves request input parameters.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| resolve() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $hydrator | \ |
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,
) {}
| public Yiisoft\ | ||
| $parameters | ReflectionParameter[] |
The parameters to resolve. |
| $request | \ |
The request to get input from. |
| return | Yiisoft\ |
The resolved parameters. |
|---|---|---|
| throws | Yiisoft\ |
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;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.