@@ -57,7 +57,12 @@ public function __construct(
5757 */
5858 public function getTab (): string
5959 {
60- $ this ->analyse ($ this ->router , $ this ->httpRequest );
60+ $ this ->analyse (
61+ $ this ->router instanceof Routing \RouteList
62+ ? $ this ->router
63+ : (new Routing \RouteList )->add ($ this ->router ),
64+ $ this ->httpRequest
65+ );
6166 return Nette \Utils \Helpers::capture (function () {
6267 $ matched = $ this ->matched ;
6368 require __DIR__ . '/templates/RoutingPanel.tab.phtml ' ;
@@ -82,91 +87,66 @@ public function getPanel(): string
8287 }
8388
8489
85- /**
86- * Analyses simple route.
87- */
8890 private function analyse (
89- Routing \Router $ router ,
91+ Routing \RouteList $ router ,
9092 ?Nette \Http \IRequest $ httpRequest ,
9193 string $ module = '' ,
9294 string $ path = '' ,
93- int $ level = -1 ,
94- int $ flag = 0
95+ int $ level = 0
9596 ): void
9697 {
97- if ($ router instanceof Routing \RouteList) {
98- if ($ httpRequest ) {
99- try {
100- $ httpRequest = $ router ->match ($ httpRequest ) === null ? null : $ httpRequest ;
101- } catch (\Throwable $ e ) {
102- $ httpRequest = null ;
98+ $ path .= $ router ->getPath ();
99+ $ module .= ($ router instanceof Nette \Application \Routers \RouteList ? $ router ->getModule () : '' );
100+ $ httpRequest = $ httpRequest
101+ ? (function () use ($ httpRequest ) { return $ this ->prepareRequest ($ httpRequest ); })->bindTo ($ router , Routing \RouteList::class)()
102+ : null ;
103+ $ flags = $ router ->getFlags ();
104+
105+ foreach ($ router ->getRouters () as $ i => $ innerRouter ) {
106+ if ($ innerRouter instanceof Routing \RouteList) {
107+ $ next = count ($ this ->routers );
108+ $ this ->analyse ($ innerRouter , $ httpRequest , $ module , $ path , $ level + 1 );
109+ if ($ info = $ this ->routers [$ next ] ?? null ) {
110+ $ info ->gutterTop = abs ($ level - $ info ->level );
103111 }
104- }
105-
106- $ prop = (new \ReflectionProperty (Routing \RouteList::class, 'path ' ));
107- $ prop ->setAccessible (true );
108- $ path .= $ pathPrefix = $ prop ->getValue ($ router );
109- if ($ httpRequest && $ pathPrefix ) {
110- $ url = $ httpRequest ->getUrl ();
111- $ url = $ url ->getRelativePath () . '/ ' === $ pathPrefix
112- ? $ url ->withPath ($ url ->getPath () . '/ ' )
113- : $ url ->withPath ($ url ->getPath (), $ url ->getBasePath () . $ pathPrefix );
114- $ httpRequest = $ httpRequest ->withUrl ($ url );
115- }
116-
117- $ module .= ($ router instanceof Nette \Application \Routers \RouteList ? $ router ->getModule () : '' );
118-
119- $ next = count ($ this ->routers );
120- $ flags = $ router ->getFlags ();
121- foreach ($ router ->getRouters () as $ i => $ subRouter ) {
122- $ this ->analyse ($ subRouter , $ httpRequest , $ module , $ path , $ level + 1 , $ flags [$ i ]);
123- }
124-
125- if ($ info = $ this ->routers [$ next ] ?? null ) {
126- $ info ->gutterTop = abs (max (0 , $ level ) - $ info ->level );
127- }
128112
129- if ($ info = end ($ this ->routers )) {
130- $ info ->gutterBottom = abs (max (0 , $ level ) - $ info ->level );
113+ if ($ info = end ($ this ->routers )) {
114+ $ info ->gutterBottom = abs ($ level - $ info ->level );
115+ }
116+ continue ;
131117 }
132118
133- return ;
134- }
135-
136- $ matched = $ flag & Routing \RouteList::ONE_WAY ? 'oneway ' : 'no ' ;
137- $ params = $ e = null ;
138- try {
139- $ params = $ httpRequest
140- ? $ router ->match ($ httpRequest )
141- : null ;
142- } catch (\Throwable $ e ) {
143- $ matched = 'error ' ;
144- }
145-
146- if ($ params !== null ) {
147- if ($ module ) {
148- $ params ['presenter ' ] = $ module . ($ params ['presenter ' ] ?? '' );
119+ $ matched = $ flags [$ i ] & $ router ::ONE_WAY ? 'oneway ' : 'no ' ;
120+ $ params = $ e = null ;
121+ try {
122+ if (
123+ $ httpRequest
124+ && ($ params = $ innerRouter ->match ($ httpRequest )) !== null
125+ && ($ params = (function () use ($ params ) { return $ this ->completeParameters ($ params ); })->bindTo ($ router , Routing \RouteList::class)()) !== null
126+ ) {
127+ $ matched = 'may ' ;
128+ if ($ this ->matched === null ) {
129+ $ this ->matched = $ params ;
130+ $ this ->findSource ();
131+ $ matched = 'yes ' ;
132+ }
133+ }
134+ } catch (\Throwable $ e ) {
135+ $ matched = 'error ' ;
149136 }
150137
151- $ matched = 'may ' ;
152- if ($ this ->matched === null ) {
153- $ this ->matched = $ params ;
154- $ this ->findSource ();
155- $ matched = 'yes ' ;
156- }
138+ $ this ->routers [] = (object ) [
139+ 'level ' => max (0 , $ level ),
140+ 'matched ' => $ matched ,
141+ 'class ' => get_class ($ innerRouter ),
142+ 'defaults ' => $ innerRouter instanceof Routing \Route || $ innerRouter instanceof Routing \SimpleRouter ? $ innerRouter ->getDefaults () : [],
143+ 'mask ' => $ innerRouter instanceof Routing \Route ? $ innerRouter ->getMask () : null ,
144+ 'params ' => $ params ,
145+ 'module ' => rtrim ($ module , ': ' ),
146+ 'path ' => $ path ,
147+ 'error ' => $ e ,
148+ ];
157149 }
158-
159- $ this ->routers [] = (object ) [
160- 'level ' => max (0 , $ level ),
161- 'matched ' => $ matched ,
162- 'class ' => get_class ($ router ),
163- 'defaults ' => $ router instanceof Routing \Route || $ router instanceof Routing \SimpleRouter ? $ router ->getDefaults () : [],
164- 'mask ' => $ router instanceof Routing \Route ? $ router ->getMask () : null ,
165- 'params ' => $ params ,
166- 'module ' => rtrim ($ module , ': ' ),
167- 'path ' => $ path ,
168- 'error ' => $ e ,
169- ];
170150 }
171151
172152
0 commit comments