Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RouterDataCollector.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\DataCollector;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  15. /**
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class RouterDataCollector extends DataCollector
  19. {
  20. /**
  21. * @var \SplObjectStorage
  22. */
  23. protected $controllers;
  24. public function __construct()
  25. {
  26. $this->reset();
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function collect(Request $request, Response $response, \Exception $exception = null)
  32. {
  33. if ($response instanceof RedirectResponse) {
  34. $this->data['redirect'] = true;
  35. $this->data['url'] = $response->getTargetUrl();
  36. if ($this->controllers->contains($request)) {
  37. $this->data['route'] = $this->guessRoute($request, $this->controllers[$request]);
  38. }
  39. }
  40. unset($this->controllers[$request]);
  41. }
  42. public function reset()
  43. {
  44. $this->controllers = new \SplObjectStorage();
  45. $this->data = [
  46. 'redirect' => false,
  47. 'url' => null,
  48. 'route' => null,
  49. ];
  50. }
  51. protected function guessRoute(Request $request, $controller)
  52. {
  53. return 'n/a';
  54. }
  55. /**
  56. * Remembers the controller associated to each request.
  57. *
  58. * @final since Symfony 4.3
  59. */
  60. public function onKernelController(FilterControllerEvent $event)
  61. {
  62. $this->controllers[$event->getRequest()] = $event->getController();
  63. }
  64. /**
  65. * @return bool Whether this request will result in a redirect
  66. */
  67. public function getRedirect()
  68. {
  69. return $this->data['redirect'];
  70. }
  71. /**
  72. * @return string|null The target URL
  73. */
  74. public function getTargetUrl()
  75. {
  76. return $this->data['url'];
  77. }
  78. /**
  79. * @return string|null The target route
  80. */
  81. public function getTargetRoute()
  82. {
  83. return $this->data['route'];
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function getName()
  89. {
  90. return 'router';
  91. }
  92. }