Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d8067f

Browse files
committed
bug #18018 [HttpFoundation] exception when registering bags for started sessions (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] exception when registering bags for started sessions | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10707, #16136 | License | MIT | Doc PR | Commits ------- c4a5b67 exception when registering bags for started sessions
2 parents 1bbcff0 + c4a5b67 commit 5d8067f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ public function clear()
260260
*/
261261
public function registerBag(SessionBagInterface $bag)
262262
{
263+
if ($this->started) {
264+
throw new \LogicException('Cannot register a bag when the session is already started.');
265+
}
266+
263267
$this->bags[$bag->getName()] = $bag;
264268
}
265269

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public function testRegisterBagException()
8383
$storage->getBag('non_existing');
8484
}
8585

86+
/**
87+
* @expectedException \LogicException
88+
*/
89+
public function testRegisterBagForAStartedSessionThrowsException()
90+
{
91+
$storage = $this->getStorage();
92+
$storage->start();
93+
$storage->registerBag(new AttributeBag());
94+
}
95+
8696
public function testGetId()
8797
{
8898
$storage = $this->getStorage();

0 commit comments

Comments
 (0)