@@ -89,34 +89,33 @@ private function analyse(
89
89
Routing \Router $ router ,
90
90
?Nette \Http \IRequest $ httpRequest ,
91
91
string $ module = '' ,
92
- ?string $ path = null ,
92
+ string $ path = '' ,
93
+ ?\Closure $ afterMatch = null ,
93
94
int $ level = -1 ,
94
95
int $ flag = 0
95
96
): void
96
97
{
98
+ $ afterMatch = $ afterMatch ?? function ($ params ) { return $ params ; };
99
+
97
100
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 () : '' );
105
103
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 ;
113
107
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
+ };
115
114
116
115
$ next = count ($ this ->routers );
117
116
$ 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 ]);
120
119
}
121
120
122
121
if ($ info = $ this ->routers [$ next ] ?? null ) {
@@ -133,18 +132,12 @@ private function analyse(
133
132
$ matched = $ flag & Routing \RouteList::ONE_WAY ? 'oneway ' : 'no ' ;
134
133
$ params = $ e = null ;
135
134
try {
136
- $ params = $ httpRequest
137
- ? $ router ->match ($ httpRequest )
138
- : null ;
135
+ $ params = $ httpRequest ? $ afterMatch ($ router ->match ($ httpRequest )) : null ;
139
136
} catch (\Throwable $ e ) {
140
137
$ matched = 'error ' ;
141
138
}
142
139
143
140
if ($ params !== null ) {
144
- if ($ module ) {
145
- $ params ['presenter ' ] = $ module . ($ params ['presenter ' ] ?? '' );
146
- }
147
-
148
141
$ matched = 'may ' ;
149
142
if ($ this ->matched === null ) {
150
143
$ this ->matched = $ params ;
0 commit comments