TraceableValueResolver.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
  13. use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
  14. use Symfony\Component\Stopwatch\Stopwatch;
  15. /**
  16. * Provides timing information via the stopwatch.
  17. *
  18. * @author Iltar van der Berg <kjarli@gmail.com>
  19. */
  20. final class TraceableValueResolver implements ValueResolverInterface
  21. {
  22. public function __construct(
  23. private ValueResolverInterface $inner,
  24. private Stopwatch $stopwatch,
  25. ) {
  26. }
  27. public function resolve(Request $request, ArgumentMetadata $argument): iterable
  28. {
  29. $method = $this->inner::class.'::'.__FUNCTION__;
  30. $this->stopwatch->start($method, 'controller.argument_value_resolver');
  31. yield from $this->inner->resolve($request, $argument);
  32. $this->stopwatch->stop($method);
  33. }
  34. }