8000 [Routing] Fix suffix aggregation · symfony/symfony@83feffc · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 83feffc

Browse files
[Routing] Fix suffix aggregation
1 parent e0bdc0c commit 83feffc

File tree

3 files changed

+102
-5
lines changed

3 files changed

+102
-5
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,16 @@ public function getRoutes(): array
6363
*
6464
* @param array|self $route
6565
*/
66-
public function addRoute(string $prefix, $route, string $staticPrefix = null)
66+
public function addRoute(string $prefix, $route)
6767
{
6868
$this->guardAgainstAddingNotAcceptedRoutes($prefix);
69-
if (null === $staticPrefix) {
70-
list($prefix, $staticPrefix) = $this->getCommonPrefix($prefix, $prefix);
71-
}
69+
list($prefix, $staticPrefix) = $this->getCommonPrefix($prefix, $prefix);
7270

7371
for ($i = \count($this->items) - 1; 0 <= $i; --$i) {
7472
$item = $this->items[$i];
7573

7674
if ($item instanceof self && $item->accepts($prefix)) {
77-
$item->addRoute($prefix, $route, $staticPrefix);
75+
$item->addRoute($prefix, $route);
7876

7977
return;
8078
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
4+
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
5+
use Symfony\Component\Routing\RequestContext;
6+
7+
/**
8+
* This class has been auto-generated
9+
* by the Symfony Routing Component.
10+
*/
11+
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
12+
{
13+
public function __construct(RequestContext $context)
14+
{
15+
$this->context = $context;
16+
}
17+
18+
public function match($rawPathinfo)
19+
{
20+
$allow = array();
21+
$pathinfo = rawurldecode($rawPathinfo);
22+
$trimmedPathinfo = rtrim($pathinfo, '/');
23+
$context = $this->context;
24+
$requestMethod = $canonicalMethod = $context->getMethod();
25+
26+
if ('HEAD' === $requestMethod) {
27+
$canonicalMethod = 'GET';
28+
}
29+
30+
$matchedPathinfo = $pathinfo;
31+
$regexList = array(
32+
0 => '{^(?'
33+
.'|/abc([^/]++)(?'
34+
.'|/1(*:24)'
35+
.'|/2(?'
36+
.'|(*:36)'
37+
.'|0(?'
38+
.'|(*:47)'
39+
.'|0(*:55)'
40+
.')'
41+
.')'
42+
.'|/10(?'
43+
.'|(*:70)'
44+
.'|0(*:78)'
45+
.')'
46+
.')'
47+
.')$}sD',
48+
);
49+
50+
foreach ($regexList as $offset => $regex) {
51+
while (preg_match($regex, $matchedPathinfo, $matches)) {
52+
switch ($m = (int) $matches['MARK']) {
53+
default:
54+
$routes = array(
55+
24 => array(array('_route' => 'r1'), array('foo'), null, null),
56+
36 => array(array('_route' => 'r2'), array('foo'), null, null),
57+
47 => array(array('_route' => 'r20'), array('foo'), null, null),
58+
55 => array(array('_route' => 'r200'), array('foo'), null, null),
59+
70 => array(array('_route' => 'r10'), array('foo'), null, null),
60+
78 => array(array('_route' => 'r100'), array('foo'), null, null),
61+
);
62+
63+
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
64+
65+
foreach ($vars as $i => $v) {
66+
if (isset($matches[1 + $i])) {
67+
$ret[$v] = $matches[1 + $i];
68+
}
69+
}
70+
71+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
72+
$allow += $requiredMethods;
73+
break;
74+
}
75+
76+
return $ret;
77+
}
78+
79+
if (78 === $m) {
80+
break;
81+
}
82+
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));
83+
$offset += strlen($m);
84+
}
85+
}
86+
87+
throw $allow ? new MethodNotAllowedException(array_keys($allow)) : new ResourceNotFoundException();
88+
}
89+
}

src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ public function getRouteCollections()
458458
$demoCollection->addRequirements(array('_locale' => 'en|fr'));
459459
$demoCollection->addDefaults(array('_locale' => 'en'));
460460

461+
/* test case 12 */
462+
$suffixCollection = new RouteCollection();
463+
$suffixCollection->add('r1', new Route('abc{foo}/1'));
464+
$suffixCollection->add('r2', new Route('abc{foo}/2'));
465+
$suffixCollection->add('r10', new Route('abc{foo}/10'));
466+
$suffixCollection->add('r20', new Route('abc{foo}/20'));
467+
$suffixCollection->add('r100', new Route('abc{foo}/100'));
468+
$suffixCollection->add('r200', new Route('abc{foo}/200'));
469+
461470
return array(
462471
array(new RouteCollection(), 'url_matcher0.php', array()),
463472
array($collection, 'url_matcher1.php', array()),
@@ -471,6 +480,7 @@ public function getRouteCollections()
471480
array($hostTreeCollection, 'url_matcher9.php', array()),
472481
array($chunkedCollection, 'url_matcher10.php', array()),
473482
array($demoCollection, 'url_matcher11.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
483+
array($suffixCollection, 'url_matcher12.php', array()),
474484
);
475485
}
476486

0 commit comments

Comments
 (0)
0