Parses a node from a loaded XML file.
RouteCollection $collection the collection to associate with the node:
DOMElement $node the node to parse:
string $path the path of the XML file being processed:
string $file:
protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file) {
switch ($node->tagName) {
case 'route':
$this
->parseRoute($collection, $node, $path);
break;
case 'import':
$resource = (string) $node
->getAttribute('resource');
$type = (string) $node
->getAttribute('type');
$prefix = (string) $node
->getAttribute('prefix');
$defaults = array();
$requirements = array();
$options = array();
foreach ($node->childNodes as $n) {
if (!$n instanceof \DOMElement) {
continue;
}
switch ($n->tagName) {
case 'default':
$defaults[(string) $n
->getAttribute('key')] = trim((string) $n->nodeValue);
break;
case 'requirement':
$requirements[(string) $n
->getAttribute('key')] = trim((string) $n->nodeValue);
break;
case 'option':
$options[(string) $n
->getAttribute('key')] = trim((string) $n->nodeValue);
break;
default:
throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $n->tagName));
}
}
$this
->setCurrentDir(dirname($path));
$collection
->addCollection($this
->import($resource, '' !== $type ? $type : null, false, $file), $prefix, $defaults, $requirements, $options);
break;
default:
throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
}
}