Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19
use Symfony\Component\Uid\AbstractUid;
20
 
21
final class UidValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
22
{
23
    /**
24
     * @deprecated since Symfony 6.2, use resolve() instead
25
     */
26
    public function supports(Request $request, ArgumentMetadata $argument): bool
27
    {
28
        @trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);
29
 
30
        return !$argument->isVariadic()
31
            && \is_string($request->attributes->get($argument->getName()))
32
            && null !== $argument->getType()
33
            && is_subclass_of($argument->getType(), AbstractUid::class, true);
34
    }
35
 
36
    public function resolve(Request $request, ArgumentMetadata $argument): array
37
    {
38
        if ($argument->isVariadic()
39
            || !\is_string($value = $request->attributes->get($argument->getName()))
40
            || null === ($uidClass = $argument->getType())
41
            || !is_subclass_of($argument->getType(), AbstractUid::class, true)
42
        ) {
43
            return [];
44
        }
45
 
46
        /* @var class-string<AbstractUid> $uidClass */
47
        try {
48
            return [$uidClass::fromString($value)];
49
        } catch (\InvalidArgumentException $e) {
50
            throw new NotFoundHttpException(sprintf('The uid for the "%s" parameter is invalid.', $argument->getName()), $e);
51
        }
52
    }
53
}