1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yiisoft\RequestModel\Attribute; |
||
6 | |||
7 | use Psr\Http\Message\ServerRequestInterface; |
||
8 | |||
9 | final class QueryResolver implements HandlerParameterResolverInterface |
||
10 | { |
||
11 | 3 | public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed |
|
12 | { |
||
13 | 3 | if ($attribute::class !== Query::class) { |
|
14 | 1 | throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Query::class, $attribute::class)); |
|
15 | } |
||
16 | |||
17 | 2 | $queryParams = $request->getQueryParams(); |
|
18 | |||
19 | 2 | if ($attribute->getName() !== null) { |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
20 | 1 | return $queryParams[$attribute->getName()] ?? throw new ValueNotFoundException(); |
|
21 | } |
||
22 | |||
23 | 1 | return $queryParams; |
|
24 | } |
||
25 | } |
||
26 |