Skip to content

Commit 4d2abea

Browse files
committed
Merge branch '4.1'
* 4.1: Supress deprecation notices thrown when getting private servies from container in tests Uses `protected` for test functions [Messenger] Allow to scope handlers per bus do not mock the session in token storage tests [DependencyInjection] resolve array env vars Add Occitan plural rule Fix security/* cross-dependencies [Messenger] implement several senders using a ChainSender [Lock] Skip test if posix extension is not installed fix bug when imported routes are prefixed [DI] Allow defining bindings on ChildDefinition use strict compare in url validator Disallow illegal characters like "." in session.name [HttpKernel] do file_exists() check instead of silent notice Select alternatives on missing receiver arg or typo fix rounding from string
2 parents b31d6eb + 54c81d2 commit 4d2abea

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

RouteCollection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public function addNamePrefix(string $prefix)
162162

163163
foreach ($this->routes as $name => $route) {
164164
$prefixedRoutes[$prefix.$name] = $route;
165+
if (null !== $name = $route->getDefault('_canonical_route')) {
166+
$route->setDefault('_canonical_route', $prefix.$name);
167+
}
165168
}
166169

167170
$this->routes = $prefixedRoutes;

Tests/RouteCollectionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,17 @@ public function testAddNamePrefix()
317317
$this->assertNull($collection->get('foo'));
318318
$this->assertNull($collection->get('bar'));
319319
}
320+
321+
public function testAddNamePrefixCanonicalRouteName()
322+
{
323+
$collection = new RouteCollection();
324+
$collection->add('foo', new Route('/foo', array('_canonical_route' => 'foo')));
325+
$collection->add('bar', new Route('/bar', array('_canonical_route' => 'bar')));
326+
$collection->add('api_foo', new Route('/api/foo', array('_canonical_route' => 'api_foo')));
327+
$collection->addNamePrefix('api_');
328+
329+
$this->assertEquals('api_foo', $collection->get('api_foo')->getDefault('_canonical_route'));
330+
$this->assertEquals('api_bar', $collection->get('api_bar')->getDefault('_canonical_route'));
331+
$this->assertEquals('api_api_foo', $collection->get('api_api_foo')->getDefault('_canonical_route'));
332+
}
320333
}

0 commit comments

Comments
 (0)