[DIC] Fixed: anonymous services are always private

This commit is contained in:
Grégoire Pineau 2014-08-14 01:29:31 +02:00 committed by Nicolas Grekas
parent 8c222110c9
commit 7f4f9ab461
2 changed files with 11 additions and 8 deletions

View File

@ -278,18 +278,20 @@ class XmlFileLoader extends FileLoader
// resolve definitions
krsort($definitions);
foreach ($definitions as $id => $def) {
list($domElement, $file, $wild) = $def;
// anonymous services are always private
$def[0]->setAttribute('public', false);
// we could not use the constant false here, because of XML parsing
$domElement->setAttribute('public', 'false');
$this->parseDefinition($id, $def[0], $def[1]);
$this->parseDefinition($id, $domElement, $file);
$oNode = $def[0];
if (true === $def[2]) {
$nNode = new \DOMElement('_services', null, self::NS);
$oNode->parentNode->replaceChild($nNode, $oNode);
$nNode->setAttribute('id', $id);
if (true === $wild) {
$tmpDomElement = new \DOMElement('_services', null, self::NS);
$domElement->parentNode->replaceChild($tmpDomElement, $domElement);
$tmpDomElement->setAttribute('id', $id);
} else {
$oNode->parentNode->removeChild($oNode);
$domElement->parentNode->removeChild($domElement);
}
}
}

View File

@ -184,6 +184,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
$inner = $services[(string) $args[0]];
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
$this->assertFalse($inner->isPublic());
// anonymous service as a property
$properties = $services['foo']->getProperties();