8000 bug #52845 [Routing] Restore aliases removal in RouteCollection::remo… · symfonyaml/symfony@e88a7f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e88a7f7

Browse files
bug symfony#52845 [Routing] Restore aliases removal in RouteCollection::remove() (fancyweb)
This PR was merged into the 5.4 branch. Discussion ---------- [Routing] Restore aliases removal in RouteCollection::remove() | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | symfony#52806 (comment) | License | MIT As suggested in symfony#52831 (comment) It's still a small behavior change on 5.4, let's see what people think 😃 Commits ------- 3c6dc17 [Routing] Restore aliases removal in RouteCollection::remove()
2 parents 735959c + 3c6dc17 commit e88a7f7

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,21 @@ public function get(string $name)
157157
*/
158158
public function remove($name)
159159
{
160-
$names = (array) $name;
161-
foreach ($names as $n) {
< 8000 /code>
162-
unset($this->routes[$n], $this->priorities[$n]);
160+
$routes = [];
161+
foreach ((array) $name as $n) {
162+
if (isset($this->routes[$n])) {
163+
$routes[] = $n;
164+
}
165+
166+
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
167+
}
168+
169+
if (!$routes) {
170+
return;
163171
}
164172

165173
foreach ($this->aliases as $k => $alias) {
166-
if (\in_array($alias->getId(), $names, true)) {
174+
if (\in_array($alias->getId(), $routes, true)) {
167175
unset($this->aliases[$k]);
168176
}
169177
}

src/Symfony/Component/Routing/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)
0