Adds a route collection to the current set of routes (at the end of the current set).
@api
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:
\InvalidArgumentException When the RouteCollection already exists in the tree
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;
}