Passed
Pull Request — master (#101)
by Łukasz
03:05
created

FirewallMapCompilerPass::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 3
nop 1
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
15
class FirewallMapCompilerPass implements CompilerPassInterface
16
{
17
    const FIREWALL_MAPPER_SERVICE = 'admin_security.firewall_mapper';
18
19
    public function process(ContainerBuilder $container)
20
    {
21
        if (false === $container->hasAlias(self::FIREWALL_MAPPER_SERVICE) &&
22
            false === $container->hasDefinition(self::FIREWALL_MAPPER_SERVICE)) {
23
            return;
24
        }
25
26
        $map = $container->getDefinition('security.firewall.map');
27
        $maps = $map->getArgument(1);
28
29
        $refs = [];
30
        foreach ($maps as $serviceName => $firewall) {
31
            $refs[substr($serviceName, 30)] = $firewall;
32
        }
33
34
        $firewallManagerDef = $container->getDefinition(self::FIREWALL_MAPPER_SERVICE);
35
        $firewallManagerDef->replaceArgument(0, $refs);
36
    }
37
}
38