Parses an import and adds the routes in the resource 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:
string $file Loaded file name:
\InvalidArgumentException When the XML is invalid
protected function parseImport(RouteCollection $collection, \DOMElement $node, $path, $file) {
if ('' === ($resource = $node
->getAttribute('resource'))) {
throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute.', $path));
}
$type = $node
->getAttribute('type');
$prefix = $node
->getAttribute('prefix');
$host = $node
->hasAttribute('host') ? $node
->getAttribute('host') : null;
$schemes = $node
->hasAttribute('schemes') ? preg_split('/[\\s,\\|]++/', $node
->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY) : null;
$methods = $node
->hasAttribute('methods') ? preg_split('/[\\s,\\|]++/', $node
->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY) : null;
list($defaults, $requirements, $options) = $this
->parseConfigs($node, $path);
$this
->setCurrentDir(dirname($path));
$subCollection = $this
->import($resource, '' !== $type ? $type : null, false, $file);
/* @var $subCollection RouteCollection */
$subCollection
->addPrefix($prefix);
if (null !== $host) {
$subCollection
->setHost($host);
}
if (null !== $schemes) {
$subCollection
->setSchemes($schemes);
}
if (null !== $methods) {
$subCollection
->setMethods($methods);
}
$subCollection
->addDefaults($defaults);
$subCollection
->addRequirements($requirements);
$subCollection
->addOptions($options);
$collection
->addCollection($subCollection);
}