8000 [WIP][HttpFoundation][Session] Fixed detection of an active session by dlsniper · Pull Request #4541 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][HttpFoundation][Session] Fixed detection of an active session #4541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function hasPreviousSession()
*/
public function hasSession()
{
return null !== $this->session;
return null !== $this->session && $this->session->isStarted();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The hasSession() must return true when a request is associated with a session, that's all. The fact that the session is started or not is not the same thing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify the meaning for discussions elsewhere: hasSession() means does this have a session object. Its not a reflection of the state of the session object.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot - why did you merge this particular commit if you also disagree with the above diff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I reverted this part in another commit.

}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/HttpFoundation/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public function clear()
$this->storage->getBag($this->attributeName)->clear();
}

/**
* {@inheritdoc}
*/
public function isStarted()
{
return $this->storage->isStarted();
}

/**
* Returns an iterator for attributes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ function remove($name);
*/
function clear();

/**
* Check if a session was started
*
* @api
*
* @return boolean
*/
public function isStarted();

/**
* Registers a SessionBagInterface with the session.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ public function getBag($name)
return $this->bags[$name];
}

/**
* Check if the session was started or not
*
* @return boolean
*/
public function isStarted()
{
return $this->started;
}

/**
* Sets the MetadataBag.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ public function getMetadataBag()
return $this->metadataBag;
}

/**
* Check if the session was started or not
*
* @return boolean
*/
public function isStarted()
{
return $this->started;
}

/**
* Sets session.* ini variables.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ public function testHasSession()

$this->assertFalse($request->hasSession());
$request->setSession(new Session(new MockArraySessionStorage()));
$request->getSession()->start();
$this->assertTrue($request->hasSession());
}

Expand All @@ -895,6 +896,7 @@ public function testHasPreviousSession()
$request->cookies->set('MOCKSESSID', 'foo');
$this->assertFalse($request->hasPreviousSession());
$request->setSession(new Session(new MockArraySessionStorage()));
$request->getSession()->start();
$this->assertTrue($request->hasPreviousSession());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function testOnKernelResponseWillRemoveSession()
protected function runSessionOnKernelResponse($newToken, $original = null)
{
$session = new Session(new MockArraySessionStorage());
$session->start();

if ($original !== null) {
$session->set('_security_session', $original);
Expand Down
0