Skip to content

Commit cb74042

Browse files
Merge branch '5.4' into 6.3
* 5.4: Fix support to denormalize plain object types [Routing] Restore aliases removal in RouteCollection::remove() remove duplicated service definition
2 parents 3f14efc + 5b5b866 commit cb74042

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

RouteCollection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ public function get(string $name): ?Route
147147
*/
148148
public function remove(string|array $name)
149149
{
150-
$names = (array) $name;
151-
foreach ($names as $n) {
152-
unset($this->routes[$n], $this->priorities[$n]);
150+
$routes = [];
151+
foreach ((array) $name as $n) {
152+
if (isset($this->routes[$n])) {
153+
$routes[] = $n;
154+
}
155+
156+
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
157+
}
158+
159+
if (!$routes) {
160+
return;
153161
}
154162

155163
foreach ($this->aliases as $k => $alias) {
156-
if (\in_array($alias->getId(), $names, true)) {
164+
if (\in_array($alias->getId(), $routes, true)) {
157165
unset($this->aliases[$k]);
158166
}
159167
}

Tests/RouteCollectionTest.php

Lines changed: 6 additions & 3 deletions
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)