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