1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Application\Diagnostics;
13:
14: use Nette,
15: Nette\Application\Routers,
16: Nette\Application\UI\Presenter,
17: Nette\Diagnostics\Debugger;
18:
19:
20: 21: 22: 23: 24:
25: class RoutingPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
26: {
27:
28: private $router;
29:
30:
31: private $httpRequest;
32:
33:
34: private $routers = array();
35:
36:
37: private $request;
38:
39:
40: public static function initializePanel(Nette\Application\Application $application)
41: {
42: Debugger::$blueScreen->addPanel(function($e) use ($application) {
43: return $e ? NULL : array(
44: 'tab' => 'Nette Application',
45: 'panel' => '<h3>Requests</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getRequests())
46: . '<h3>Presenter</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getPresenter())
47: );
48: });
49: }
50:
51:
52: public function __construct(Nette\Application\IRouter $router, Nette\Http\IRequest $httpRequest)
53: {
54: $this->router = $router;
55: $this->httpRequest = $httpRequest;
56: }
57:
58:
59: 60: 61: 62:
63: public function getTab()
64: {
65: $this->analyse($this->router);
66: ob_start();
67: require __DIR__ . '/templates/RoutingPanel.tab.phtml';
68: return ob_get_clean();
69: }
70:
71:
72: 73: 74: 75:
76: public function getPanel()
77: {
78: ob_start();
79: require __DIR__ . '/templates/RoutingPanel.panel.phtml';
80: return ob_get_clean();
81: }
82:
83:
84: 85: 86: 87: 88:
89: private function analyse($router, $module = '')
90: {
91: if ($router instanceof Routers\RouteList) {
92: foreach ($router as $subRouter) {
93: $this->analyse($subRouter, $module . $router->getModule());
94: }
95: return;
96: }
97:
98: $matched = 'no';
99: $request = $router->match($this->httpRequest);
100: if ($request) {
101: $request->setPresenterName($module . $request->getPresenterName());
102: $matched = 'may';
103: if (empty($this->request)) {
104: $this->request = $request;
105: $matched = 'yes';
106: }
107: }
108:
109: $this->routers[] = array(
110: 'matched' => $matched,
111: 'class' => get_class($router),
112: 'defaults' => $router instanceof Routers\Route || $router instanceof Routers\SimpleRouter ? $router->getDefaults() : array(),
113: 'mask' => $router instanceof Routers\Route ? $router->getMask() : NULL,
114: 'request' => $request,
115: 'module' => rtrim($module, ':')
116: );
117: }
118:
119: }
120: