Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / routing / RouteCollection.php
index 2ccb90f3b096696963487f9a726cf83d63341a48..e22cbc5f2e0c79c95e17b681384ed034a1ca5c67 100644 (file)
@@ -104,7 +104,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
     /**
      * Removes a route or an array of routes by name from the collection.
      *
-     * @param string|array $name The route name or an array of route names
+     * @param string|string[] $name The route name or an array of route names
      */
     public function remove($name)
     {
@@ -116,10 +116,8 @@ class RouteCollection implements \IteratorAggregate, \Countable
     /**
      * Adds a route collection at the end of the current set by appending all
      * routes of the added collection.
-     *
-     * @param RouteCollection $collection A RouteCollection instance
      */
-    public function addCollection(RouteCollection $collection)
+    public function addCollection(self $collection)
     {
         // we need to remove all routes with the same names first because just replacing them
         // would not place the new route at the end of the merged array
@@ -128,7 +126,9 @@ class RouteCollection implements \IteratorAggregate, \Countable
             $this->routes[$name] = $route;
         }
 
-        $this->resources = array_merge($this->resources, $collection->getResources());
+        foreach ($collection->getResources() as $resource) {
+            $this->addResource($resource);
+        }
     }
 
     /**
@@ -234,7 +234,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
     /**
      * Sets the schemes (e.g. 'https') all child routes are restricted to.
      *
-     * @param string|array $schemes The scheme or an array of schemes
+     * @param string|string[] $schemes The scheme or an array of schemes
      */
     public function setSchemes($schemes)
     {
@@ -246,7 +246,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
     /**
      * Sets the HTTP methods (e.g. 'POST') all child routes are restricted to.
      *
-     * @param string|array $methods The method or an array of methods
+     * @param string|string[] $methods The method or an array of methods
      */
     public function setMethods($methods)
     {
@@ -262,16 +262,19 @@ class RouteCollection implements \IteratorAggregate, \Countable
      */
     public function getResources()
     {
-        return array_unique($this->resources);
+        return array_values($this->resources);
     }
 
     /**
-     * Adds a resource for this collection.
-     *
-     * @param ResourceInterface $resource A resource instance
+     * Adds a resource for this collection. If the resource already exists
+     * it is not added.
      */
     public function addResource(ResourceInterface $resource)
     {
-        $this->resources[] = $resource;
+        $key = (string) $resource;
+
+        if (!isset($this->resources[$key])) {
+            $this->resources[$key] = $resource;
+        }
     }
 }