SecurityServicesPass   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 29 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\SymfonySecurityBridgeBundle\DependencyInjection\Compiler;
14
15
use BenGorUser\SymfonySecurityBridge\Infrastructure\Security\SymfonyUserPasswordEncoder;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Reference;
20
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
21
22
/**
23
 * Register security services compiler pass.
24
 *
25
 * Service declaration via PHP allows more
26
 * flexibility with customization extend users.
27
 *
28
 * @author Beñat Espiña <[email protected]>
29
 */
30
class SecurityServicesPass implements CompilerPassInterface
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function process(ContainerBuilder $container)
36
    {
37
        $config = $container->getParameter('bengor_user.config');
38
39
        foreach ($config['user_class'] as $key => $user) {
40
            $container->setDefinition(
41
                $key . '_password_encoder',
42
                (new Definition(
43
                    BCryptPasswordEncoder::class, [
44
                        $user['class'],
45
                    ]
46
                ))->setFactory([new Reference('security.encoder_factory'), 'getEncoder'])
47
            )->setPublic(false);
48
49
            $container->setDefinition(
50
                'bengor.user.infrastructure.security.symfony.' . $key . '_password_encoder',
51
                new Definition(
52
                    SymfonyUserPasswordEncoder::class, [
53
                        $container->getDefinition($key . '_password_encoder'),
54
                    ]
55
                )
56
            )->setPublic(false);
57
58
            $container->setAlias(
59
                'bengor_user.' . $key . '.symfony_password_encoder',
60
                'bengor.user.infrastructure.security.symfony.' . $key . '_password_encoder'
61
            );
62
        }
63
    }
64
}
65