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