Skip to content

Commit 6b75eba

Browse files
authored
Merge pull request #445 from FriendsOfSymfony/session-listener-no-session
when sessions are not enabled, the listener does not exist either
2 parents 4e719a9 + 63ce9f4 commit 6b75eba

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
2.2.2
5+
-----
6+
7+
### Fixed
8+
9+
* Fix session_listener decoration when session is not enabled.
10+
411
2.2.1
512
-----
613

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSHttpCacheBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* Remove the session listener decorator again if the application has no session listener.
19+
*
20+
* This will happen on some APIs when the session system is not activated.
21+
*/
22+
class SessionListenerRemovePass implements CompilerPassInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function process(ContainerBuilder $container)
28+
{
29+
if ($container->has('session_listener')) {
30+
return;
31+
}
32+
33+
$container->removeDefinition('fos_http_cache.user_context.session_listener');
34+
}
35+
}

src/FOSHttpCacheBundle.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
1515
use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass;
16+
use FOS\HttpCacheBundle\DependencyInjection\Compiler\SessionListenerRemovePass;
1617
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
1718
use Symfony\Component\Console\Application;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\HttpKernel\Bundle\Bundle;
21+
use Symfony\Component\HttpKernel\Kernel;
2022

2123
class FOSHttpCacheBundle extends Bundle
2224
{
@@ -28,6 +30,11 @@ public function build(ContainerBuilder $container)
2830
$container->addCompilerPass(new LoggerPass());
2931
$container->addCompilerPass(new TagListenerPass());
3032
$container->addCompilerPass(new HashGeneratorPass());
33+
if (version_compare(Kernel::VERSION, '3.4', '>=')
34+
&& version_compare(Kernel::VERSION, '4.1', '<')
35+
) {
36+
$container->addCompilerPass(new SessionListenerRemovePass());
37+
}
3138
}
3239

3340
public function registerCommands(Application $application)

0 commit comments

Comments
 (0)