Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35994bf

Browse files
bug #11666 [DIC] Fixed: anonymous services are always private (lyrixx)
This PR was squashed before being merged into the 2.5 branch (closes #11666). Discussion ---------- [DIC] Fixed: anonymous services are always private | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | This PR fix a regression introduce by 33c91f9#diff-c68f5120ea7d664e07e96cc40bdf6295L268 * First commit is just about CS * Second commit really fix the regression (see only this diff to easily understand) ping @sandermarechal @romainneutron Commits ------- 7f4f9ab [DIC] Fixed: anonymous services are always private
2 parents 8c22211 + 7f4f9ab commit 35994bf

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,20 @@ private function processAnonymousServices(\DOMDocument $xml, $file)
278278
// resolve definitions
279279
krsort($definitions);
280280
foreach ($definitions as $id => $def) {
281+
list($domElement, $file, $wild) = $def;
282+
281283
// anonymous services are always private
282-
$def[0]->setAttribute('public', false);
284+
// we could not use the constant false here, because of XML parsing
285+
$domElement->setAttribute('public', 'false');
283286

284-
$this->parseDefinition($id, $def[0], $def[1]);
287+
$this->parseDefinition($id, $domElement, $file);
285288

286-
$oNode = $def[0];
287-
if (true === $def[2]) {
288-
$nNode = new \DOMElement('_services', null, self::NS);
289-
$oNode->parentNode->replaceChild($nNode, $oNode);
290-
$nNode->setAttribute('id', $id);
289+
if (true === $wild) {
290+
$tmpDomElement = new \DOMElement('_services', null, self::NS);
291+
$domElement->parentNode->replaceChild($tmpDomElement, $domElement);
292+
$tmpDomElement->setAttribute('id', $id);
291293
} else {
292-
$oNode->parentNode->removeChild($oNode);
294+
$domElement->parentNode->removeChild($domElement);
293295
}
294296
}
295297
}

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public function testLoadAnonymousServices()
184184
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
185185
$inner = $services[(string) $args[0]];
186186
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
187+
$this->assertFalse($inner->isPublic());
187188

188189
// anonymous service as a property
189190
$properties = $services['foo']->getProperties();

0 commit comments

Comments
 (0)