Skip to content

Commit 6b1b5c2

Browse files
Merge branch '4.0' into 4.1
* 4.0: [Console] fix CS [OptionResolver] resolve arrays [TwigBridge] Fix missing path and separators in loader paths list on debug:twig output [PropertyInfo] Fix dock block lookup fallback loop [HttpFoundation] don't encode cookie name for BC improve deprecation messages minor #27858 [Console] changed warning verbosity; fixes typo (adrian-enspired) AppBundle->App. [DI] Fix dumping ignore-on-uninitialized references to synthetic services
2 parents 047fb12 + 4fe862b commit 6b1b5c2

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Dumper/PhpDumper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,8 +1662,10 @@ private function getServiceCall(string $id, Reference $reference = null): string
16621662
return '$this';
16631663
}
16641664

1665-
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
1666-
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
1665+
if ($this->container->hasDefinition($id) && $definition = $this->container->getDefinition($id)) {
1666+
if ($definition->isSynthetic()) {
1667+
$code = sprintf('$this->get(\'%s\'%s)', $id, null !== $reference ? ', '.$reference->getInvalidBehavior() : '');
1668+
} elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
16671669
$code = 'null';
16681670
if (!$definition->isShared()) {
16691671
return $code;

Tests/ContainerBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,21 @@ public function testArgumentsHaveHigherPriorityThanBindings()
13991399
$this->assertSame('via-bindings', $container->get('foo')->class2->identifier);
14001400
}
14011401

1402+
public function testUninitializedSyntheticReference()
1403+
{
1404+
$container = new ContainerBuilder();
1405+
$container->register('foo', 'stdClass')->setPublic(true)->setSynthetic(true);
1406+
$container->register('bar', 'stdClass')->setPublic(true)->setShared(false)
1407+
->setProperty('foo', new Reference('foo', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE));
1408+
1409+
$container->compile();
1410+
1411+
$this->assertEquals((object) array('foo' => null), $container->get('bar'));
1412+
1413+
$container->set('foo', (object) array(123));
1414+
$this->assertEquals((object) array('foo' => (object) array(123)), $container->get('bar'));
1415+
}
1416+
14021417
public function testIdCanBeAnObjectAsLongAsItCanBeCastToString()
14031418
{
14041419
$id = new Reference('another_service');

Tests/Dumper/PhpDumperTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,29 @@ public function testDumpHandlesObjectClassNames()
953953
$this->assertInstanceOf('stdClass', $container->get('bar'));
954954
}
955955

956+
public function testUninitializedSyntheticReference()
957+
{
958+
$container = new ContainerBuilder();
959+
$container->register('foo', 'stdClass')->setPublic(true)->setSynthetic(true);
960+
$container->register('bar', 'stdClass')->setPublic(true)->setShared(false)
961+
->setProperty('foo', new Reference('foo', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE));
962+
963+
$container->compile();
964+
965+
$dumper = new PhpDumper($container);
966+
eval('?>'.$dumper->dump(array(
967+
'class' => 'Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference',
968+
'inline_class_loader_parameter' => 'inline_requires',
969+
)));
970+
971+
$container = new \Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference();
972+
973+
$this->assertEquals((object) array('foo' => null), $container->get('bar'));
974+
975+
$container->set('foo', (object) array(123));
976+
$this->assertEquals((object) array('foo' => (object) array(123)), $container->get('bar'));
977+
}
978+
956979
/**
957980
* This test checks the trigger of a deprecation note and should not be removed in major releases.
958981
*

0 commit comments

Comments
 (0)