[Routing] fix dumping same-path routes with placeholders
This commit is contained in:
parent
9455c0b233
commit
94a143011a
@ -526,15 +526,10 @@ EOF;
|
||||
);
|
||||
} else {
|
||||
$prevRegex = $compiledRoute->getRegex();
|
||||
$combine = ' $matches = array(';
|
||||
foreach ($vars as $j => $m) {
|
||||
$combine .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
|
||||
}
|
||||
$combine = $vars ? substr_replace($combine, ");\n\n", -2) : '';
|
||||
|
||||
$state->switch .= <<<EOF
|
||||
case {$state->mark}:
|
||||
{$combine}{$this->compileRoute($route, $name, false, $hasTrailingSlash)}
|
||||
{$this->compileRoute($route, $name, false, $hasTrailingSlash, $vars)}
|
||||
break;
|
||||
|
||||
EOF;
|
||||
@ -621,7 +616,7 @@ EOF;
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash): string
|
||||
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash, array $vars = null): string
|
||||
{
|
||||
$compiledRoute = $route->compile();
|
||||
$conditions = array();
|
||||
@ -669,6 +664,14 @@ EOF;
|
||||
);
|
||||
}
|
||||
|
||||
if ($vars) {
|
||||
$code .= ' $matches = array(';
|
||||
foreach ($vars as $j => $m) {
|
||||
$code .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
|
||||
}
|
||||
$code = substr_replace($code, ");\n\n", -2);
|
||||
}
|
||||
|
||||
if ($route->getCondition()) {
|
||||
$expression = $this->getExpressionLanguage()->compile($route->getCondition(), array('context', 'request'));
|
||||
|
||||
|
@ -139,8 +139,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||
switch ($m = (int) $matches['MARK']) {
|
||||
case 115:
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
// baz4
|
||||
if ('/' !== $pathinfo[-1]) {
|
||||
goto not_baz4;
|
||||
@ -149,6 +147,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$matches = $n;
|
||||
}
|
||||
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||
not_baz4:
|
||||
|
||||
@ -188,13 +188,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
|
||||
break;
|
||||
case 160:
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
// foo1
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
goto not_foo1;
|
||||
}
|
||||
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
||||
$allow += $a;
|
||||
@ -206,25 +206,25 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
|
||||
break;
|
||||
case 204:
|
||||
$matches = array('foo1' => $matches[1] ?? null);
|
||||
|
||||
// foo2
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
goto not_foo2;
|
||||
}
|
||||
|
||||
$matches = array('foo1' => $matches[1] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||
not_foo2:
|
||||
|
||||
break;
|
||||
case 279:
|
||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
// foo3
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
goto not_foo3;
|
||||
}
|
||||
|
||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||
not_foo3:
|
||||
|
||||
|
@ -42,13 +42,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||
switch ($m = (int) $matches['MARK']) {
|
||||
case 56:
|
||||
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
// r1
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
goto not_r1;
|
||||
}
|
||||
|
||||
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
|
||||
not_r1:
|
||||
|
||||
|
@ -179,8 +179,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||
switch ($m = (int) $matches['MARK']) {
|
||||
case 115:
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
// baz4
|
||||
if ('/' !== $pathinfo[-1]) {
|
||||
if ('GET' === $canonicalMethod) {
|
||||
@ -192,6 +190,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$matches = $n;
|
||||
}
|
||||
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||
not_baz4:
|
||||
|
||||
@ -231,13 +231,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
|
||||
break;
|
||||
case 160:
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
// foo1
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
goto not_foo1;
|
||||
}
|
||||
|
||||
$matches = array('foo' => $matches[1] ?? null);
|
||||
|
||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
||||
$allow += $a;
|
||||
@ -249,8 +249,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
|
||||
break;
|
||||
case 204:
|
||||
$matches = array('foo1' => $matches[1] ?? null);
|
||||
|
||||
// foo2
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
if ('GET' === $canonicalMethod) {
|
||||
@ -259,13 +257,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
goto not_foo2;
|
||||
}
|
||||
|
||||
$matches = array('foo1' => $matches[1] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||
not_foo2:
|
||||
|
||||
break;
|
||||
case 279:
|
||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
// foo3
|
||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||
if ('GET' === $canonicalMethod) {
|
||||
@ -274,6 +272,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
goto not_foo3;
|
||||
}
|
||||
|
||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||
|
||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||
not_foo3:
|
||||
|
||||
|
Reference in New Issue
Block a user