File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,27 @@ public function createFromPreviousAndProps(
6060
6161 private function createPath (string $ previousUrl , array $ props ): string
6262 {
63- return $ this ->router ->generate (
64- $ this ->router -> match ($ previousUrl )[ ' _route ' ] ?? '' ,
63+ $ newPath = $ this ->router ->generate (
64+ $ this ->matchRoute ($ previousUrl ),
6565 $ props
6666 );
67+
68+ return $ newPath ;
69+ }
70+
71+ private function matchRoute (string $ previousUrl ): string
72+ {
73+ $ context = $ this ->router ->getContext ();
74+ $ tmpContext = clone $ context ;
75+ $ tmpContext ->setMethod ('GET ' );
76+ $ this ->router ->setContext ($ tmpContext );
77+ try {
78+ $ match = $ this ->router ->match ($ previousUrl );
79+ } finally {
80+ $ this ->router ->setContext ($ context );
81+ }
82+
83+ return $ match ['_route ' ] ?? '' ;
6784 }
6885
6986 private function replaceQueryString ($ url , array $ props ): string
Original file line number Diff line number Diff line change 1515use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
1616use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
1717use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
18+ use Symfony \Component \Routing \RequestContext ;
1819use Symfony \Component \Routing \RouterInterface ;
1920use Symfony \UX \LiveComponent \Util \UrlFactory ;
2021
@@ -178,7 +179,13 @@ private function createRouterStub(
178179 array $ props = [],
179180 ): RouterInterface {
180181 $ matchedRoute = 'default ' ;
182+ $ context = $ this ->createMock (RequestContext::class);
181183 $ router = $ this ->createMock (RouterInterface::class);
184+ $ router ->expects (self ::once ())
185+ ->method ('getContext ' )
186+ ->willReturn ($ context );
187+ $ router ->expects (self ::exactly (2 ))
188+ ->method ('setContext ' );
182189 $ router ->expects (self ::once ())
183190 ->method ('match ' )
184191 ->with ($ previousUrl )
You can’t perform that action at this time.
0 commit comments