Skip to content

Commit fc55062

Browse files
Merge branch '6.4' into 7.0
* 6.4: [Serializer] Remove TranslatableNormalizer service when the Translator is disabled Fix support to denormalize plain object types [Routing] Restore aliases removal in RouteCollection::remove() [Workflow] Add `getEnabledTransition()` to TraceableWorkflow [DependencyInjection] Fix parsing named autowiring aliases that contain underscores [Console] Add Les-Tilleuls.coop as sponsor of version 6.4/7.0 remove duplicated service definition
2 parents 2d5fe14 + 0c95c16 commit fc55062

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

RouteCollection.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,21 @@ public function get(string $name): ?Route
142142
*/
143143
public function remove(string|array $name): void
144144
{
145-
$names = (array) $name;
146-
foreach ($names as $n) {
147-
unset($this->routes[$n], $this->priorities[$n]);
145+
$routes = [];
146+
foreach ((array) $name as $n) {
147+
if (isset($this->routes[$n])) {
148+
$routes[] = $n;
149+
}
150+
151+
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
152+
}
153+
154+
if (!$routes) {
155+
return;
148156
}
149157

150158
foreach ($this->aliases as $k => $alias) {
151-
if (\in_array($alias->getId(), $names, true)) {
159+
if (\in_array($alias->getId(), $routes, true)) {
152160
unset($this->aliases[$k]);
153161
}
154162
}

Tests/RouteCollectionTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,22 @@ public function testGet()
219219
public function testRemove()
220220
{
221221
$collection = new RouteCollection();
222-
$collection->add('foo', $foo = new Route('/foo'));
222+
$collection->add('foo', new Route('/foo'));
223223

224224
$collection1 = new RouteCollection();
225225
$collection1->add('bar', $bar = new Route('/bar'));
226226
$collection->addCollection($collection1);
227227
$collection->add('last', $last = new Route('/last'));
228-
$collection->addAlias('ccc_my_custom_alias', 'foo');
228+
$collection->addAlias('alias_removed_when_removing_route_foo', 'foo');
229+
$collection->addAlias('alias_directly_removed', 'bar');
229230

230231
$collection->remove('foo');
231232
$this->assertSame(['bar' => $bar, 'last' => $last], $collection->all(), '->remove() can remove a single route');
233+
$collection->remove('alias_directly_removed');
234+
$this->assertNull($collection->getAlias('alias_directly_removed'));
232235
$collection->remove(['bar', 'last']);
233236
$this->assertSame([], $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
234-
$this->assertNull($collection->getAlias('ccc_my_custom_alias'));
237+
$this->assertNull($collection->getAlias('alias_removed_when_removing_route_foo'));
235238
}
236239

237240
public function testSetHost()

0 commit comments

Comments
 (0)