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

FirewallMapCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 4
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