Skip to content

Commit

Permalink
kept routes priorities after add a name prefix to the collection
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Jun 9, 2020
1 parent 6d6d989 commit 2108fd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Routing/RouteCollection.php
Expand Up @@ -179,8 +179,8 @@ public function addNamePrefix(string $prefix)

foreach ($this->routes as $name => $route) {
$prefixedRoutes[$prefix.$name] = $route;
if (null !== $name = $route->getDefault('_canonical_route')) {
$route->setDefault('_canonical_route', $prefix.$name);
if (null !== $canonicalName = $route->getDefault('_canonical_route')) {
$route->setDefault('_canonical_route', $prefix.$canonicalName);
}
if (isset($this->priorities[$name])) {
$prefixedPriorities[$prefix.$name] = $this->priorities[$name];
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Expand Up @@ -362,5 +362,19 @@ public function testAddWithPriority()
];

$this->assertSame($expected, $collection2->all());

$collection3 = new RouteCollection();
$collection3->add('foo3', $foo3 = new Route('/foo'), 0);
$collection3->add('bar3', $bar3 = new Route('/bar'), 1);
$collection3->add('baz3', $baz3 = new Route('/baz'));
$collection3->addNamePrefix('prefix_');

$expected = [
'prefix_bar3' => $bar3,
'prefix_foo3' => $foo3,
'prefix_baz3' => $baz3,
];

$this->assertSame($expected, $collection3->all());
}
}

0 comments on commit 2108fd1

Please sign in to comment.