function XmlFileLoader::parseDefinitions
1 call to XmlFileLoader::parseDefinitions()
- XmlFileLoader::loadXml in vendor/
symfony/ dependency-injection/ Loader/ XmlFileLoader.php
File
-
vendor/
symfony/ dependency-injection/ Loader/ XmlFileLoader.php, line 132
Class
- XmlFileLoader
- XmlFileLoader loads XML files service definitions.
Namespace
Symfony\Component\DependencyInjection\LoaderCode
private function parseDefinitions(\DOMDocument $xml, string $file, Definition $defaults, ?\DOMNode $root = null) : void {
$xpath = new \DOMXPath($xml);
$xpath->registerNamespace('container', self::NS);
if (false === ($services = $xpath->query('./container:services/container:service|./container:services/container:prototype|./container:services/container:stack', $root))) {
return;
}
$this->setCurrentDir(\dirname($file));
$this->instanceof = [];
$this->isLoadingInstanceof = true;
$instanceof = $xpath->query('./container:services/container:instanceof', $root);
foreach ($instanceof as $service) {
$this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, new Definition()));
}
$this->isLoadingInstanceof = false;
foreach ($services as $service) {
if ('stack' === $service->tagName) {
$service->setAttribute('parent', '-');
$definition = $this->parseDefinition($service, $file, $defaults)
->setTags(array_merge_recursive([
'container.stack' => [
[],
],
], $defaults->getTags()));
$this->setDefinition($id = (string) $service->getAttribute('id'), $definition);
$stack = [];
foreach ($this->getChildren($service, 'service') as $k => $frame) {
$k = $frame->getAttribute('id') ?: $k;
$frame->setAttribute('id', $id . '" at index "' . $k);
if ($alias = $frame->getAttribute('alias')) {
$this->validateAlias($frame, $file);
$stack[$k] = new Reference($alias);
}
else {
$stack[$k] = $this->parseDefinition($frame, $file, $defaults)
->setInstanceofConditionals($this->instanceof);
}
}
$definition->setArguments($stack);
}
elseif (null !== ($definition = $this->parseDefinition($service, $file, $defaults))) {
if ('prototype' === $service->tagName) {
$excludes = array_column($this->getChildren($service, 'exclude'), 'nodeValue');
if ($service->hasAttribute('exclude')) {
if (\count($excludes) > 0) {
throw new InvalidArgumentException('You cannot use both the attribute "exclude" and <exclude> tags at the same time.');
}
$excludes = [
$service->getAttribute('exclude'),
];
}
$this->registerClasses($definition, (string) $service->getAttribute('namespace'), (string) $service->getAttribute('resource'), $excludes, $file);
}
else {
$this->setDefinition((string) $service->getAttribute('id'), $definition);
}
}
}
}