8000 [HttpKernel] Dont implement ServiceSubscriberInterface on *SessionLis… · symfony/symfony@5aa4a24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aa4a24

Browse files
[HttpKernel] Dont implement ServiceSubscriberInterface on *SessionListener
1 parent 05d15cf commit 5aa4a24

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@
5353

5454
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\SessionListener">
5555
<tag name="kernel.event_subscriber" />
56-
<tag name="container.service_subscriber" id="session" />
57-
<argument type="service" id="container" />
56+
<argument type="service">
57+
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
58+
<tag name="container.service_locator" />
59+
<argument type="collection">
60+
<argument key="session" type="service" id="session" on-invalid="ignore" />
61+
</argument>
62+
</service>
63+
</argument>
5864
</service>
5965

6066
<service id="session.save_listener" class="Symfony\Component\HttpKernel\EventListener\SaveSessionListener">

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222

2323
<service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\TestSessionListener">
2424
<tag name="kernel.event_subscriber" />
25-
<tag name="container.service_subscriber" id="session" />
26-
<argument type="service" id="container" />
25+
<argument type="service">
26+
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
27+
<tag name="container.service_locator" />
28+
<argument type="collection">
29+
<argument key="session" type="service" id="session" on-invalid="ignore" />
30+
</argument>
31+
</service>
32+
</argument>
2733
</service>
2834
</services>
2935
</container>

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

1414
use Psr\Container\ContainerInterface;
15-
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
16-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1715

1816
/**
1917
* Sets the session in the request.
@@ -22,7 +20,7 @@
2220
*
2321
* @final since version 3.3
2422
*/
25-
class SessionListener extends AbstractSessionListener implements ServiceSubscriberInterface
23+
class SessionListener extends AbstractSessionListener
2624
{
2725
private $container;
2826

@@ -39,14 +37,4 @@ protected function getSession()
3937

4038
return $this->container->get('session');
4139
}
42-
43-
/**
44-
* {@inheritdoc}
45-
*/
46-
public static function getSubscribedServices()
47-
{
48-
return array(
49-
'session' => '?'.SessionInterface::class,
50-
);
51-
}
5240
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

1414
use Psr\Container\ContainerInterface;
15-
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
16-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1715

1816
/**
1917
* Sets the session in the request.
@@ -22,7 +20,7 @@
2220
*
2321
* @final since version 3.3
2422
*/
25-
class TestSessionListener extends AbstractTestSessionListener implements ServiceSubscriberInterface
23+
class TestSessionListener extends AbstractTestSessionListener
2624
{
2725
private $container;
2826

@@ -39,14 +37,4 @@ protected function getSession()
3937

4038
return $this->container->get('session');
4139
}
42-
43-
/**
44-
* {@inheritdoc}
45-
*/
46-
public static function getSubscribedServices()
47-
{
48-
return array(
49-
'session' => '?'.SessionInterface::class,
50-
);
51-
}
5240
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\HttpKernel\Tests\EventListener;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1516
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpKernel\HttpKernelInterface;
1819
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
20+
use Symfony\Component\HttpKernel\EventListener\SessionListener;
21+
use Symfony\Component\HttpKernel\EventListener\TestSessionListener;
1922
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2023

2124
/**
@@ -79,6 +82,15 @@ public function testUnstartedSessionIsNotSave()
7982
$this->filterResponse(new Request());
8083
}
8184

85+
public function testDoesNotImplementServiceSubscriberInterface()
86+
{
87+
$this->assertTrue(interface_exists(ServiceSubscriberInterface::class));
88+
$this->assertTrue(class_exists(SessionListener::class));
89+
$this->assertTrue(class_exists(TestSessionListener::class));
90+
$this->assertFalse(is_subclass_of(SessionListener::class, ServiceSubscriberInterface::class), 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cant afford');
91+
$this->assertFalse(is_subclass_of(TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cant afford'));
92+
}
93+
8294
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
8395
{
8496
$request->setSession($this->session);

0 commit comments

Comments
 (0)
0