protected function XmlFileLoader::parseRoute

Parses a route and adds it to the RouteCollection.

Parameters

RouteCollection $collection A RouteCollection instance:

\DOMElement $definition Route definition:

string $file An XML file path:

Throws

\InvalidArgumentException When the definition cannot be parsed

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 131

Class

XmlFileLoader
XmlFileLoader loads XML routing files.

Namespace

Symfony\Component\Routing\Loader

Code

protected function parseRoute(RouteCollection $collection, \DOMElement $definition, $file) {
  $defaults = array();
  $requirements = array();
  $options = array();
  foreach ($definition->childNodes as $node) {
    if (!$node instanceof \DOMElement) {
      continue;
    }
    switch ($node->tagName) {
      case 'default':
        $defaults[(string) $node
          ->getAttribute('key')] = trim((string) $node->nodeValue);
        break;
      case 'option':
        $options[(string) $node
          ->getAttribute('key')] = trim((string) $node->nodeValue);
        break;
      case 'requirement':
        $requirements[(string) $node
          ->getAttribute('key')] = trim((string) $node->nodeValue);
        break;
      default:
        throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
    }
  }
  $route = new Route((string) $definition
    ->getAttribute('pattern'), $defaults, $requirements, $options);
  $collection
    ->add((string) $definition
    ->getAttribute('id'), $route);
}