Completed
Pull Request — master (#30)
by
unknown
02:40
created

EnumExtension::load()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 9.568
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Yokai\EnumBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
use Yokai\EnumBundle\Enum\EnumInterface;
10
use Yokai\EnumBundle\Registry\EnumRegistryInterface;
11
12
/**
13
 * @author Yann Eugoné <[email protected]>
14
 */
15
class EnumExtension extends Extension
16
{
17
    /**
18
     * @inheritdoc
19
     */
20 4
    public function load(array $configs, ContainerBuilder $container)
21
    {
22 4
        $configuration = new Configuration();
23 4
        $config = $this->processConfiguration($configuration, $configs);
24
25 4
        $container->setParameter('enum.register_bundles', $config['register_bundles']);
26
27 4
        $xmlLoader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
28 4
        $xmlLoader->load('services.xml');
29 4
        $xmlLoader->load('forms.xml');
30 4
        $xmlLoader->load('validators.xml');
31 4
        $xmlLoader->load('twig.xml');
32
33 4
        if ($config['enum_autoconfiguration'] && method_exists($container, 'registerForAutoconfiguration')) {
34 3
            $container->registerForAutoconfiguration(EnumInterface::class)
35 3
                ->addTag('enum');
36
        }
37
38 4
        if ($config['enum_registry_autoconfigurable']) {
39 3
            $container->setAlias(EnumRegistryInterface::class, 'enum.registry');
40
        }
41 4
    }
42
}
43