File tree 3 files changed +42
-2
lines changed
Filter options
src/Symfony/Component/DependencyInjection 3 files changed +42
-2
lines changed
Original file line number Diff line number Diff line change @@ -1898,8 +1898,10 @@ private function getServiceCall($id, Reference $reference = null)
1898
1898
return '$this ' ;
1899
1899
}
1900
1900
1901
- if ($ this ->container ->hasDefinition ($ id ) && ($ definition = $ this ->container ->getDefinition ($ id )) && !$ definition ->isSynthetic ()) {
1902
- if (null !== $ reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $ reference ->getInvalidBehavior ()) {
1901
+ if ($ this ->container ->hasDefinition ($ id ) && $ definition = $ this ->container ->getDefinition ($ id )) {
1902
+ if ($ definition ->isSynthetic ()) {
1903
+ $ code = sprintf ('$this->get( \'%s \', %d) ' , $ id , $ reference ->getInvalidBehavior ());
1904
+ } elseif (null !== $ reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $ reference ->getInvalidBehavior ()) {
1903
1905
$ code = 'null ' ;
1904
1906
if (!$ definition ->isShared ()) {
1905
1907
return $ code ;
Original file line number Diff line number Diff line change @@ -1434,6 +1434,21 @@ public function testArgumentsHaveHigherPriorityThanBindings()
1434
1434
$ this ->assertSame ('via-argument ' , $ container ->get ('foo ' )->class1 ->identifier );
1435
1435
$ this ->assertSame ('via-bindings ' , $ container ->get ('foo ' )->class2 ->identifier );
1436
1436
}
1437
+
1438
+ public function testUninitializedSyntheticReference ()
1439
+ {
1440
+ $ container = new ContainerBuilder ();
1441
+ $ container ->register ('foo ' , 'stdClass ' )->setPublic (true )->setSynthetic (true );
1442
+ $ container ->register ('bar ' , 'stdClass ' )->setPublic (true )->setShared (false )
1443
+ ->setProperty ('foo ' , new Reference ('foo ' , ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE ));
1444
+
1445
+ $ container ->compile ();
1446
+
1447
+ $ this ->assertEquals ((object ) array ('foo ' => null ), $ container ->get ('bar ' ));
1448
+
1449
+ $ container ->set ('foo ' , (object ) array (123 ));
1450
+ $ this ->assertEquals ((object ) array ('foo ' => (object ) array (123 )), $ container ->get ('bar ' ));
1451
+ }
1437
1452
}
1438
1453
1439
1454
class FooClass
Original file line number Diff line number Diff line change @@ -913,6 +913,29 @@ public function testDumpHandlesObjectClassNames()
913
913
$ this ->assertInstanceOf ('stdClass ' , $ container ->get ('bar ' ));
914
914
}
915
915
916
+ public function testUninitializedSyntheticReference ()
917
+ {
918
+ $ container = new ContainerBuilder ();
919
+ $ container ->register ('foo ' , 'stdClass ' )->setPublic (true )->setSynthetic (true );
920
+ $ container ->register ('bar ' , 'stdClass ' )->setPublic (true )->setShared (false )
921
+ ->setProperty ('foo ' , new Reference ('foo ' , ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE ));
922
+
923
+ $ container ->compile ();
924
+
925
+ $ dumper = new PhpDumper ($ container );
926
+ eval ('?> ' .$ dumper ->dump (array (
927
+ 'class ' => 'Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference ' ,
928
+ 'inline_class_loader_parameter ' => 'inline_requires ' ,
929
+ )));
930
+
931
+ $ container = new \Symfony_DI_PhpDumper_Test_UninitializedSyntheticReference ();
932
+
933
+ $ this ->assertEquals ((object ) array ('foo ' => null ), $ container ->get ('bar ' ));
934
+
935
+ $ container ->set ('foo ' , (object ) array (123 ));
936
+ $ this ->assertEquals ((object ) array ('foo ' => (object ) array (123 )), $ container ->get ('bar ' ));
937
+ }
938
+
916
939
/**
917
940
* @group legacy
918
941
* @expectedDeprecation The "private" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
You can’t perform that action at this time.
0 commit comments