*/
public function count()
{
- return count($this->routes);
+ return \count($this->routes);
}
/**
/**
* 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)
{
/**
* 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
$this->routes[$name] = $route;
}
- $this->resources = array_merge($this->resources, $collection->getResources());
+ foreach ($collection->getResources() as $resource) {
+ $this->addResource($resource);
+ }
}
/**
/**
* 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)
{
/**
* 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)
{
*/
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;
+ }
}
}