|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the 2martens Web Platform. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Jim Martens <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace TwoMartens\Bundle\CoreBundle\DependencyInjection; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Config\FileLocator; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Container extension for TwoMartensCoreBundle. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Jim Martens <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class TwoMartensCoreExtension extends Extension |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
29
|
|
|
{ |
|
30
|
|
|
$loader = new YamlFileLoader( |
|
31
|
|
|
$container, |
|
32
|
|
|
new FileLocator(__DIR__.'/../Resources/config') |
|
33
|
|
|
); |
|
34
|
|
|
$loader->load('services.yml'); |
|
35
|
|
|
|
|
36
|
|
|
// TODO replace with semantic configuration |
|
37
|
|
|
$config = [ |
|
38
|
|
|
'db_driver' => 'mongodb' |
|
39
|
|
|
]; |
|
40
|
|
|
$container->setParameter('twomartens.core.storage', $config['db_driver']); |
|
41
|
|
|
|
|
42
|
|
|
if ('custom' !== $config['db_driver']) { |
|
43
|
|
|
$loader->load(sprintf('%s.yml', $config['db_driver'])); |
|
44
|
|
|
$container->setParameter('twomartens.core.backend_type_' . $config['db_driver'], true); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
switch ($config['db_driver']) { |
|
48
|
|
|
case 'orm': |
|
49
|
|
|
$container->getDefinition('twomartens.core.group_listener') |
|
50
|
|
|
->addTag( |
|
51
|
|
|
'doctrine.event_subscriber', |
|
52
|
|
|
[ |
|
53
|
|
|
'priority' => 10 |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
break; |
|
57
|
|
|
|
|
58
|
|
|
case 'mongodb': |
|
59
|
|
|
$container->getDefinition('twomartens.core.group_listener') |
|
60
|
|
|
->addTag( |
|
61
|
|
|
'doctrine_mongodb.odm.event_subscriber', |
|
62
|
|
|
[ |
|
63
|
|
|
'priority' => 10 |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
break; |
|
67
|
|
|
|
|
68
|
|
|
case 'couchdb': |
|
69
|
|
|
$container->getDefinition('twomartens.core.group_listener') |
|
70
|
|
|
->addTag( |
|
71
|
|
|
'doctrine_couchdb.event_subscriber', |
|
72
|
|
|
[ |
|
73
|
|
|
'priority' => 10 |
|
74
|
|
|
] |
|
75
|
|
|
); |
|
76
|
|
|
break; |
|
77
|
|
|
|
|
78
|
|
|
case 'propel': |
|
79
|
|
|
break; |
|
80
|
|
|
|
|
81
|
|
|
default: |
|
82
|
|
|
break; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|