TraceableControllerResolver.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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;
  11. use Symfony\Component\Stopwatch\Stopwatch;
  12. use Symfony\Component\HttpFoundation\Request;
  13. /**
  14. * TraceableControllerResolver.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class TraceableControllerResolver implements ControllerResolverInterface, ArgumentResolverInterface
  19. {
  20. private $resolver;
  21. private $stopwatch;
  22. private $argumentResolver;
  23. /**
  24. * Constructor.
  25. *
  26. * @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
  27. * @param Stopwatch $stopwatch A Stopwatch instance
  28. * @param ArgumentResolverInterface $argumentResolver Only required for BC
  29. */
  30. public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch, ArgumentResolverInterface $argumentResolver = null)
  31. {
  32. $this->resolver = $resolver;
  33. $this->stopwatch = $stopwatch;
  34. $this->argumentResolver = $argumentResolver;
  35. // BC
  36. if (null === $this->argumentResolver) {
  37. $this->argumentResolver = $resolver;
  38. }
  39. if (!$this->argumentResolver instanceof TraceableArgumentResolver) {
  40. $this->argumentResolver = new TraceableArgumentResolver($this->argumentResolver, $this->stopwatch);
  41. }
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getController(Request $request)
  47. {
  48. $e = $this->stopwatch->start('controller.get_callable');
  49. $ret = $this->resolver->getController($request);
  50. $e->stop();
  51. return $ret;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. *
  56. * @deprecated This method is deprecated as of 3.1 and will be removed in 4.0.
  57. */
  58. public function getArguments(Request $request, $controller)
  59. {
  60. @trigger_error(sprintf('The %s method is deprecated as of 3.1 and will be removed in 4.0. Please use the %s instead.', __METHOD__, TraceableArgumentResolver::class), E_USER_DEPRECATED);
  61. $ret = $this->argumentResolver->getArguments($request, $controller);
  62. return $ret;
  63. }
  64. }