public function RouteCollection::addCollection

Adds a route collection to the current set of routes (at the end of the current set).

@api

Parameters

RouteCollection $collection A RouteCollection instance:

string $prefix An optional prefix to add before each pattern of the route collection:

array $defaults An array of default values:

array $requirements An array of requirements:

array $options An array of options:

Throws

\InvalidArgumentException When the RouteCollection already exists in the tree

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/RouteCollection.php, line 196

Class

RouteCollection
A RouteCollection represents a set of Route instances as a tree structure.

Namespace

Symfony\Component\Routing

Code

public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array()) {

  // prevent infinite loops by recursive referencing
  $root = $this
    ->getRoot();
  if ($root === $collection || $root
    ->hasCollection($collection)) {
    throw new \InvalidArgumentException('The RouteCollection already exists in the tree.');
  }

  // remove all routes with the same names in all existing collections
  $this
    ->remove(array_keys($collection
    ->all()));
  $collection
    ->setParent($this);

  // the sub-collection must have the prefix of the parent (current instance) prepended because it does not
  // necessarily already have it applied (depending on the order RouteCollections are added to each other)
  $collection
    ->addPrefix($this
    ->getPrefix() . $prefix, $defaults, $requirements, $options);
  $this->routes[] = $collection;
}