Skip to content

Commit 4fe862b

Browse files
Merge branch '3.4' into 4.0
* 3.4: [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 29d1321 + b51640d commit 4fe862b

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
@@ -1640,8 +1640,10 @@ private function getServiceCall(string $id, Reference $reference = null): string
16401640
return '$this';
16411641
}
16421642

1643-
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
1644-
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
1643+
if ($this->container->hasDefinition($id) && $definition = $this->container->getDefinition($id)) {
1644+
if ($definition->isSynthetic()) {
1645+
$code = sprintf('$this->get(\'%s\'%s)', $id, null !== $reference ? ', '.$reference->getInvalidBehavior() : '');
1646+
} elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
16451647
$code = 'null';
16461648
if (!$definition->isShared()) {
16471649
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
@@ -911,6 +911,29 @@ public function testDumpHandlesObjectClassNames()
911911
$this->assertInstanceOf('stdClass', $container->get('bar'));
912912
}
913913

914+
public function testUninitializedSyntheticReference()
915+
{
916+
$container = new ContainerBuilder();
917+
$container->register('foo', 'stdClass')->setPublic(true)->setSynthetic(true);
918+
$container->register('bar', 'stdClass')->setPublic(true)->setShared(false)
919+
->setProperty('foo', new Reference('foo', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE));
920+
921+
$container->compile();
922+
923+
$dumper = new PhpDumper($container);
924+
eval('?>'.$dumper->dump(array(
925+
'class' => 'Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference',
926+
'inline_class_loader_parameter' => 'inline_requires',
927+
)));
928+
929+
$container = new \Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference();
930+
931+
$this->assertEquals((object) array('foo' => null), $container->get('bar'));
932+
933+
$container->set('foo', (object) array(123));
934+
$this->assertEquals((object) array('foo' => (object) array(123)), $container->get('bar'));
935+
}
936+
914937
/**
915938
* This test checks the trigger of a deprecation note and should not be removed in major releases.
916939
*

0 commit comments

Comments
 (0)