Fixed detection of an active session
This commit is contained in:
parent
c07e9163a6
commit
f72ba0a27d
@ -518,7 +518,7 @@ class Request
|
||||
*/
|
||||
public function hasSession()
|
||||
{
|
||||
return null !== $this->session;
|
||||
return null !== $this->session && $this->session->isStarted();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,6 +130,14 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
|
||||
$this->storage->getBag($this->attributeName)->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->storage->isStarted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for attributes.
|
||||
*
|
||||
|
@ -174,6 +174,15 @@ interface SessionInterface
|
||||
*/
|
||||
function clear();
|
||||
|
||||
/**
|
||||
* Check if a session was started
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isStarted();
|
||||
|
||||
/**
|
||||
* Registers a SessionBagInterface with the session.
|
||||
*
|
||||
|
@ -199,6 +199,16 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return $this->bags[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the session was started or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->started;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MetadataBag.
|
||||
*
|
||||
|
@ -289,6 +289,16 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return $this->metadataBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the session was started or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->started;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets session.* ini variables.
|
||||
*
|
||||
|
@ -884,6 +884,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertFalse($request->hasSession());
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
$request->getSession()->start();
|
||||
$this->assertTrue($request->hasSession());
|
||||
}
|
||||
|
||||
@ -895,6 +896,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->cookies->set('MOCKSESSID', 'foo');
|
||||
$this->assertFalse($request->hasPreviousSession());
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
$request->getSession()->start();
|
||||
$this->assertTrue($request->hasPreviousSession());
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
|
||||
protected function runSessionOnKernelResponse($newToken, $original = null)
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->start();
|
||||
|
||||
if ($original !== null) {
|
||||
$session->set('_security_session', $original);
|
||||
|
Reference in New Issue
Block a user