Parses a route and adds it to the RouteCollection.
RouteCollection $collection A RouteCollection instance:
\DOMElement $definition Route definition:
string $file An XML file path:
\InvalidArgumentException When the definition cannot be parsed
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);
}