File tree 2 files changed +6
-15
lines changed
src/Symfony/Component/Dependen
8000
cyInjection
2 files changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -362,21 +362,14 @@ public function getScopeChildren()
362
362
public function set ($ id , $ service , $ scope = self ::SCOPE_CONTAINER )
363
363
{
364
364
$ id = strtolower ($ id );
365
+ $ set = isset ($ this ->definitions [$ id ]);
365
366
366
- if ($ this ->isFrozen ()) {
367
+ if ($ this ->isFrozen () && ( $ set || isset ( $ this -> obsoleteDefinitions [ $ id ])) && ! $ this ->{ $ set ? ' definitions ' : ' obsoleteDefinitions ' }[ $ id ]-> isSynthetic () ) {
367
368
// 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 ));
377
370
}
378
371
379
- if (isset ( $ this -> definitions [ $ id ]) ) {
372
+ if ($ set ) {
380
373
$ this ->obsoleteDefinitions [$ id ] = $ this ->definitions [$ id ];
381
374
}
382
375
Original file line number Diff line number Diff line change @@ -637,14 +637,12 @@ public function testThrowsExceptionWhenSetServiceOnAFrozenContainer()
637
637
$ container ->set ('a ' , new \stdClass ());
638
638
}
639
639
640
- /**
641
- * @expectedException \BadMethodCallException
642
- */
643
640
public function testThrowsExceptionWhenAddServiceOnAFrozenContainer ()
644
641
{
645
642
$ container = new ContainerBuilder ();
646
643
$ container ->compile ();
647
- $ container ->set ('a ' , new \stdClass ());
644
+ $ container ->set ('a ' , $ foo = new \stdClass ());
645
+ $ this ->assertSame ($ foo , $ container ->get ('a ' ));
648
646
}
649
647
650
648
public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer ()
You can’t perform that action at this time.
0 commit comments