Completed
Push — master ( 93e21a...f3a82e )
by Christian
03:39
created

SecurityContextCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\MediaBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * SecurityContextCompilerPass.
19
 *
20
 * This compiler pass provides compatibility with Syfmony < 2.6 security.context service
21
 * and 2.6+ security.authorization_checker service. This pass may be removed when support
22
 * for Symfony < 2.6 is dropped.
23
 */
24
class SecurityContextCompilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        // Prefer the security.authorization_checker service
32
        if ($container->hasDefinition('security.authorization_checker')) {
33
            $security = $container->getDefinition('security.authorization_checker');
34
        } else {
35
            $security = $container->getDefinition('security.context');
36
        }
37
38
        $container->getDefinition('sonata.media.security.superadmin_strategy')
39
            ->replaceArgument(1, $security);
40
41
        $container->getDefinition('sonata.media.security.connected_strategy')
42
            ->replaceArgument(1, $security);
43
    }
44
}
45