Processes anonymous services
SimpleXMLElement $xml:
string $file:
private function processAnonymousServices(SimpleXMLElement $xml, $file) {
$definitions = array();
$count = 0;
// anonymous services as arguments/properties
if (false !== ($nodes = $xml
->xpath('//container:argument[@type="service"][not(@id)]|//container:property[@type="service"][not(@id)]'))) {
foreach ($nodes as $node) {
// give it a unique name
$node['id'] = sprintf('%s_%d', md5($file), ++$count);
$definitions[(string) $node['id']] = array(
$node->service,
$file,
false,
);
$node->service['id'] = (string) $node['id'];
}
}
// anonymous services "in the wild"
if (false !== ($nodes = $xml
->xpath('//container:services/container:service[not(@id)]'))) {
foreach ($nodes as $node) {
// give it a unique name
$node['id'] = sprintf('%s_%d', md5($file), ++$count);
$definitions[(string) $node['id']] = array(
$node,
$file,
true,
);
$node->service['id'] = (string) $node['id'];
}
}
// resolve definitions
krsort($definitions);
foreach ($definitions as $id => $def) {
// anonymous services are always private
$def[0]['public'] = false;
$this
->parseDefinition($id, $def[0], $def[1]);
$oNode = dom_import_simplexml($def[0]);
if (true === $def[2]) {
$nNode = new \DOMElement('_services');
$oNode->parentNode
->replaceChild($nNode, $oNode);
$nNode
->setAttribute('id', $id);
}
else {
$oNode->parentNode
->removeChild($oNode);
}
}
}