Skip to content

Commit bbd0ba1

Browse files
committed
kept routes priorities after add a name prefix to the collection
1 parent 95cf301 commit bbd0ba1

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected function parseImport(RouteCollection $collection, array $config, strin
171171
$schemes = isset($config['schemes']) ? $config['schemes'] : null;
172172
$methods = isset($config['methods']) ? $config['methods'] : null;
173173
$trailingSlashOnRoot = $config['trailing_slash_on_root'] ?? true;
174-
$namePrefix = $config['name_prefix'] ?? '';
174+
$namePrefix = $config['name_prefix'] ?? null;
175175
$exclude = $config['exclude'] ?? null;
176176

177177
if (isset($config['controller'])) {

RouteCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public function addNamePrefix(string $prefix)
179179

180180
foreach ($this->routes as $name => $route) {
181181
$prefixedRoutes[$prefix.$name] = $route;
182-
if (null !== $name = $route->getDefault('_canonical_route')) {
183-
$route->setDefault('_canonical_route', $prefix.$name);
182+
if (null !== $canonicalName = $route->getDefault('_canonical_route')) {
183+
$route->setDefault('_canonical_route', $prefix.$canonicalName);
184184
}
185185
if (isset($this->priorities[$name])) {
186186
$prefixedPriorities[$prefix.$name] = $this->priorities[$name];

Tests/RouteCollectionTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,21 @@ public function testAddWithPriority()
363363

364364
$this->assertSame($expected, $collection2->all());
365365
}
366+
367+
public function testAddWithPriorityAndPrefix()
368+
{
369+
$collection3 = new RouteCollection();
370+
$collection3->add('foo3', $foo3 = new Route('/foo'), 0);
371+
$collection3->add('bar3', $bar3 = new Route('/bar'), 1);
372+
$collection3->add('baz3', $baz3 = new Route('/baz'));
373+
$collection3->addNamePrefix('prefix_');
374+
375+
$expected = [
376+
'prefix_bar3' => $bar3,
377+
'prefix_foo3' => $foo3,
378+
'prefix_baz3' => $baz3,
379+
];
380+
381+
$this->assertSame($expected, $collection3->all());
382+
}
366383
}

0 commit comments

Comments
 (0)