Skip to content

Commit c4a5b67

Browse files
committed
exception when registering bags for started sessions
1 parent ce60be5 commit c4a5b67

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)