Skip to content

Commit

Permalink
Merge pull request #447 from emodric/session_listener_regression
Browse files Browse the repository at this point in the history
[1.3] when sessions are not enabled, the listener does not exist either
  • Loading branch information
dbu committed Apr 24, 2018
2 parents 5e9a1b2 + 16425d8 commit 860edff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.3.15
------

* Fix session_listener decoration when session is not enabled.

1.3.14
------

Expand Down
35 changes: 35 additions & 0 deletions DependencyInjection/Compiler/SessionListenerRemovePass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the FOSHttpCacheBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* 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');
}
}
5 changes: 5 additions & 0 deletions FOSHttpCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
}
}
}

0 comments on commit 860edff

Please sign in to comment.