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