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

Skip to content

Commit e8f0972

Browse files
committed
Revert SessionListener rename for BC
SessionListener and TestSessionListener are extended outside of Symfony in Silex. These classes cannot be renamed.
1 parent 1b63474 commit e8f0972

File tree

11 files changed

+187
-202
lines changed

11 files changed

+187
-202
lines changed

src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\EventListener;
1313

14-
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
14+
use Symfony\Component\HttpKernel\EventListener\ContainerAwareSessionListener;
1515

16-
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', SessionListener::class, BaseSessionListener::class), E_USER_DEPRECATED);
16+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', ContainerAwareSessionListener::class, BaseSessionListener::class), E_USER_DEPRECATED);
1717

1818
/**
1919
* Sets the session in the request.
2020
*
2121
* @author Fabien Potencier <[email protected]>
2222
*
23-
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseSessionListener} instead
23+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link ContainerAwareSessionListener} instead
2424
*/
25-
class SessionListener extends BaseSessionListener
25+
class SessionListener extends ContainerAwareSessionListener
2626
{
2727
}

src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,15 @@
1313

1414
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\HttpKernel\EventListener\TestSessionListener instead.', TestSessionListener::class), E_USER_DEPRECATED);
1515

16-
use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener;
17-
use Symfony\Component\DependencyInjection\ContainerInterface;
16+
use Symfony\Component\HttpKernel\EventListener\ContainerAwareTestSessionListener;
1817

1918
/**
2019
* TestSessionListener.
2120
*
2221
* @author Fabien Potencier <[email protected]>
2322
*
24-
* @deprecated since version 3.3, to be removed in 4.0.
23+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link ContainerAwareTestSessionListener} instead
2524
*/
26-
class TestSessionListener extends AbstractTestSessionListener
25+
class TestSessionListener extends ContainerAwareTestSessionListener
2726
{
28-
protected $container;
29-
30-
public function __construct(ContainerInterface $container)
31-
{
32-
$this->container = $container;
33-
}
34-
35-
protected function getSession()
36-
{
37-
if (!$this->container->has('session')) {
38-
return;
39-
}
40-
41-
return $this->container->get('session');
42-
}
4327
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
<service id="session.handler.write_check" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler" public="false" />
5353

54-
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\SessionListener">
54+
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\ContainerAwareSessionListener">
5555
<tag name="kernel.event_subscriber" />
5656
<tag name="container.service_subscriber" id="session" />
5757
<argument type="service" id="container" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<service id="test.client.cookiejar" class="Symfony\Component\BrowserKit\CookieJar" shared="false" />
2222

23-
<service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\TestSessionListener">
23+
<service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\ContainerAwareTestSessionListener">
2424
<tag name="kernel.event_subscriber" />
2525
<tag name="container.service_subscriber" id="session" />
2626
<argument type="service" id="container" />

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 Psr\Container\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
16+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
17+
18+
/**
19+
* Sets the session in the request.
20+
*
21+
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @final since version 3.3
24+
*/
25+
class ContainerAwareSessionListener extends SessionListener implements ServiceSubscriberInterface
26+
{
27+
private $container;
28+
29+
public function __construct(ContainerInterface $container)
30+
{
31+
$this->container = $container;
32+
}
33+
34+
protected function getSession()
35+
{
36+
if (!$this->container->has('session')) {
37+
return;
38+
}
39+
40+
return $this->container->get('session');
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public static function getSubscribedServices()
47+
{
48+
return array(
49+
'session' => '?'.SessionInterface::class,
50+
);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 Psr\Container\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
16+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
17+
18+
/**
19+
* Sets the session in the request.
20+
*
21+
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @final since version 3.3
24+
*/
25+
class ContainerAwareTestSessionListener extends TestSessionListener implements ServiceSubscriberInterface
26+
{
27+
private $container;
28+
29+
public function __construct(ContainerInterface $container)
30+
{
31+
$this->container = $container;
32+
}
33+
34+
protected function getSession()
35+
{
36+
if (!$this->container->has('session')) {
37+
return;
38+
}
39+
40+
return $this->container->get('session');
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public static function getSubscribedServices()
47+
{
48+
return array(
49+
'session' => '?'.SessionInterface::class,
50+
);
51+
}
52+
}

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,44 @@
1111

1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

14-
use Psr\Container\ContainerInterface;
15-
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1614
use Symfony\Component\HttpFoundation\Session\SessionInterface;
15+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\KernelEvents;
17+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1718

1819
/**
1920
* Sets the session in the request.
2021
*
21-
* @author Fabien Potencier <[email protected]>
22-
*
23-
* @final since version 3.3
22+
* @author Johannes M. Schmitt <[email protected]>
2423
*/
25-
class SessionListener extends AbstractSessionListener implements ServiceSubscriberInterface
24+
abstract class SessionListener implements EventSubscriberInterface
2625
{
27-
private $container;
28-
29-
public function __construct(ContainerInterface $container)
26+
public function onKernelRequest(GetResponseEvent $event)
3027
{
31-
$this->container = $container;
32-
}
28+
if (!$event->isMasterRequest()) {
29+
return;
30+
}
3331

34-
protected function getSession()
35-
{
36-
if (!$this->container->has('session')) {
32+
$request = $event->getRequest();
33+
$session = $this->getSession();
34+
if (null === $session || $request->hasSession()) {
3735
return;
3836
}
3937

40-
return $this->container->get('session');
38+
$request->setSession($session);
4139
}
4240

43-
/**
44-
* {@inheritdoc}
45-
*/
46-
public static function getSubscribedServices()
41+
public static function getSubscribedEvents()
4742
{
4843
return array(
49-
'session' => '?'.SessionInterface::class,
44+
KernelEvents::REQUEST => array('onKernelRequest', 128),
5045
);
5146
}
47+
48+
/**
49+
* Gets the session object.
50+
*
51+
* @return SessionInterface|null A SessionInterface instance or null if no session is available
52+
*/
53+
abstract protected function getSession();
5254
}

0 commit comments

Comments
 (0)