| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\HttpFoundation\Request;
|
|
|
15 |
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
|
|
16 |
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
|
|
|
17 |
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Yields a non-variadic argument's value from the request attributes.
|
|
|
21 |
*
|
|
|
22 |
* @author Iltar van der Berg <kjarli@gmail.com>
|
|
|
23 |
*/
|
|
|
24 |
final class RequestAttributeValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
* @deprecated since Symfony 6.2, use resolve() instead
|
|
|
28 |
*/
|
|
|
29 |
public function supports(Request $request, ArgumentMetadata $argument): bool
|
|
|
30 |
{
|
|
|
31 |
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);
|
|
|
32 |
|
|
|
33 |
return !$argument->isVariadic() && $request->attributes->has($argument->getName());
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function resolve(Request $request, ArgumentMetadata $argument): array
|
|
|
37 |
{
|
|
|
38 |
return !$argument->isVariadic() && $request->attributes->has($argument->getName()) ? [$request->attributes->get($argument->getName())] : [];
|
|
|
39 |
}
|
|
|
40 |
}
|