Symfony\Component\Routing\RouteCollection::addCollection PHP Method

addCollection() public method

Adds a route collection to the current set of routes (at the end of the current set).
public addCollection ( RouteCollection $collection, string $prefix = '' )
$collection RouteCollection A RouteCollection instance
$prefix string An optional prefix to add before each pattern of the route collection
    public function addCollection(RouteCollection $collection, $prefix = '')
    {
        $collection->addPrefix($prefix);

        foreach ($collection->getResources() as $resource) {
            $this->addResource($resource);
        }

        $this->routes = array_merge($this->routes, $collection->all());
    }

Same methods

RouteCollection::addCollection ( RouteCollection $collection, string $prefix = '', array $defaults = [], array $requirements = [], array $options = [] )

Usage Example

 /**
  * @param mixed $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  * @throws \RuntimeException
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     /*
      * For each core bunle then for each module
      */
     // CoreBundle
     $loader = $this->resolver->resolve('@EtuCoreBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuCoreBundle/Api/Resource/', 'annotation'));
     }
     // UserBundle
     $loader = $this->resolver->resolve('@EtuUserBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuUserBundle/Api/Resource/', 'annotation'));
     }
     /** @var $module Module */
     foreach ($this->kernel->getModulesDefinitions() as $module) {
         $routing = $module->getApiRouting();
         $loader = $this->resolver->resolve($routing['resource'], $routing['type']);
         if ($loader) {
             $routes->addCollection($loader->load($routing['resource'], $routing['type']));
         }
     }
     return $routes;
 }
All Usage Examples Of Symfony\Component\Routing\RouteCollection::addCollection