XabbuhLrsExtension::loadMongoDbDriver()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 21
rs 9.3142
c 1
b 0
f 1
cc 2
eloc 14
nc 2
nop 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
    public function load(array $configs, ContainerBuilder $container)
33
    {
34
        $processor = new Processor();
35
        $configuration = new Configuration();
36
        $config = $processor->processConfiguration($configuration, $configs);
37
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38
39
        // load the database driver
40
        switch ($config['driver']) {
41
            case 'mongodb':
42
                $this->loadMongoDbDriver($container, $loader);
43
                break;
44
        }
45
46
        $loader->load('listener.xml');
47
        $loader->load('serializer.xml');
48
    }
49
50
    private function loadMongoDbDriver(ContainerBuilder $container, LoaderInterface $loader)
51
    {
52
        $loader->load('mongodb.xml');
53
54
        $statementObjectManager = $container->getDefinition('xabbuh_lrs.statement_object_manager');
55
        $statementRepository = $container->getDefinition('xabbuh_lrs.statement_repository');
56
57
        if (method_exists('Symfony\Component\DependencyInjection\Definition', 'setFactory')) {
58
            $statementObjectManager->setFactory(array(new Reference('doctrine_mongodb'), 'getManagerForClass'));
59
            $statementRepository->setFactory(array(
60
                new Reference('xabbuh_lrs.statement_object_manager'),
61
                'getRepository'
62
            ));
63
        } else {
64
            $statementObjectManager->setFactoryService('doctrine_mongodb');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Depend...on::setFactoryService() has been deprecated with message: since version 2.6, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
65
            $statementObjectManager->setFactoryMethod('getManagerForClass');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Depend...ion::setFactoryMethod() has been deprecated with message: since version 2.6, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
66
67
            $statementRepository->setFactoryService('xabbuh_lrs.statement_object_manager');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Depend...on::setFactoryService() has been deprecated with message: since version 2.6, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
68
            $statementRepository->setFactoryMethod('getRepository');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Depend...ion::setFactoryMethod() has been deprecated with message: since version 2.6, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
69
        }
70
    }
71
}
72