8000 [Routing] Ensure uniqueness without repeated check · symfony/symfony@16f7281 · GitHub
[go: up one dir, main page]

Skip to content

Commit < 10000 span class="text-mono bgColor-muted rounded p-1">16f7281

Browse files
endroidfabpot
authored andcommitted
[Routing] Ensure uniqueness without repeated check
1 parent 42390a2 commit 16f7281

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public function addCollection(RouteCollection $collection)
128128
$this->routes[$name] = $route;
129129
}
130130

131-
$this->resources = array_merge($this->resources, $collection->getResources());
131+
foreach ($collection->getResources() as $resource) {
132+
$this->addResource($resource);
133+
}
132134
}
133135

134136
/**
@@ -262,16 +264,21 @@ public function setMethods($methods)
262264
*/
263265
public function getResources()
264266
{
265-
return array_unique($this->resources);
267+
return array_values($this->resources);
266268
}
267269

268270
/**
269-
* Adds a resource for this collection.
271+
* Adds a resource for this collection. If the resource already exists
272+
* it is not added.
270273
*
271274
* @param ResourceInterface $resource A resource instance
272275
*/
273276
public function addResource(ResourceInterface $resource)
274277
{
275-
$this->resources[] = $resource;
278+
$key = (string) $resource;
279+
280+
if (!isset($this->resources[$key])) {
281+
$this->resources[$key] = $resource;
282+
}
276283
}
277284
}

0 commit comments

Comments
 (0)
0