Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2b5208

Browse files
committed
merged branch dlsniper/session-start-fix (PR #4541)
Commits ------- f72ba0a Fixed detection of an active session Discussion ---------- [WIP][HttpFoundation][Session] Fixed detection of an active session Bug fix: yes Feature addition: no Backwards compatibility break: not sure Symfony2 tests pass: no Fixes the following tickets: #4529 Todo: Fix failing tests License of the code: MIT Documentation PR: ~ This fixes the problem when the session variable inside $request now has always data in it as it's now more powerful but this introduces the problem that the old way of detecting if a session is started or not doesn't work anymore. --------------------------------------------------------------------------- by travisbot at 2012-06-09T21:53:17Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1578839) (merged 9ae13e12 into 6266b72). --------------------------------------------------------------------------- by drak at 2012-06-10T01:57:59Z Sessions should be started implicitly. The SF auto_start config parameter controls the session listener to start the session. --------------------------------------------------------------------------- by dlsniper at 2012-06-11T06:46:02Z So this patch is correct then and I should continue the work on it? --------------------------------------------------------------------------- by drak at 2012-06-11T07:51:39Z @dlsniper - no it's not correct. The session should not be auto-started like this, @fabpot and I recently discussed it. --------------------------------------------------------------------------- by dlsniper at 2012-06-11T07:52:55Z @Drak, ok I'll remove the patch for auto_start then but the fix for start would still stand, right? --------------------------------------------------------------------------- by drak at 2012-06-12T18:40:35Z @dlsniper - I have no objection to the rest of the PR except for the autostart stuff. I've annotated for clarity :) --------------------------------------------------------------------------- by travisbot at 2012-06-12T19:51:12Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1604158) (merged 3499980e into 37550d2). --------------------------------------------------------------------------- by travisbot at 2012-06-12T19:52:00Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1604166) (merged dcc73071 into 37550d2). --------------------------------------------------------------------------- by dlsniper at 2012-06-12T19:56:51Z Seems Travis doesn't like the squashing of commits that I've did but the PR does pass the normal tests. @Drak is this good for merging now? Thanks :) --------------------------------------------------------------------------- by dlsniper at 2012-06-13T09:05:09Z @fabpot this can be merged safely, I've just applied the patch on my production application and the patch is ok, it's just travis failing. Thanks --------------------------------------------------------------------------- by travisbot at 2012-06-13T09:23:46Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1608735) (merged 1a6eabd2 into 37550d2). --------------------------------------------------------------------------- by travisbot at 2012-06-13T09:28:26Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1608758) (merged 4e3a93c8 into 37550d2). --------------------------------------------------------------------------- by dlsniper at 2012-06-13T09:29:28Z I've noticed that this is failing, I'll fix it later on today. --------------------------------------------------------------------------- by travisbot at 2012-06-13T15:14:01Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1611541) (merged 5504c4b7 into 37550d2). --------------------------------------------------------------------------- by drak at 2012-06-13T15:23:47Z It's possible that other tests are failing not related to this PR. Run the tests on the current master, and try rebasing your branch to the current master also. --------------------------------------------------------------------------- by dlsniper at 2012-06-13T15:44:22Z I've just reminded why this is failing on builds, I can't do them locally because of this: ``` Installing dev dependencies Your requirements could not be solved to an installable set of packages. Problems: - Problem caused by: - Installation request for doctrine/orm [>= 2.2.0.0, < 2.4.0.0-dev]: Satisfiable by [doctrine/orm-2.2.2, doctrine/orm-2.2.1, doctrine/orm-2.2.0, doctrine/orm-2.2.x-dev, doctrine/orm-2.3.x-dev]. ``` I'll try and install this somehow and see what's wrong with it. --------------------------------------------------------------------------- by mvrhov at 2012-06-13T18:08:58Z @dlsniper: as @stof said to me this should be resolved in latest versions of composer, but it seems that is not. The problem is that composer cannot figure out that you are on dev-master if you try to instal dev. dependencies on feature branch. Take a look at the .travis.yml file on how to do a proper dev vendors install. cc @Seldaek --------------------------------------------------------------------------- by dlsniper at 2012-06-13T23:08:53Z @mvrhov Thanks for pointing this out. @Drak I still got two tests not passing but I'm not sure how to fix them as adding $session->start() will either fail with the message that the session has already been started, the headers_sent() call which returns true. Any help with them will be greatly appreciated. Thanks! Here is what the HttpKernel tests are returning: ``` There were 2 failures: 1) Symfony\Component\HttpKernel\Tests\EventListener\LocaleListenerTest::testDefaultLocaleWithSession Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'es' +'fr' /var/www/symfony-orig/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php:51 2) Symfony\Component\HttpKernel\Tests\EventListener\LocaleListenerTest::testLocaleFromRequestAttribute Expectation failed for method name is equal to <string:set> when invoked 1 time(s). Method was expected to be called 1 times, actually called 0 times. FAILURES! Tests: 263, Assertions: 1025, Failures: 2, Skipped: 10. ``` --------------------------------------------------------------------------- by travisbot at 2012-06-13T23:42:59Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1614883) (merged 1004b7c0 into c07e916). --------------------------------------------------------------------------- by travisbot at 2012-06-13T23:53:06Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1614897) (merged f72ba0a into c07e916). --------------------------------------------------------------------------- by dlsniper at 2012-06-16T20:14:41Z @stof / @vicb Hi, do either of you think that you can either point me out to the right direction for fixing this either ping someone else for home help as @Drak doesn't seem available for this and at the moment I'm pretty much clueless in what direction I should take this fix. Thanks! --------------------------------------------------------------------------- by dlsniper at 2012-06-19T14:16:29Z ping @fabpot Can you please provide some input on this one as I'm a bit stuck and seems noone else is available. --------------------------------------------------------------------------- by drak at 2012-06-20T10:24:43Z fyi - I'll be able to look again in a few days --------------------------------------------------------------------------- by fabpot at 2012-07-01T07:53:28Z I'm +1 to add the `isStarted()` method, but -1 for the change of `Request::hasSession`. --------------------------------------------------------------------------- by drak at 2012-07-01T09:06:15Z @fabpot, I agree. `hasSession()` should not be changed, it's semantically incorrect to make it return effectively "hasActiveSession".
2 parents 7ac10fe + f72ba0a commit d2b5208

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
@@ -526,7 +526,7 @@ public function hasPreviousSession()
526526
*/
527527
public function hasSession()
528528
{
529-
return null !== $this->session;
529+
return null !== $this->session && $this->session->isStarted();
530530
}
531531

532532
/**

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
@@ -176,6 +176,15 @@ function remove($name);
176176
*/
177177
function clear();
178178

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

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

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

207+
/**
208+
* Check if the session was started or not
209+
*
210+
* @return boolean
211+
*/
212+
public function isStarted()
213+
{
214+
return $this->started;
215+
}
216+
207217
/**
208218
* Sets the MetadataBag.
209219
*

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
@@ -949,6 +949,7 @@ public function testHasSession()
949949

950950
$this->assertFalse($request->hasSession());
951951
$request->setSession(new Session(new MockArraySessionStorage()));
952+
$request->getSession()->start();
952953
$this->assertTrue($request->hasSession());
953954
}
954955

@@ -960,6 +961,7 @@ public function testHasPreviousSession()
960961
$request->cookies->set('MOCKSESSID', 'foo');
961962
$this->assertFalse($request->hasPreviousSession());
962963
$request->setSession(new Session(new MockArraySessionStorage()));
964+
$request->getSession()->start();
963965
$this->assertTrue($request->hasPreviousSession());
964966
}
965967

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)