Skip to content

Commit da46174

Browse files
committed
Merge branch '2.5'
* 2.5: added missing files [TwigBundle] added a test Indicate which file was being parsed if an exception is thrown while running translation:debug [ClassLoader] Cast $useIncludePath property to boolean [HttpFoundation] Minor spelling fix in PHPDocs improve error message for multiple documents Remove aligned '=>' and '=' [Session] remove invalid workaround in session regenerate [Kernel] ensure session is saved before sending response [Routing] serialize the compiled route to speed things up [Form] Fixed usage of "name" variable in form_start block [Validator] Fixed Regex::getHtmlPattern() to work with complex and negated patterns [DependencyInjection] use inheritdoc for loaders [Config] fix filelocator with empty name [Form] fix form handling with unconventional request methods like OPTIONS CSRF warning docs on Request::enableHttpMethodParameterOverride() Conflicts: src/Symfony/Component/Console/Helper/ProgressBar.php
2 parents dab2e0a + c483f74 commit da46174

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

Config/FileLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(KernelInterface $kernel, $path = null, array $paths
4747
*/
4848
public function locate($file, $currentPath = null, $first = true)
4949
{
50-
if ('@' === $file[0]) {
50+
if (isset($file[0]) && '@' === $file[0]) {
5151
return $this->kernel->locateResource($file, $this->path, $first);
5252
}
5353

DataCollector/TimeDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function collect(Request $request, Response $response, \Exception $except
4343
}
4444

4545
$this->data = array(
46-
'token' => $response->headers->get('X-Debug-Token'),
46+
'token' => $response->headers->get('X-Debug-Token'),
4747
'start_time' => $startTime * 1000,
4848
'events' => array(),
4949
);

EventListener/SaveSessionListener.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\EventListener;
13+
14+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15+
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
16+
use Symfony\Component\HttpKernel\HttpKernelInterface;
17+
use Symfony\Component\HttpKernel\KernelEvents;
18+
19+
/**
20+
* Saves the session, in case it is still open, before sending the response/headers.
21+
*
22+
* This ensures several things in case the developer did not save the session explicitly:
23+
*
24+
* * If a session save handler without locking is used, it ensures the data is available
25+
* on the next request, e.g. after a redirect. PHPs auto-save at script end via
26+
* session_register_shutdown is executed after fastcgi_finish_request. So in this case
27+
* the data could be missing the next request because it might not be saved the moment
28+
* the new request is processed.
29+
* * A locking save handler (e.g. the native 'files') circumvents concurrency problems like
30+
* the one above. But by saving the session before long-running things in the terminate event,
31+
* we ensure the session is not blocked longer than needed.
32+
* * When regenerating the session ID no locking is involved in PHPs session design. See
33+
* https://bugs.php.net/bug.php?id=61470 for a discussion. So in this case, the session must
34+
* be saved anyway before sending the headers with the new session ID. Otherwise session
35+
* data could get lost again for concurrent requests with the new ID. One result could be
36+
* that you get logged out after just logging in.
37+
*
38+
* This listener should be executed as one of the last listeners, so that previous listeners
39+
* can still operate on the open session. This prevents the overhead of restarting it.
40+
* Listeners after closing the session can still work with the session as usual because
41+
* Symfonys session implementation starts the session on demand. So writing to it after
42+
* it is saved will just restart it.
43+
*
44+
* @author Tobias Schultze <http://tobion.de>
45+
*/
46+
class SaveSessionListener implements EventSubscriberInterface
47+
{
48+
public function onKernelResponse(FilterResponseEvent $event)
49+
{
50+
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
51+
return;
52+
}
53+
54+
$session = $event->getRequest()->getSession();
55+
if ($session && $session->isStarted()) {
56+
$session->save();
57+
}
58+
}
59+
60+
public static function getSubscribedEvents()
61+
{
62+
return array(
63+
// low priority but higher than StreamedResponseListener
64+
KernelEvents::RESPONSE => array(array('onKernelResponse', -1000)),
65+
);
66+
}
67+
}

Tests/EventListener/ProfilerListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testKernelTerminate()
8787
->getMock();
8888

8989
$onlyException = true;
90-
$listener = new ProfilerListener($profiler, null, $onlyException);
90+
$listener = new ProfilerListener($profiler, null, $onlyException);
9191

9292
// master request
9393
$listener->onKernelRequest(new GetResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST));

0 commit comments

Comments
 (0)