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