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

remove() public method

Removes a route or an array of routes by name from all connected collections (this instance and all parents and children).
public remove ( string | array $name )
$name string | array The route name or an array of route names
    public function remove($name)
    {
        $root = $this->getRoot();

        foreach ((array) $name as $n) {
            $root->removeRecursively($n);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($collection as $name => $route) {
         if ($route->hasRequirement('_module_dependencies')) {
             $modules = $route->getRequirement('_module_dependencies');
             $explode_and = $this->explodeString($modules, '+');
             if (count($explode_and) > 1) {
                 foreach ($explode_and as $module) {
                     // If any moduleExists() call returns FALSE, remove the route and
                     // move on to the next.
                     if (!$this->moduleHandler->moduleExists($module)) {
                         $collection->remove($name);
                         continue 2;
                     }
                 }
             } else {
                 // OR condition, exploding on ',' character.
                 foreach ($this->explodeString($modules, ',') as $module) {
                     if ($this->moduleHandler->moduleExists($module)) {
                         continue 2;
                     }
                 }
                 // If no modules are found, and we get this far, remove the route.
                 $collection->remove($name);
             }
         }
     }
 }
All Usage Examples Of Symfony\Component\Routing\RouteCollection::remove