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\Stopwatch\Stopwatch;
19
 
20
/**
21
 * Provides timing information via the stopwatch.
22
 *
23
 * @author Iltar van der Berg <kjarli@gmail.com>
24
 */
25
final class TraceableValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
26
{
27
    private ArgumentValueResolverInterface|ValueResolverInterface $inner;
28
    private Stopwatch $stopwatch;
29
 
30
    public function __construct(ArgumentValueResolverInterface|ValueResolverInterface $inner, Stopwatch $stopwatch)
31
    {
32
        $this->inner = $inner;
33
        $this->stopwatch = $stopwatch;
34
    }
35
 
36
    /**
37
     * @deprecated since Symfony 6.2, use resolve() instead
38
     */
39
    public function supports(Request $request, ArgumentMetadata $argument): bool
40
    {
41
        if ($this->inner instanceof ValueResolverInterface) {
42
            return true;
43
        }
44
 
45
        $method = \get_class($this->inner).'::'.__FUNCTION__;
46
        $this->stopwatch->start($method, 'controller.argument_value_resolver');
47
 
48
        $return = $this->inner->supports($request, $argument);
49
 
50
        $this->stopwatch->stop($method);
51
 
52
        return $return;
53
    }
54
 
55
    public function resolve(Request $request, ArgumentMetadata $argument): iterable
56
    {
57
        $method = \get_class($this->inner).'::'.__FUNCTION__;
58
        $this->stopwatch->start($method, 'controller.argument_value_resolver');
59
 
60
        yield from $this->inner->resolve($request, $argument);
61
 
62
        $this->stopwatch->stop($method);
63
    }
64
}