0 follower

Final Class Yiisoft\Input\Http\Attribute\Parameter\RequestResolver

InheritanceYiisoft\Input\Http\Attribute\Parameter\RequestResolver
ImplementsYiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface

Resolver for {@see Request} attribute.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\RequestProvider\RequestProviderInterface $requestProvider )
$requestProvider \Yiisoft\RequestProvider\RequestProviderInterface

The request provider.

                public function __construct(
    private RequestProviderInterface $requestProvider
) {
}

            
getParameterValue() public method

public \Yiisoft\Hydrator\Result getParameterValue ( \Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface $attribute, \Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext $context )
$attribute \Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface
$context \Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext

                public function getParameterValue(
    ParameterAttributeInterface $attribute,
    ParameterAttributeResolveContext $context,
): Result {
    if (!$attribute instanceof Request) {
        throw new UnexpectedAttributeException(Request::class, $attribute);
    }
    $requestAttributes = $this->requestProvider->get()->getAttributes();
    $name = $attribute->getName() ?? $context->getParameter()->getName();
    if (!ArrayHelper::pathExists($requestAttributes, $name)) {
        return Result::fail();
    }
    return Result::success(ArrayHelper::getValueByPath($requestAttributes, $name));
}