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
|
|
|
#[\Override] |
32
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
33
|
|
|
{ |
34
|
|
|
$configuration = new Configuration(); |
35
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
36
|
|
|
|
37
|
|
|
foreach ($config as $key => $value) { |
38
|
|
|
$container->setParameter('xiidea.easy_audit.' . $key, $value); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
42
|
|
|
$loader->load('services.yml'); |
43
|
|
|
|
44
|
|
|
$this->loadDefaultResolverServices($config, $loader); |
45
|
|
|
|
46
|
|
|
if (false !== $config['doctrine_objects']) { |
47
|
|
|
$loader->load('doctrine_services.yml'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $config |
53
|
|
|
* @param LoaderInterface $loader |
54
|
|
|
* |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
|
|
protected function loadDefaultResolverServices($config, LoaderInterface $loader) |
58
|
|
|
{ |
59
|
|
|
if ('xiidea.easy_audit.default_event_resolver' === $config['resolver']) { |
60
|
|
|
$loader->load('default/event-resolver.yml'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (true === $config['default_logger']) { |
64
|
|
|
$loader->load('default/logger.yml'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (false !== $config['doctrine_objects'] && 'xiidea.easy_audit.default_doctrine_event_resolver' === $config['doctrine_event_resolver']) { |
68
|
|
|
$loader->load('default/doctrine-event-resolver.yml'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Allow an extension to prepend the extension configurations. |
74
|
|
|
* @param ContainerBuilder $container |
75
|
|
|
*/ |
76
|
|
|
#[\Override] |
77
|
|
|
public function prepend(ContainerBuilder $container): void |
78
|
|
|
{ |
79
|
|
|
$prependConfig = $this->getExtendedConfig($container); |
80
|
|
|
|
81
|
|
|
if (!empty($prependConfig)) { |
82
|
|
|
$container->prependExtensionConfig($this->getAlias(), $prependConfig); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param ContainerBuilder $container |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
protected function getExtendedConfig(ContainerBuilder $container): array |
92
|
|
|
{ |
93
|
|
|
$configs = array_merge(...$container->getExtensionConfig($this->getAlias())); |
94
|
|
|
|
95
|
|
|
$prependConfig = []; |
96
|
|
|
|
97
|
|
|
$doctrineConfig = $container->getExtensionConfig('doctrine'); |
98
|
|
|
|
99
|
|
|
if (!empty($doctrineConfig) && !isset($configs['doctrine_event_resolver'])) { |
100
|
|
|
$prependConfig['doctrine_event_resolver'] = 'xiidea.easy_audit.default_doctrine_event_resolver'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $prependConfig; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|