public function RouteCollection::add

Adds a route.

@api

Parameters

string $name The route name:

Route $route A Route instance:

Throws

\InvalidArgumentException When route name contains non valid characters

File

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

Class

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

Namespace

Symfony\Component\Routing

Code

public function add($name, Route $route) {
  if (!preg_match('/^[a-z0-9A-Z_.]+$/', $name)) {
    throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (a-z and A-Z), underscores (_) and dots (.).', $name));
  }
  $this
    ->remove($name);
  $this->routes[$name] = $route;
}