protected function XmlFileLoader::parseRoute

Parses a route and adds it to the RouteCollection.

Parameters

RouteCollection $collection RouteCollection instance:

\DOMElement $node Element to parse that represents a Route:

string $path Full path of the XML file being processed:

Throws

\InvalidArgumentException When the XML is invalid

1 call to XmlFileLoader::parseRoute()
XmlFileLoader::parseNode in drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php
Parses a node from a loaded XML file.

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php, line 114

Class

XmlFileLoader
XmlFileLoader loads XML routing files.

Namespace

Symfony\Component\Routing\Loader

Code

protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path) {
  if ('' === ($id = $node
    ->getAttribute('id')) || !$node
    ->hasAttribute('pattern') && !$node
    ->hasAttribute('path')) {
    throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
  }
  if ($node
    ->hasAttribute('pattern')) {
    if ($node
      ->hasAttribute('path')) {
      throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
    }
    $node
      ->setAttribute('path', $node
      ->getAttribute('pattern'));
    $node
      ->removeAttribute('pattern');
  }
  $schemes = preg_split('/[\\s,\\|]++/', $node
    ->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
  $methods = preg_split('/[\\s,\\|]++/', $node
    ->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
  list($defaults, $requirements, $options) = $this
    ->parseConfigs($node, $path);
  $route = new Route($node
    ->getAttribute('path'), $defaults, $requirements, $options, $node
    ->getAttribute('host'), $schemes, $methods);
  $collection
    ->add($id, $route);
}