Parses a route and adds it to the RouteCollection.
RouteCollection $collection RouteCollection instance:
\DOMElement $node Element to parse that represents a Route:
string $path Full path of the XML file being processed:
\InvalidArgumentException When the XML is invalid
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);
}