1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19:
20: class NRoutingDebugger extends NDebugPanel
21: {
22:
23: private $router;
24:
25:
26: private $httpRequest;
27:
28:
29: private $routers;
30:
31:
32: private $request;
33:
34:
35:
36: public function __construct(IRouter $router, IHttpRequest $httpRequest)
37: {
38: $this->router = $router;
39: $this->httpRequest = $httpRequest;
40: $this->routers = new ArrayObject;
41: parent::__construct('RoutingDebugger', array($this, 'renderTab'), array($this, 'renderPanel'));
42: }
43:
44:
45:
46: 47: 48: 49:
50: public function renderTab()
51: {
52: $this->analyse($this->router);
53: require dirname(__FILE__) . '/templates/RoutingDebugger.tab.phtml';
54: }
55:
56:
57:
58: 59: 60: 61:
62: public function renderPanel()
63: {
64: require dirname(__FILE__) . '/templates/RoutingDebugger.panel.phtml';
65: }
66:
67:
68:
69: 70: 71: 72: 73:
74: private function analyse($router)
75: {
76: if ($router instanceof NMultiRouter) {
77: foreach ($router as $subRouter) {
78: $this->analyse($subRouter);
79: }
80: return;
81: }
82:
83: $request = $router->match($this->httpRequest);
84: $matched = $request === NULL ? 'no' : 'may';
85: if ($request !== NULL && empty($this->request)) {
86: $this->request = $request;
87: $matched = 'yes';
88: }
89:
90: $this->routers[] = array(
91: 'matched' => $matched,
92: 'class' => get_class($router),
93: 'defaults' => $router instanceof NRoute || $router instanceof NSimpleRouter ? $router->getDefaults() : array(),
94: 'mask' => $router instanceof NRoute ? $router->getMask() : NULL,
95: 'request' => $request,
96: );
97: }
98:
99: }
100: