@@ -89,34 +89,33 @@ private function analyse(
8989 Routing \Router $ router ,
9090 ?Nette \Http \IRequest $ httpRequest ,
9191 string $ module = '' ,
92- ?string $ path = null ,
92+ string $ path = '' ,
93+ ?\Closure $ afterMatch = null ,
9394 int $ level = -1 ,
9495 int $ flag = 0
9596 ): void
9697 {
98+ $ afterMatch = $ afterMatch ?? function ($ params ) { return $ params ; };
99+
97100 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 ;
103- }
104- }
101+ $ path .= $ router ->getPath ();
102+ $ module .= ($ router instanceof Nette \Application \Routers \RouteList ? $ router ->getModule () : '' );
105103
106- $ prop = (new \ReflectionProperty (Routing \RouteList::class, 'path ' ));
107- $ prop ->setAccessible (true );
108- if ($ httpRequest && ($ pathPrefix = $ prop ->getValue ($ router ))) {
109- $ path .= $ pathPrefix ;
110- $ url = $ httpRequest ->getUrl ();
111- $ httpRequest = $ httpRequest ->withUrl ($ url ->withPath ($ url ->getPath (), $ url ->getBasePath () . $ pathPrefix ));
112- }
104+ $ httpRequest = $ httpRequest
105+ ? (new \ReflectionMethod ($ router , 'beforeMatch ' ))->invoke ($ router , $ httpRequest )
106+ : null ;
113107
114- $ module .= ($ router instanceof Nette \Application \Routers \RouteList ? $ router ->getModule () : '' );
108+ $ afterMatch = function ($ params ) use ($ router , $ afterMatch ) {
109+ $ params = $ params === null
110+ ? null
111+ : (new \ReflectionMethod ($ router , 'afterMatch ' ))->invoke ($ router , $ params );
112+ return $ afterMatch ($ params );
113+ };
115114
116115 $ next = count ($ this ->routers );
117116 $ flags = $ router ->getFlags ();
118- foreach ($ router ->getRouters () as $ i => $ subRouter ) {
119- $ this ->analyse ($ subRouter , $ httpRequest , $ module , $ path , $ level + 1 , $ flags [$ i ]);
117+ foreach ($ router ->getRouters () as $ i => $ innerRouter ) {
118+ $ this ->analyse ($ innerRouter , $ httpRequest , $ module , $ path, $ afterMatch , $ level + 1 , $ flags [$ i ]);
120119 }
121120
122121 if ($ info = $ this ->routers [$ next ] ?? null ) {
@@ -133,18 +132,12 @@ private function analyse(
133132 $ matched = $ flag & Routing \RouteList::ONE_WAY ? 'oneway ' : 'no ' ;
134133 $ params = $ e = null ;
135134 try {
136- $ params = $ httpRequest
137- ? $ router ->match ($ httpRequest )
138- : null ;
135+ $ params = $ httpRequest ? $ afterMatch ($ router ->match ($ httpRequest )) : null ;
139136 } catch (\Throwable $ e ) {
140137 $ matched = 'error ' ;
141138 }
142139
143140 if ($ params !== null ) {
144- if ($ module ) {
145- $ params ['presenter ' ] = $ module . ($ params ['presenter ' ] ?? '' );
146- }
147-
148141 $ matched = 'may ' ;
149142 if ($ this ->matched === null ) {
150143 $ this ->matched = $ params ;
0 commit comments