private function XmlFileLoader::processAnonymousServices in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php \Symfony\Component\DependencyInjection\Loader\XmlFileLoader::processAnonymousServices()
Processes anonymous services.
Parameters
\DOMDocument $xml:
string $file:
1 call to XmlFileLoader::processAnonymousServices()
- XmlFileLoader::load in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Loader/ XmlFileLoader.php
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Loader/ XmlFileLoader.php, line 273
Class
- XmlFileLoader
- XmlFileLoader loads XML files service definitions.
Namespace
Symfony\Component\DependencyInjection\LoaderCode
private function processAnonymousServices(\DOMDocument $xml, $file) {
$definitions = array();
$count = 0;
$xpath = new \DOMXPath($xml);
$xpath
->registerNamespace('container', self::NS);
// anonymous services as arguments/properties
if (false !== ($nodes = $xpath
->query('//container:argument[@type="service"][not(@id)]|//container:property[@type="service"][not(@id)]'))) {
foreach ($nodes as $node) {
// give it a unique name
$id = sprintf('%s_%d', hash('sha256', $file), ++$count);
$node
->setAttribute('id', $id);
if ($services = $this
->getChildren($node, 'service')) {
$definitions[$id] = array(
$services[0],
$file,
false,
);
$services[0]
->setAttribute('id', $id);
}
}
}
// anonymous services "in the wild"
if (false !== ($nodes = $xpath
->query('//container:services/container:service[not(@id)]'))) {
foreach ($nodes as $node) {
// give it a unique name
$id = sprintf('%s_%d', hash('sha256', $file), ++$count);
$node
->setAttribute('id', $id);
if ($services = $this
->getChildren($node, 'service')) {
$definitions[$id] = array(
$node,
$file,
true,
);
$services[0]
->setAttribute('id', $id);
}
}
}
// resolve definitions
krsort($definitions);
foreach ($definitions as $id => $def) {
list($domElement, $file, $wild) = $def;
// anonymous services are always private
// we could not use the constant false here, because of XML parsing
$domElement
->setAttribute('public', 'false');
if (null !== ($definition = $this
->parseDefinition($domElement, $file))) {
$this->container
->setDefinition($id, $definition);
}
if (true === $wild) {
$tmpDomElement = new \DOMElement('_services', null, self::NS);
$domElement->parentNode
->replaceChild($tmpDomElement, $domElement);
$tmpDomElement
->setAttribute('id', $id);
}
else {
$domElement->parentNode
->removeChild($domElement);
}
}
}