@@ -147,6 +147,7 @@ public function match(Request $request, int $pathOffset = 0, array $options = []
147147 {
148148 $ partialResult = $ this ->route ->partialMatch ($ request , $ pathOffset , $ options );
149149
150+ // no match, bail out
150151 if ($ partialResult ->isFailure () && ! $ partialResult ->isMethodFailure ()) {
151152 return RouteResult::fromRouteFailure ();
152153 }
@@ -162,54 +163,54 @@ public function match(Request $request, int $pathOffset = 0, array $options = []
162163 return RouteResult::fromMethodFailure ($ partialResult ->getAllowedMethods ());
163164 }
164165
166+ // @TODO get rid of lazy routes
165167 if ($ this ->childRoutes !== null ) {
166168 $ this ->addRoutes ($ this ->childRoutes );
167169 $ this ->childRoutes = null ;
168170 }
169171
170- $ nextOffset = $ pathOffset + $ partialResult ->getMatchedPathLength ();
171-
172- if (isset ($ options ['translator ' ])
173- && ! isset ($ options ['locale ' ])
174- && $ partialResult ->isSuccess ()
175- && null !== ($ locale = $ partialResult ->getMatchedParams ()['locale ' ] ?? null )
176- ) {
177- $ options ['locale ' ] = $ locale ;
172+ // pass matched params to child routes.
173+ // Could be used for obtaining locale from parent route match.
174+ if ($ partialResult ->isSuccess ()) {
175+ $ options ['parent_match_params ' ] = $ options ['parent_match_params ' ] ?? [];
176+ $ options ['parent_match_params ' ] += $ partialResult ->getMatchedParams ();
178177 }
179178
180- $ gatherMethods = $ options ['gather_allowed_methods ' ] ?? false ;
181179 if ($ partialResult ->isMethodFailure ()) {
180+ // we got partial method failure, keep matching to find all allowed methods
182181 $ options ['gather_allowed_methods ' ] = true ;
183182 }
184183
184+ // match child routes
185+ $ nextOffset = $ pathOffset + $ partialResult ->getMatchedPathLength ();
185186 $ result = parent ::match ($ request , $ nextOffset , $ options );
186187 if ($ result ->isFailure () && ! $ result ->isMethodFailure ()) {
187188 return $ result ;
188189 }
189- if ($ partialResult ->isMethodFailure ()) {
190- $ allowed = $ partialResult ->getAllowedMethods ();
191- if (! empty ($ methods = $ result ->getAllowedMethods ())) {
192- $ allowed = \array_intersect ($ allowed , $ methods );
190+
191+ // gather allowed methods
192+ $ partialAllowed = $ partialResult ->getAllowedMethods ();
193+ $ childAllowed = $ result ->getAllowedMethods ();
194+ if (null !== $ partialAllowed && null !== $ childAllowed ) {
195+ $ allowed = \array_intersect ($ partialAllowed , $ childAllowed );
196+ } else {
197+ $ allowed = $ partialAllowed ?? $ childAllowed ;
198+ }
199+
200+ // was it a method failure?
201+ if ($ partialResult ->isMethodFailure () || $ result ->isMethodFailure ()) {
202+ if (empty ($ allowed )) {
203+ return RouteResult::fromRouteFailure ();
193204 }
194205 return RouteResult::fromMethodFailure ($ allowed );
195206 }
196- if ($ result ->isMethodFailure ()) {
197- return $ result ;
198- }
207+
208+ // we got success
199209 $ return = RouteResult::fromRouteMatch (
200210 \array_merge ($ partialResult ->getMatchedParams (), $ result ->getMatchedParams ()),
201211 $ result ->getMatchedRouteName ()
202212 );
203- $ allowed = $ partialResult ->getAllowedMethods ();
204- $ nested = $ result ->getAllowedMethods ();
205- if (! empty ($ allowed ) && ! empty ($ nested )) {
206- $ allowed = \array_intersect ($ allowed , $ nested );
207- }
208- $ allowed = $ allowed ?? $ nested ;
209- if (! empty ($ allowed )) {
210- $ return ->withAllowedMethods ($ allowed );
211- }
212- return $ return ;
213+ return $ return ->withAllowedMethods ($ allowed );
213214 }
214215
215216 /**
0 commit comments