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 ($config['doctrine_entities'] !== false) { |
46
|
|
|
$loader->load('doctrine_services.yml'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $config |
52
|
|
|
* @param $loader |
53
|
|
|
*/ |
54
|
|
|
protected function loadDefaultResolverServices($config, LoaderInterface $loader) |
55
|
|
|
{ |
56
|
|
|
if ($config['resolver'] == 'xiidea.easy_audit.default_event_resolver') { |
57
|
|
|
$loader->load('default/event-resolver.yml'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (true === $config['default_logger']) { |
61
|
|
|
$loader->load('default/logger.yml'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($config['doctrine_entities'] !== false && $config['entity_event_resolver'] == 'xiidea.easy_audit.default_entity_event_resolver') { |
65
|
|
|
$loader->load('default/entity-event-resolver.yml'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Allow an extension to prepend the extension configurations. |
71
|
|
|
*/ |
72
|
|
|
public function prepend(ContainerBuilder $container) |
73
|
|
|
{ |
74
|
|
|
$extensions = $container->getExtensionConfig('doctrine'); |
75
|
|
|
$configs = $container->getExtensionConfig($this->getAlias()); |
76
|
|
|
|
77
|
|
|
if (!empty($extensions) && !isset($configs['entity_event_resolver'])) { |
78
|
|
|
$container->prependExtensionConfig($this->getAlias(), ['entity_event_resolver' => 'xiidea.easy_audit.default_entity_event_resolver']); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|