HappyrGoogleSiteAuthenticatorExtension::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Happyr\GoogleSiteAuthenticatorBundle\DependencyInjection;
4
5
use Happyr\GoogleSiteAuthenticatorBundle\Model\TokenConfig;
6
use Happyr\GoogleSiteAuthenticatorBundle\Service\ClientProvider;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ChildDefinition;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\DefinitionDecorator;
11
use Symfony\Component\DependencyInjection\Loader;
12
use Symfony\Component\DependencyInjection\Reference;
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
15
class HappyrGoogleSiteAuthenticatorExtension extends Extension
16
{
17
    /**
18
     * @param array            $configs
19 2
     * @param ContainerBuilder $container
20
     */
21 2
    public function load(array $configs, ContainerBuilder $container)
22 2
    {
23
        $configuration = new Configuration();
24 2
        $config = $this->processConfiguration($configuration, $configs);
25 2
26
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27
        $loader->load('services.yml');
28 2
29 2
        // Configure the correct PSR-6 cache
30
        $clientProvider = $container->getDefinition(ClientProvider::class);
31
        $clientProvider->replaceArgument(1, new Reference($config['cache_service']));
32 2
33 2
        // Configure TokenConfig
34
        $definition = $container->getDefinition(TokenConfig::class);
35
        $definition->replaceArgument(0, $config['tokens']);
36 2
37 2
        // make sure we shortcut the service name
38 2
        $decorator = new ChildDefinition('happyr.google_site_authenticator.client');
39 2
        foreach ($config['tokens'] as $name => $tokenConfig) {
40
            $service = $container->setDefinition('google.client.'.$name, $decorator);
41
            $service->replaceArgument(0, $name);
42
        }
43 2
44 2
        // set an alias for happyr.google_site_authenticator.client
45
        $container->setAlias('google.client', 'happyr.google_site_authenticator.client');
46
    }
47
}
48