XabbuhLrsExtension::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
ccs 13
cts 13
cp 1
rs 9.4285
cc 2
eloc 11
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Bundle\LrsBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Processor;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\Config\Loader\LoaderInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Extension\Extension;
19
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * xAPI LRS bundle DI container extension.
24
 *
25
 * @author Christian Flothmann <[email protected]>
26
 */
27
class XabbuhLrsExtension extends Extension
28
{
29
    /**
30
     * {@inheritDoc}
31
     */
32 2
    public function load(array $configs, ContainerBuilder $container)
33
    {
34 2
        $processor = new Processor();
35 2
        $configuration = new Configuration();
36 2
        $config = $processor->processConfiguration($configuration, $configs);
37 1
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38
39
        // load the database driver
40 1
        switch ($config['driver']) {
41 1
            case 'mongodb':
42 1
                $this->loadMongoDbDriver($container, $loader);
43 1
                break;
44 1
        }
45
46 1
        $loader->load('listener.xml');
47 1
        $loader->load('serializer.xml');
48 1
    }
49
50 1
    private function loadMongoDbDriver(ContainerBuilder $container, LoaderInterface $loader)
51
    {
52 1
        $loader->load('mongodb.xml');
53
54 1
        $statementObjectManager = $container->getDefinition('xabbuh_lrs.statement_object_manager');
55 1
        $statementRepository = $container->getDefinition('xabbuh_lrs.statement_repository');
56
57 1
        if (method_exists('Symfony\Component\DependencyInjection\Definition', 'setFactory')) {
58 1
            $statementObjectManager->setFactory(array(new Reference('doctrine_mongodb'), 'getManagerForClass'));
59 1
            $statementRepository->setFactory(array(
60 1
                new Reference('xabbuh_lrs.statement_object_manager'),
61
                'getRepository'
62 1
            ));
63 1
        } else {
64
            $statementObjectManager->setFactoryService('doctrine_mongodb');
65
            $statementObjectManager->setFactoryMethod('getManagerForClass');
66
67
            $statementRepository->setFactoryService('xabbuh_lrs.statement_object_manager');
68
            $statementRepository->setFactoryMethod('getRepository');
69
        }
70 1
    }
71
}
72