diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index bee7a4a5694c3..cd137eea78be0 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -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'])) { diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index a3284771bb579..b661bb13a61de 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -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]; diff --git a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php index 05d3d0162ad1e..90a66dbc679eb 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php @@ -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()); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy