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