|
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\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
17
|
|
|
|
|
18
|
|
|
class ResolverFactoryPass implements CompilerPassInterface |
|
19
|
|
|
{ |
|
20
|
|
|
#[\Override] |
|
21
|
|
|
public function process(ContainerBuilder $container): void |
|
22
|
|
|
{ |
|
23
|
|
|
if (false === $container->hasDefinition('xiidea.easy_audit.event_resolver_factory')) { |
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$definition = $container->getDefinition('xiidea.easy_audit.event_resolver_factory'); |
|
28
|
|
|
|
|
29
|
|
|
$calls = $definition->getMethodCalls(); |
|
30
|
|
|
$definition->setMethodCalls(array()); |
|
31
|
|
|
|
|
32
|
|
|
foreach ($container->getParameter('xiidea.easy_audit.custom_resolvers') as $id) { |
|
33
|
|
|
if ($container->hasDefinition($id)) { |
|
34
|
|
|
$definition->addMethodCall('addCustomResolver', array($id, new Reference($id))); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$definition->addMethodCall('setCommonResolver', array( |
|
39
|
|
|
$this->getServiceReferenceByConfigName($container, 'resolver'), ) |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
if (null !== $container->getParameter('xiidea.easy_audit.doctrine_event_resolver')) { |
|
43
|
|
|
$definition->addMethodCall('setEntityEventResolver', array( |
|
44
|
|
|
$this->getServiceReferenceByConfigName($container, 'doctrine_event_resolver'), ) |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param ContainerBuilder $container |
|
53
|
|
|
* @param $configName |
|
54
|
|
|
* |
|
55
|
|
|
* @return Reference |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getServiceReferenceByConfigName(ContainerBuilder $container, $configName) |
|
58
|
|
|
{ |
|
59
|
|
|
return new Reference($container->getParameter('xiidea.easy_audit.'.$configName)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|