0 follower

Final Class Yiisoft\Router\HydratorAttribute\RouteArgumentResolver

InheritanceYiisoft\Router\HydratorAttribute\RouteArgumentResolver
ImplementsYiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Router\CurrentRoute $currentRoute )
$currentRoute Yiisoft\Router\CurrentRoute

                public function __construct(
    private readonly CurrentRoute $currentRoute,
) {
}

            
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 RouteArgument) {
        throw new UnexpectedAttributeException(RouteArgument::class, $attribute);
    }
    $arguments = $this->currentRoute->getArguments();
    $name = $attribute->getName() ?? $context->getParameter()->getName();
    if (array_key_exists($name, $arguments)) {
        return Result::success($arguments[$name]);
    }
    return Result::fail();
}