function XmlFileLoader::parseConfigs
Parses the config elements (default, requirement, option).
Throws
\InvalidArgumentException When the XML is invalid
2 calls to XmlFileLoader::parseConfigs()
- XmlFileLoader::parseImport in vendor/
symfony/ routing/ Loader/ XmlFileLoader.php - Parses an import and adds the routes in the resource to the RouteCollection.
- XmlFileLoader::parseRoute in vendor/
symfony/ routing/ Loader/ XmlFileLoader.php - Parses a route and adds it to the RouteCollection.
File
-
vendor/
symfony/ routing/ Loader/ XmlFileLoader.php, line 245
Class
- XmlFileLoader
- XmlFileLoader loads XML routing files.
Namespace
Symfony\Component\Routing\LoaderCode
private function parseConfigs(\DOMElement $node, string $path) : array {
$defaults = [];
$requirements = [];
$options = [];
$condition = null;
$prefixes = [];
$paths = [];
$hosts = [];
/** @var \DOMElement $n */
foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) {
if ($node !== $n->parentNode) {
continue;
}
switch ($n->localName) {
case 'path':
$paths[$n->getAttribute('locale')] = trim($n->textContent);
break;
case 'host':
$hosts[$n->getAttribute('locale')] = trim($n->textContent);
break;
case 'prefix':
$prefixes[$n->getAttribute('locale')] = trim($n->textContent);
break;
case 'default':
if ($this->isElementValueNull($n)) {
$defaults[$n->getAttribute('key')] = null;
}
else {
$defaults[$n->getAttribute('key')] = $this->parseDefaultsConfig($n, $path);
}
break;
case 'requirement':
$requirements[$n->getAttribute('key')] = trim($n->textContent);
break;
case 'option':
$options[$n->getAttribute('key')] = XmlUtils::phpize(trim($n->textContent));
break;
case 'condition':
$condition = trim($n->textContent);
break;
case 'resource':
break;
default:
throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "condition".', $n->localName, $path));
}
}
if ($controller = $node->getAttribute('controller')) {
if (isset($defaults['_controller'])) {
$name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName);
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" attribute and the defaults key "_controller" for ', $path) . $name);
}
$defaults['_controller'] = $controller;
}
if ($node->hasAttribute('locale')) {
$defaults['_locale'] = $node->getAttribute('locale');
}
if ($node->hasAttribute('format')) {
$defaults['_format'] = $node->getAttribute('format');
}
if ($node->hasAttribute('utf8')) {
$options['utf8'] = XmlUtils::phpize($node->getAttribute('utf8'));
}
if ($stateless = $node->getAttribute('stateless')) {
if (isset($defaults['_stateless'])) {
$name = $node->hasAttribute('id') ? \sprintf('"%s".', $node->getAttribute('id')) : \sprintf('the "%s" tag.', $node->tagName);
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" attribute and the defaults key "_stateless" for ', $path) . $name);
}
$defaults['_stateless'] = XmlUtils::phpize($stateless);
}
if (!$hosts) {
$hosts = $node->hasAttribute('host') ? $node->getAttribute('host') : null;
}
return [
$defaults,
$requirements,
$options,
$condition,
$paths,
$prefixes,
$hosts,
];
}