Completed
Push — master ( 09827c...357bd4 )
by Ivo
01:50
created

FreshcellsSoapClientExtension::load()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 15
cts 15
cp 1
rs 8.8177
c 0
b 0
f 0
cc 6
nc 12
nop 2
crap 6
1
<?php
2
3
namespace Freshcells\SoapClientBundle\DependencyInjection;
4
5
use Freshcells\SoapClientBundle\Plugin\AnonymizerLogPlugin;
6
use Freshcells\SoapClientBundle\Plugin\LogPlugin;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Loader;
10
use Symfony\Component\DependencyInjection\Reference;
11
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
12
13
class FreshcellsSoapClientExtension extends Extension
14
{
15
    /**
16
     * {@inheritDoc}
17 3
     */
18
    public function load(array $configs, ContainerBuilder $container)
19 3
    {
20 3
        $configuration = new Configuration();
21
        $config        = $this->processConfiguration($configuration, $configs);
22 3
23 3
        foreach ($config as $key => $configVal) {
24 3
            $container->setParameter(
25 3
                'freshcells_soap_client".'.$key,
26
                $configVal
27
            );
28
        }
29 3
30 3
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
31
        $loader->load('services.xml');
32 3
33 3
        if ($config['enable_profiler']) {
34
            $loader->load('data_collector.xml');
35
        }
36 3
37 3
        if ($config['logger']) {
38 3
            $subscriber = $container->getDefinition(LogPlugin::class);
39 3
            if (isset($config['anonymize_logs']['elements']) && isset($config['anonymize_logs']['attributes'])) {
40
                $subscriber = $container->getDefinition(AnonymizerLogPlugin::class);
41 3
                $subscriber->replaceArgument('$elements', $config['anonymize_logs']['elements']);
42
                $subscriber->replaceArgument('$attributes', $config['anonymize_logs']['attributes']);
43
            }
44
            $subscriber->replaceArgument(0, new Reference($config['logger']));
45
            $subscriber->addTag('kernel.event_subscriber');
46
        }
47
    }
48
}
49