菜谱项目

TraceableControllerResolver.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class TraceableControllerResolver implements ControllerResolverInterface, ArgumentResolverInterface
  17. {
  18. private $resolver;
  19. private $stopwatch;
  20. private $argumentResolver;
  21. public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch, ArgumentResolverInterface $argumentResolver = null)
  22. {
  23. $this->resolver = $resolver;
  24. $this->stopwatch = $stopwatch;
  25. $this->argumentResolver = $argumentResolver;
  26. // BC
  27. if (null === $this->argumentResolver) {
  28. $this->argumentResolver = $resolver;
  29. }
  30. if (!$this->argumentResolver instanceof TraceableArgumentResolver) {
  31. $this->argumentResolver = new TraceableArgumentResolver($this->argumentResolver, $this->stopwatch);
  32. }
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getController(Request $request)
  38. {
  39. $e = $this->stopwatch->start('controller.get_callable');
  40. $ret = $this->resolver->getController($request);
  41. $e->stop();
  42. return $ret;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. *
  47. * @deprecated This method is deprecated as of 3.1 and will be removed in 4.0.
  48. */
  49. public function getArguments(Request $request, $controller)
  50. {
  51. @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);
  52. $ret = $this->argumentResolver->getArguments($request, $controller);
  53. return $ret;
  54. }
  55. }