File tree Expand file tree Collapse file tree 3 files changed +7
-16
lines changed Expand file tree Collapse file tree 3 files changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -362,21 +362,14 @@ public function getScopeChildren()
362362 public function set ($ id , $ service , $ scope = self ::SCOPE_CONTAINER )
363363 {
364364 $ id = strtolower ($ id );
365+ $ set = isset ($ this ->definitions [$ id ]);
365366
366- if ($ this ->isFrozen ()) {
367+ if ($ this ->isFrozen () && ( $ set || isset ( $ this -> obsoleteDefinitions [ $ id ])) && ! $ this ->{ $ set ? ' definitions ' : ' obsoleteDefinitions ' }[ $ id ]-> isSynthetic () ) {
367368 // setting a synthetic service on a frozen container is alright
368- if (
369- (!isset ($ this ->definitions [$ id ]) && !isset ($ this ->obsoleteDefinitions [$ id ]))
370- ||
371- (isset ($ this ->definitions [$ id ]) && !$ this ->definitions [$ id ]->isSynthetic ())
372- ||
373- (isset ($ this ->obsoleteDefinitions [$ id ]) && !$ this ->obsoleteDefinitions [$ id ]->isSynthetic ())
374- ) {
375- throw new BadMethodCallException (sprintf ('Setting service "%s" on a frozen container is not allowed. ' , $ id ));
376- }
369+ throw new BadMethodCallException (sprintf ('Setting service "%s" on a frozen container is not allowed. ' , $ id ));
377370 }
378371
379- if (isset ( $ this -> definitions [ $ id ]) ) {
372+ if ($ set ) {
380373 $ this ->obsoleteDefinitions [$ id ] = $ this ->definitions [$ id ];
381374 }
382375
Original file line number Diff line number Diff line change @@ -637,14 +637,12 @@ public function testThrowsExceptionWhenSetServiceOnAFrozenContainer()
637637 $ container ->set ('a ' , new \stdClass ());
638638 }
639639
640- /**
641- * @expectedException \BadMethodCallException
642- */
643640 public function testThrowsExceptionWhenAddServiceOnAFrozenContainer ()
644641 {
645642 $ container = new ContainerBuilder ();
646643 $ container ->compile ();
647- $ container ->set ('a ' , new \stdClass ());
644+ $ container ->set ('a ' , $ foo = new \stdClass ());
645+ $ this ->assertSame ($ foo , $ container ->get ('a ' ));
648646 }
649647
650648 public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer ()
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ public function testGetReturnsNullOnInactiveScope()
258258
259259 /**
260260 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
261- * @expectedExcepionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
261+ * @expectedExceptionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
262262 */
263263 public function testGetSyntheticServiceAlwaysThrows ()
264264 {
You can’t perform that action at this time.
0 commit comments