Skip to content

Commit

Permalink
bug #37176 [Routing] Keeping routes priorities after add a name prefi…
Browse files Browse the repository at this point in the history
…x to the collection (yceruto)

This PR was merged into the 5.1 branch.

Discussion
----------

[Routing] Keeping routes priorities after add a name prefix to the collection

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37089
| License       | MIT
| Doc PR        | -

Commits
-------

1010526 kept routes priorities after add a name prefix to the collection
  • Loading branch information
fabpot committed Jun 10, 2020
2 parents 292be5f + 1010526 commit 7c892ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Expand Up @@ -171,7 +171,7 @@ protected function parseImport(RouteCollection $collection, array $config, strin
$schemes = isset($config['schemes']) ? $config['schemes'] : null;
$methods = isset($config['methods']) ? $config['methods'] : null;
$trailingSlashOnRoot = $config['trailing_slash_on_root'] ?? true;
$namePrefix = $config['name_prefix'] ?? '';
$namePrefix = $config['name_prefix'] ?? null;
$exclude = $config['exclude'] ?? null;

if (isset($config['controller'])) {
Expand Down
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
17 changes: 17 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Expand Up @@ -363,4 +363,21 @@ public function testAddWithPriority()

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

public function testAddWithPriorityAndPrefix()
{
$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 7c892ee

Please sign in to comment.