8000 [FrameworkBundle][HttpFoundation] make session service resettable · symfony/symfony@6e670cd · GitHub
[go: up one dir, main page]

Skip to content

Provide feedback

8000

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e670cd

Browse files
committed
[FrameworkBundle][HttpFoundation] make session service resettable
1 parent c8d6dec commit 6e670cd

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<argument type="service" id="session.storage" />
1616
<argument type="service" id="session.attribute_bag" />
1717
<argument type="service" id="session.flash_bag" />
18+
<tag name="kernel.reset" method="save" />
1819
</service>
1920

2021
<service id="Symfony\Component\HttpFoundation\Session\SessionInterface" alias="session" />

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/dependency-injection": "^3.4.3|^4.0.3",
2424
"symfony/config": "~3.4|~4.0",
2525
"symfony/event-dispatcher": "~3.4|~4.0",
26-
"symfony/http-foundation": "^3.3.11|~4.0",
26+
"symfony/http-foundation": "^3.4.24|^4.2.5",
2727
"symfony/http-kernel": "~3.4|~4.0",
2828
"symfony/polyfill-mbstring": "~1.0",
2929
"symfony/filesystem": "~2.8|~3.0|~4.0",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ public function migrate($destroy = false, $lifetime = null)
193193
*/
194194
public function save()
195195
{
196-
$this->storage->save();
196+
if ($this->isStarted()) {
197+
$this->storage->save();
198+
}
197199
}
198200

199201
/**

src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
1717
use Symfony\Component\HttpFoundation\Session\Session;
1818
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
19+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
1920

2021
/**
2122
* SessionTest.
@@ -260,4 +261,13 @@ public function testIsEmpty()
260261
$flash->get('hello');
261262
$this->assertTrue($this->session->isEmpty());
262263
}
264+
265+
public function testSaveIfNotStarted()
266+
{
267+
$storage = $this->createMock(SessionStorageInterface::class);
268+
$session = new Session($storage);
269+
270+
$storage->expects($this->never())->method('save');
271+
$session->save();
272+
}
263273
}

0 commit comments

Comments
 (0)
0