1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the XiideaEasyAuditBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Xiidea <http://www.xiidea.net> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xiidea\EasyAuditBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This is the class that loads and manages your bundle configuration. |
23
|
|
|
* |
24
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
25
|
|
|
*/ |
26
|
|
|
class XiideaEasyAuditExtension extends Extension implements PrependExtensionInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function load(array $configs, ContainerBuilder $container) |
32
|
|
|
{ |
33
|
|
|
$configuration = new Configuration(); |
34
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
35
|
|
|
|
36
|
|
|
foreach ($config as $key => $value) { |
37
|
|
|
$container->setParameter('xiidea.easy_audit.' . $key, $value); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
41
|
|
|
$loader->load('services.yml'); |
42
|
|
|
|
43
|
|
|
$this->loadDefaultResolverServices($config, $loader); |
44
|
|
|
|
45
|
|
|
if (false !== $config['doctrine_objects']) { |
46
|
|
|
$loader->load('doctrine_services.yml'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $config |
52
|
|
|
* @param LoaderInterface $loader |
53
|
|
|
* |
54
|
|
|
* @throws \Exception |
55
|
|
|
*/ |
56
|
|
|
protected function loadDefaultResolverServices($config, LoaderInterface $loader) |
57
|
|
|
{ |
58
|
|
|
if ('xiidea.easy_audit.default_event_resolver' === $config['resolver']) { |
59
|
|
|
$loader->load('default/event-resolver.yml'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (true === $config['default_logger']) { |
63
|
|
|
$loader->load('default/logger.yml'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (false !== $config['doctrine_objects'] && 'xiidea.easy_audit.default_doctrine_event_resolver' === $config['doctrine_event_resolver']) { |
67
|
|
|
$loader->load('default/doctrine-event-resolver.yml'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Allow an extension to prepend the extension configurations. |
73
|
|
|
* @param ContainerBuilder $container |
74
|
|
|
*/ |
75
|
|
|
public function prepend(ContainerBuilder $container) |
76
|
|
|
{ |
77
|
|
|
$prependConfig = $this->getExtendedConfig($container); |
78
|
|
|
|
79
|
|
|
if (!empty($prependConfig)) { |
80
|
|
|
$container->prependExtensionConfig($this->getAlias(), $prependConfig); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param ContainerBuilder $container |
86
|
|
|
* |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
protected function getExtendedConfig(ContainerBuilder $container) |
90
|
|
|
{ |
91
|
|
|
$configs = array_merge(...$container->getExtensionConfig($this->getAlias())); |
92
|
|
|
|
93
|
|
|
$prependConfig = []; |
94
|
|
|
|
95
|
|
|
$doctrineConfig = $container->getExtensionConfig('doctrine'); |
96
|
|
|
|
97
|
|
|
if (!empty($doctrineConfig) && !isset($configs['doctrine_event_resolver'])) { |
98
|
|
|
$prependConfig['doctrine_event_resolver'] = 'xiidea.easy_audit.default_doctrine_event_resolver'; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $prependConfig; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|