Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/http-kernel/DataCollector/RouterDataCollector.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\HttpKernel\DataCollector; | |
13 | |
14 use Symfony\Component\HttpFoundation\Request; | |
15 use Symfony\Component\HttpFoundation\Response; | |
16 use Symfony\Component\HttpFoundation\RedirectResponse; | |
17 use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
18 | |
19 /** | |
20 * RouterDataCollector. | |
21 * | |
22 * @author Fabien Potencier <fabien@symfony.com> | |
23 */ | |
24 class RouterDataCollector extends DataCollector | |
25 { | |
26 /** | |
27 * @var \SplObjectStorage | |
28 */ | |
29 protected $controllers; | |
30 | |
31 public function __construct() | |
32 { | |
33 $this->reset(); | |
34 } | |
35 | |
36 /** | |
37 * {@inheritdoc} | |
38 */ | |
39 public function collect(Request $request, Response $response, \Exception $exception = null) | |
40 { | |
41 if ($response instanceof RedirectResponse) { | |
42 $this->data['redirect'] = true; | |
43 $this->data['url'] = $response->getTargetUrl(); | |
44 | |
45 if ($this->controllers->contains($request)) { | |
46 $this->data['route'] = $this->guessRoute($request, $this->controllers[$request]); | |
47 } | |
48 } | |
49 | |
50 unset($this->controllers[$request]); | |
51 } | |
52 | |
53 public function reset() | |
54 { | |
55 $this->controllers = new \SplObjectStorage(); | |
56 | |
57 $this->data = array( | |
58 'redirect' => false, | |
59 'url' => null, | |
60 'route' => null, | |
61 ); | |
62 } | |
63 | |
64 protected function guessRoute(Request $request, $controller) | |
65 { | |
66 return 'n/a'; | |
67 } | |
68 | |
69 /** | |
70 * Remembers the controller associated to each request. | |
71 */ | |
72 public function onKernelController(FilterControllerEvent $event) | |
73 { | |
74 $this->controllers[$event->getRequest()] = $event->getController(); | |
75 } | |
76 | |
77 /** | |
78 * @return bool Whether this request will result in a redirect | |
79 */ | |
80 public function getRedirect() | |
81 { | |
82 return $this->data['redirect']; | |
83 } | |
84 | |
85 /** | |
86 * @return string|null The target URL | |
87 */ | |
88 public function getTargetUrl() | |
89 { | |
90 return $this->data['url']; | |
91 } | |
92 | |
93 /** | |
94 * @return string|null The target route | |
95 */ | |
96 public function getTargetRoute() | |
97 { | |
98 return $this->data['route']; | |
99 } | |
100 | |
101 /** | |
102 * {@inheritdoc} | |
103 */ | |
104 public function getName() | |
105 { | |
106 return 'router'; | |
107 } | |
108 } |