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