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

Skip to content

Commit d85ba56

Browse files
committed
CS
1 parent 93286a6 commit d85ba56

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@
2222
/**
2323
* Sets the session onto the request on the "kernel.request" event and saves
2424
* it on the "kernel.response" event.
25+
*
2526
* In addition, if the session has been started it overrides the Cache-Control
2627
* header in such a way that all caching is disabled in that case.
2728
* If you have a scenario where caching responses with session information in
2829
* them makes sense, you can disable this behaviour by setting the header
29-
* AbstractSessionListener::SESSION_NO_AUTO_CACHE_CONTROL on the response.
30+
* AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER on the response.
3031
*
3132
* @author Johannes M. Schmitt <[email protected]>
3233
* @author Tobias Schultze <http://tobion.de>
3334
*/
3435
abstract class AbstractSessionListener implements EventSubscriberInterface
3536
{
36-
const SESSION_NO_AUTO_CACHE_CONTROL = 'Symfony-Session-NoAutoCacheControl';
37+
const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl';
3738

3839
protected $container;
3940

@@ -71,7 +72,7 @@ public function onKernelResponse(FilterResponseEvent $event)
7172
$response = $event->getResponse();
7273

7374
if ($session->isStarted() || ($session instanceof Session && $session->hasBeenStarted())) {
74-
if (!$response->headers->has(self::SESSION_NO_AUTO_CACHE_CONTROL)) {
75+
if (!$response->headers->has(self::NO_AUTO_CACHE_CONTROL_HEADER)) {
7576
$response
7677
->setPrivate()
7778
->setMaxAge(0)
@@ -80,7 +81,7 @@ public function onKernelResponse(FilterResponseEvent $event)
8081
}
8182

8283
// Always remove the internal header if present
83-
$response->headers->remove(self::SESSION_NO_AUTO_CACHE_CONTROL);
84+
$response->headers->remove(self::NO_AUTO_CACHE_CONTROL_HEADER);
8485

8586
if ($session->isStarted()) {
8687
/*

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testResponseIsPrivateIfSessionStarted()
7474
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
7575
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
7676
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
77-
$this->assertFalse($response->headers->has(AbstractSessionListener::SESSION_NO_AUTO_CACHE_CONTROL));
77+
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
7878
}
7979

8080
public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
@@ -91,14 +91,14 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
9191

9292
$response = new Response();
9393
$response->setSharedMaxAge(60);
94-
$response->headers->set(AbstractSessionListener::SESSION_NO_AUTO_CACHE_CONTROL, 'true');
94+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
9595
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
9696

9797
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
9898
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
9999
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
100100
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
101-
$this->assertFalse($response->headers->has(AbstractSessionListener::SESSION_NO_AUTO_CACHE_CONTROL));
101+
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
102102
}
103103

104104
public function testUninitilizedSession()

0 commit comments

Comments
 (0)