From 16425d89a163df4ee6a66b9521a4ebb65d543115 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 20 Apr 2018 08:32:01 +0200 Subject: [PATCH] when sessions are not enabled, the listener does not exist either --- CHANGELOG.md | 5 +++ .../Compiler/SessionListenerRemovePass.php | 35 +++++++++++++++++++ FOSHttpCacheBundle.php | 5 +++ 3 files changed, 45 insertions(+) create mode 100644 DependencyInjection/Compiler/SessionListenerRemovePass.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 808ffe58..b25ab649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +1.3.15 +------ + +* Fix session_listener decoration when session is not enabled. + 1.3.14 ------ diff --git a/DependencyInjection/Compiler/SessionListenerRemovePass.php b/DependencyInjection/Compiler/SessionListenerRemovePass.php new file mode 100644 index 00000000..58898975 --- /dev/null +++ b/DependencyInjection/Compiler/SessionListenerRemovePass.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\HttpCacheBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Remove the session listener decorator again if the application has no session listener. + * + * This will happen on some APIs when the session system is not activated. + */ +class SessionListenerRemovePass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + if ($container->has('session_listener')) { + return; + } + + $container->removeDefinition('fos_http_cache.user_context.session_listener'); + } +} diff --git a/FOSHttpCacheBundle.php b/FOSHttpCacheBundle.php index 7d4734cd..4b6e914b 100644 --- a/FOSHttpCacheBundle.php +++ b/FOSHttpCacheBundle.php @@ -15,8 +15,10 @@ use FOS\HttpCacheBundle\DependencyInjection\Compiler\SecurityContextPass; use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagSubscriberPass; use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass; +use FOS\HttpCacheBundle\DependencyInjection\Compiler\SessionListenerRemovePass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\HttpKernel\Kernel; class FOSHttpCacheBundle extends Bundle { @@ -29,5 +31,8 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new SecurityContextPass()); $container->addCompilerPass(new TagSubscriberPass()); $container->addCompilerPass(new HashGeneratorPass()); + if (version_compare(Kernel::VERSION, '3.4', '>=')) { + $container->addCompilerPass(new SessionListenerRemovePass()); + } } }