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

PiedWebCMSExtension::loadConfigHelper()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 12
rs 10
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