TraceableValueResolver.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\ArgumentValueResolverInterface;
  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 ArgumentValueResolverInterface
  21. {
  22. private $inner;
  23. private $stopwatch;
  24. public function __construct(ArgumentValueResolverInterface $inner, Stopwatch $stopwatch)
  25. {
  26. $this->inner = $inner;
  27. $this->stopwatch = $stopwatch;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function supports(Request $request, ArgumentMetadata $argument): bool
  33. {
  34. $method = \get_class($this->inner).'::'.__FUNCTION__;
  35. $this->stopwatch->start($method, 'controller.argument_value_resolver');
  36. $return = $this->inner->supports($request, $argument);
  37. $this->stopwatch->stop($method);
  38. return $return;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function resolve(Request $request, ArgumentMetadata $argument): iterable
  44. {
  45. $method = \get_class($this->inner).'::'.__FUNCTION__;
  46. $this->stopwatch->start($method, 'controller.argument_value_resolver');
  47. yield from $this->inner->resolve($request, $argument);
  48. $this->stopwatch->stop($method);
  49. }
  50. }