Skip to content

Commit

Permalink
Merge pull request #445 from FriendsOfSymfony/session-listener-no-ses…
Browse files Browse the repository at this point in the history
…sion

when sessions are not enabled, the listener does not exist either
  • Loading branch information
dbu authored Apr 20, 2018
2 parents 4e719a9 + 63ce9f4 commit 6b75eba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

2.2.2
-----

### Fixed

* Fix session_listener decoration when session is not enabled.

2.2.1
-----

Expand Down
35 changes: 35 additions & 0 deletions src/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');
}
}
7 changes: 7 additions & 0 deletions src/FOSHttpCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\SessionListenerRemovePass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;

class FOSHttpCacheBundle extends Bundle
{
Expand All @@ -28,6 +30,11 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new LoggerPass());
$container->addCompilerPass(new TagListenerPass());
$container->addCompilerPass(new HashGeneratorPass());
if (version_compare(Kernel::VERSION, '3.4', '>=')
&& version_compare(Kernel::VERSION, '4.1', '<')
) {
$container->addCompilerPass(new SessionListenerRemovePass());
}
}

public function registerCommands(Application $application)
Expand Down

0 comments on commit 6b75eba

Please sign in to comment.