FirewallMapCompilerPass::process()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
nc 5
nop 1
dl 0
loc 20
rs 9.5555
c 2
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
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
class FirewallMapCompilerPass implements CompilerPassInterface
19
{
20
    private const FIREWALL_MAPPER_SERVICE = 'admin_security.firewall_mapper';
21
22
    public function process(ContainerBuilder $container): void
23
    {
24
        if (false === $container->hasAlias(self::FIREWALL_MAPPER_SERVICE) &&
25
            false === $container->hasDefinition(self::FIREWALL_MAPPER_SERVICE)) {
26
            return;
27
        }
28
29
        $map = $container->getDefinition('security.firewall.map');
30
        $maps = $map->getArgument(1);
31
        if ($maps instanceof IteratorArgument) {
32
            $maps = $maps->getValues();
33
        }
34
35
        $refs = [];
36
        foreach ($maps as $serviceName => $firewall) {
37
            $refs[substr($serviceName, 30)] = $firewall;
38
        }
39
40
        $firewallManagerDef = $container->getDefinition(self::FIREWALL_MAPPER_SERVICE);
41
        $firewallManagerDef->replaceArgument(0, $refs);
42
    }
43
}
44