DekaleeCdn77Extension::prepend()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 16
Ratio 76.19 %

Importance

Changes 0
Metric Value
dl 16
loc 21
rs 9.584
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
namespace Dekalee\Cdn77Bundle\DependencyInjection;
4
5
use Dekalee\Cdn77\Query\CreateResourceQuery;
6
use Dekalee\Cdn77\Query\DeleteResourceQuery;
7
use Dekalee\Cdn77\Query\ListResourcesQuery;
8
use Dekalee\Cdn77\Query\PurgeAllQuery;
9
use Dekalee\Cdn77\Query\PurgeFileQuery;
10
use Dekalee\Cdn77\Query\ResourceLogQuery;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\Config\FileLocator;
13
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
14
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15
use Symfony\Component\DependencyInjection\Loader;
16
17
/**
18
 * This is the class that loads and manages your bundle configuration
19
 *
20
 * To learn more see {@link https://symfony.com}
21
 */
22
class DekaleeCdn77Extension extends Extension implements PrependExtensionInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load(array $configs, ContainerBuilder $container)
28
    {
29
        $configuration = new Configuration();
30
        $config = $this->processConfiguration($configuration, $configs);
31
32
        $container->setParameter('dekalee_cdn77.api.login', $config['login']);
33
        $container->setParameter('dekalee_cdn77.api.password', $config['password']);
34
35
        foreach ([
36
            'list' => ListResourcesQuery::URL,
37
            'purge' => PurgeFileQuery::URL,
38
            'purge_all' => PurgeAllQuery::URL,
39
            'create' => CreateResourceQuery::URL,
40
            'resource_log' => ResourceLogQuery::URL,
41
            'delete_resource' => DeleteResourceQuery::URL,
42
        ] as $queryType => $url) {
43
            if (array_key_exists($queryType, $config['url'])) {
44
                $url = $config['url'][$queryType];
45
            }
46
            $container->setParameter('dekalee_cdn77.url.' . $queryType, $url);
47
        }
48
49
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
50
        $loader->load('query.yaml');
51
        $loader->load('command.yaml');
52
53
        $bundles = $container->getParameter('kernel.bundles');
54
        if (!array_key_exists('GuzzleBundle', $bundles)) {
55
            $loader->load('client.yaml');
56
        }
57
    }
58
59
    /**
60
     * Allow an extension to prepend the extension configurations.
61
     *
62
     * @param ContainerBuilder $container
63
     */
64
    public function prepend(ContainerBuilder $container)
65
    {
66
        $bundles = $container->getParameter('kernel.bundles');
67
68 View Code Duplication
        if (array_key_exists('EightPointsGuzzleBundle', $bundles)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
            $config = $container->getExtensionConfig('eight_points_guzzle');
70
            $config[0]['clients']['cdn77'] = [
71
                'base_url' => ''
72
            ];
73
            $processedConfiguration = $this->processConfiguration(new \EightPoints\Bundle\GuzzleBundle\DependencyInjection\Configuration('eight_points_guzzle'), $config);
74
75
            $container->prependExtensionConfig('eight_points_guzzle', $processedConfiguration);
76
        }
77 View Code Duplication
        if (array_key_exists('GuzzleBundle', $bundles)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
            $config = $container->getExtensionConfig('guzzle');
79
            $config[0]['clients']['cdn77'] = null;
80
            $processedConfiguration = $this->processConfiguration(new \EightPoints\Bundle\GuzzleBundle\DependencyInjection\Configuration('guzzle'), $config);
81
82
            $container->prependExtensionConfig('guzzle', $processedConfiguration);
83
        }
84
    }
85
}
86