Completed
Push — master ( c6e087...ee18d8 )
by Dorian
02:20
created

Extension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
namespace Gnutix\Library\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Processor;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Loader;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
10
11
/**
12
 * Extension
13
 */
14
class Extension implements ExtensionInterface
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function load(array $config, ContainerBuilder $container)
20
    {
21
        $configProcessor = new Processor();
22
        $config = $configProcessor->processConfiguration(new Configuration(), $config);
23
24
        $container->setParameter('gnutix_library.source_file_path', $config['source_file_path']);
25
26
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27
        $loader->load('services.yml');
28
29
        $container->setAliases($this->getLibraryAliases($config['source_file_path']));
30
    }
31
32
    /**
33
     * @param string $sourceFilePath
34
     *
35
     * @return array
36
     */
37
    protected function getLibraryAliases($sourceFilePath)
38
    {
39
        $libraryType = strtolower(pathinfo($sourceFilePath, PATHINFO_EXTENSION));
40
41
        if ('yml' === $libraryType) {
42
            $libraryType = 'yaml';
43
        }
44
45
        return array(
46
            'gnutix_library.loader' => 'gnutix_library.loader.'.$libraryType.'_file_loader',
47
            'gnutix_library.library_factory' => 'gnutix_library.library_factory.'.$libraryType.'_library_factory',
48
        );
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function getNamespace()
55
    {
56
        return '';
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function getXsdValidationBasePath()
63
    {
64
        return '';
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70
    public function getAlias()
71
    {
72
        return 'gnutix_library';
73
    }
74
}
75