8000 Fixed detection of an active session · symfony/symfony@f72ba0a · GitHub
[go: up one dir, main page]

Skip to content

Commit f72ba0a

Browse files
committed
Fixed detection of an active session
1 parent c07e916 commit f72ba0a

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ public function hasPreviousSession()
518518
*/
519519
public function hasSession()
520520
{
521-
return null !== $this->session;
521+
return null !== $this->session && $this->session->isStarted();
522522
}
523523

524524
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public function clear()
130130
$this->storage->getBag($this->attributeName)->clear();
131131
}
132132

133+
/**
134+
* {@inheritdoc}
135+
*/
136+
public function isStarted()
137+
{
138+
return $this->storage->isStarted();
139+
}
140+
133141
/**
134142
* Returns an iterator for attributes.
135143
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ function remove($name);
174174
*/
175175
function clear();
176176

177+
/**
178+
* Check if a session was started
179+
*
180+
* @api
181+
*
182+
* @return boolean
183+
*/
184+
public function isStarted();
185+
177186
/**
178187
* Registers a SessionBagInterface with the session.
179188
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ public function getBag($name)
199199
return $this->bags[$name];
200200
}
201201

202+
/**
203+
* Check if the session was started or not
204+
*
205+
* @return boolean
206+
*/
207+
public function isStarted()
208+
{
209+
return $this->started;
210+
}
211+
202212
/**
203213
* Sets the MetadataBag.
204214
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ public function getMetadataBag()
289289
return $this->metadataBag;
290290
}
291291

292+
/**
293+
* Check if the session was started or not
294+
*
295+
* @return boolean
296+
*/
297+
public function isStarted()
298+
{
299+
return $this->started;
300+
}
301+
292302
/**
293303
* Sets session.* ini variables.
294304
*

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ public function testHasSession()
884884

885885
$this->assertFalse($request->hasSession());
886886
$request->setSession(new Session(new MockArraySessionStorage()));
887+
$request->getSession()->start();
887888
$this->assertTrue($request->hasSession());
888889
}
889890

@@ -895,6 +896,7 @@ public function testHasPreviousSession()
895896
$request->cookies->set('MOCKSESSID', 'foo');
896897
$this->assertFalse($request->hasPreviousSession());
897898
$request->setSession(new Session(new MockArraySessionStorage()));
899+
$request->getSession()->start();
898900
$this->assertTrue($request->hasPreviousSession());
899901
}
900902

src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function testOnKernelResponseWillRemoveSession()
8585
protected function runSessionOnKernelResponse($newToken, $original = null)
8686
{
8787
$session = new Session(new MockArraySessionStorage());
88+
$session->start();
8889

8990
if ($original !== null) {
9091
$session->set('_security_session', $original);

0 commit comments

Comments
 (0)
0