Skip to content

Commit

Permalink
[FrameworkBundle][HttpFoundation] make session service resettable
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Mar 21, 2019
1 parent c8d6dec commit 44f8253
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Expand Up @@ -15,6 +15,7 @@
<argument type="service" id="session.storage" />
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
<tag name="kernel.reset" method="save" />
</service>

<service id="Symfony\Component\HttpFoundation\Session\SessionInterface" alias="session" />
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Expand Up @@ -23,7 +23,7 @@
"symfony/dependency-injection": "^3.4.3|^4.0.3",
"symfony/config": "~3.4|~4.0",
"symfony/event-dispatcher": "~3.4|~4.0",
"symfony/http-foundation": "^3.3.11|~4.0",
"symfony/http-foundation": "^3.4.24|^4.2.5",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "~2.8|~3.0|~4.0",
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpFoundation/Session/Session.php
Expand Up @@ -193,7 +193,9 @@ public function migrate($destroy = false, $lifetime = null)
*/
public function save()
{
$this->storage->save();
if ($this->isStarted()) {
$this->storage->save();
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
Expand Up @@ -260,4 +260,14 @@ public function testIsEmpty()
$flash->get('hello');
$this->assertTrue($this->session->isEmpty());
}

public function testSaveIfNotStarted()
{
$storage = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface')->getMock();
$session = new Session($storage);

$storage->expects($this->once())->method('isStarted')->willReturn(false);
$storage->expects($this->never())->method('save');
$session->save();
}
}

0 comments on commit 44f8253

Please sign in to comment.