for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Router\HydratorAttribute;
use Yiisoft\Hydrator\Context;
use Yiisoft\Hydrator\NotResolvedException;
use Yiisoft\Hydrator\ParameterAttributeInterface;
use Yiisoft\Hydrator\ParameterAttributeResolverInterface;
use Yiisoft\Hydrator\UnexpectedAttributeException;
use Yiisoft\Router\CurrentRoute;
final class RouteResolver implements ParameterAttributeResolverInterface
{
public function __construct(
private CurrentRoute $currentRoute,
) {
}
public function getParameterValue(ParameterAttributeInterface $attribute, Context $context): mixed
if (!$attribute instanceof Route) {
throw new UnexpectedAttributeException(Route::class, $attribute);
$arguments = $this->currentRoute->getArguments();
$name = $attribute->getName();
if ($name === null) {
return $arguments;
return $arguments[$name] ?? throw new NotResolvedException();