Completed
Push — master ( b2a3d2...f8de40 )
by David
10:38
created

SessionListenerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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
 * Undo our workarounds for the Symfony session listener when the session
19
 * system of Symfony has not been activated.
20
 *
21
 * - Set the hasSessionListener option of the UserContextListener to false to
22
 *   avoid the AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER being
23
 *   leaked to clients.
24
 * - Remove the session listener decorator we configured.
25
 */
26
class SessionListenerPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container)
32
    {
33
        if ($container->has('session_listener')) {
34
            return;
35
        }
36
37
        if ($container->hasDefinition('fos_http_cache.event_listener.user_context')) {
38
            $contextListener = $container->getDefinition('fos_http_cache.event_listener.user_context');
39
            $contextListener->setArgument(5, false);
40
        }
41
        $container->removeDefinition('fos_http_cache.user_context.session_listener');
42
    }
43
}
44