File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 14
14
use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
15
15
use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
16
16
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
17
+ use Symfony \Component \Routing \Matcher \UrlMatcher ;
18
+ use Symfony \Component \Routing \Matcher \UrlMatcherInterface ;
17
19
use Symfony \Component \Routing \RouterInterface ;
18
20
19
21
/**
@@ -60,10 +62,24 @@ public function createFromPreviousAndProps(
60
62
61
63
private function createPath (string $ previousUrl , array $ props ): string
62
64
{
63
- return $ this ->router ->generate (
64
- $ this ->router -> match ($ previousUrl )[ ' _route ' ] ?? '' ,
65
+ $ newPath = $ this ->router ->generate (
66
+ $ this ->matchRoute ($ previousUrl ),
65
67
$ props
66
68
);
69
+
70
+ return $ newPath ;
71
+ }
72
+
73
+ private function matchRoute (string $ previousUrl ): string
74
+ {
75
+ $ context = $ this ->router ->getContext ();
76
+ $ tmpContext = clone $ context ;
77
+ $ tmpContext ->setMethod ('GET ' );
78
+ $ this ->router ->setContext ($ tmpContext );
79
+ $ match = $ this ->router ->match ($ previousUrl );
80
+ $ this ->router ->setContext ($ context );
81
+
82
+ return $ match ['_route ' ] ?? '' ;
67
83
}
68
84
69
85
private function replaceQueryString ($ url , array $ props ): string
Original file line number Diff line number Diff line change 15
15
use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
16
16
use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
17
17
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
18
+ use Symfony \Component \Routing \RequestContext ;
18
19
use Symfony \Component \Routing \RouterInterface ;
19
20
use Symfony \UX \LiveComponent \Util \UrlFactory ;
20
21
@@ -178,7 +179,13 @@ private function createRouterStub(
178
179
array $ props = [],
179
180
): RouterInterface {
180
181
$ matchedRoute = 'default ' ;
182
+ $ context = $ this ->createMock (RequestContext::class);
181
183
$ 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 ' );
182
189
$ router ->expects (self ::once ())
183
190
->method ('match ' )
184
191
->with ($ previousUrl )
You can’t perform that action at this time.
0 commit comments