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