Skip to content

Commit 38ef48f

Browse files
committed
[LiveComponent] Fix LiveUrl : use custom UrlMatcher to not depend of the current context
1 parent 337b860 commit 38ef48f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/LiveComponent/src/Util/UrlFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@
1414
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1515
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
1616
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
17+
use Symfony\Component\Routing\Matcher\UrlMatcher;
18+
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
1719
use Symfony\Component\Routing\RouterInterface;
1820

1921
/**
2022
* @internal
2123
*/
2224
class UrlFactory
2325
{
26+
private UrlMatcherInterface $matcher;
27+
2428
public function __construct(
2529
private RouterInterface $router,
2630
) {
31+
$context = clone $this->router->getContext();
32+
$context->setMethod('GET');
33+
$this->matcher = new UrlMatcher(
34+
routes: $this->router->getRouteCollection(),
35+
context: $context,
36+
);
2737
}
2838

2939
public function createFromPreviousAndProps(
@@ -61,7 +71,7 @@ public function createFromPreviousAndProps(
6171
private function createPath(string $previousUrl, array $props): string
6272
{
6373
return $this->router->generate(
64-
$this->router->match($previousUrl)['_route'] ?? '',
74+
$this->matcher->match($previousUrl)['_route'] ?? '',
6575
$props
6676
);
6777
}

0 commit comments

Comments
 (0)