Passed
Push — master ( d392b0...2c4ea6 )
by Dev
11:36
created

PiedWebCMSExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 13
c 1
b 1
f 0
dl 0
loc 35
rs 10
ccs 0
cts 13
cp 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfigToParameters() 0 8 3
A load() 0 9 1
A getAlias() 0 3 1
1
<?php
2
/**
3
 * todo: make it cleaner: https://symfony.com/doc/current/bundles/prepend_extension.html.
4
 */
5
6
namespace PiedWeb\CMSBundle\DependencyInjection;
7
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Extension\Extension;
11
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
12
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
13
use Symfony\Component\Finder\Finder;
14
use Symfony\Component\Yaml\Parser;
15
16
class PiedWebCMSExtension extends Extension //implements PrependExtensionInterface
17
{
18
    public function load(array $configs, ContainerBuilder $container)
19
    {
20
        $configuration = new Configuration(); //$configuration = $this->getConfiguration($configs, $container);
21
        $config = $this->processConfiguration($configuration, $configs);
22
23
        self::loadConfigToParameters($container, $config);
24
25
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
        $loader->load('services.yaml');
27
28
        // todo : https://symfony.com/doc/current/bundles/extension.html#adding-classes-to-compile
29
    }
30
31
    /**
32
     * @param string $prefix must contain the last
33
     *
34
     * @return void
35
     */
36
    protected static function loadConfigToParameters(ContainerBuilder $container, array $config, $prefix = '')
37
    {
38
        foreach ($config as $key => $value) {
39
            if (is_array($value)) {
40
                self::loadConfigToParameters($container, $value, $prefix.$key.'.');
41
            } else {
42
                $container->setParameter('app.'.$prefix.$key, $value); // to deprecate in next release
43
                $container->setParameter('pwc.'.$prefix.$key, $value);
44
            }
45
        }
46
    }
47
48
    public function getAlias()
49
    {
50
        return 'piedweb_cms'; // change to pwc todo
51
    }
52
53
    /*
54
    public function prepend(ContainerBuilder $container)
55
    {
56
        // Load configurations for other package
57
        $parser = new Parser();
58
        $finder = Finder::create()->files()->name('*.yaml')->in(__DIR__.'/../Resources/config/packages/');
59
        foreach ($finder as $file) {
60
            $configs = $parser->parse(file_get_contents($file->getRealPath()));
61
            foreach ($configs as $name => $config) {
62
                $container->prependExtensionConfig($name, $config);
63
            }
64
        }
65
    }
66
    /**/
67
}
68