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'); |
|
|
|
|
65
|
|
|
$statementObjectManager->setFactoryMethod('getManagerForClass'); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$statementRepository->setFactoryService('xabbuh_lrs.statement_object_manager'); |
|
|
|
|
68
|
|
|
$statementRepository->setFactoryMethod('getRepository'); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.