SmartAuthenticationExtension::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Smart\AuthenticationBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
6
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
10
use Symfony\Component\Config\FileLocator;
11
use Symfony\Component\Yaml\Yaml;
12
13
/**
14
 * @author Mathieu Ducrot <[email protected]>
15
 */
16
class SmartAuthenticationExtension extends Extension implements PrependExtensionInterface
17
{
18
    /**
19
     * @param array<array> $configs
20
     * @param ContainerBuilder $container
21
     * @throws \Exception
22
     * @return void
23
     */
24
    public function load(array $configs, ContainerBuilder $container)
25
    {
26
        $loader = new XmlFileLoader(
27
            $container,
28
            new FileLocator(__DIR__ . '/../Resources/config')
29
        );
30
        $loader->load('admin_extension.xml');
31
        $loader->load('security.xml');
32
        $loader->load('fixtures.xml');
33
    }
34
35
    /**
36
     * @param ContainerBuilder $container
37
     * @throws \Exception
38
     * @return void
39
     */
40
    public function prepend(ContainerBuilder $container)
41
    {
42
        $config = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml'));
43
44
        foreach ($config as $name => $extension) {
45
            $container->prependExtensionConfig($name, $extension);
46
        }
47
48
        // Override bundle template from another bundle in Symfony 4/5 https://stackoverflow.com/a/52693472
49
        $container->prependExtensionConfig('twig', array(
50
            'paths' => array(
51
                '%kernel.project_dir%/vendor/smartbooster/authentication-bundle/src/Resources/SmartSonataBundle/views' => 'SmartSonata',
52
            ),
53
        ));
54
    }
55
}
56