1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebnetFr\DatabaseAnonymizerBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Processor; |
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
10
|
|
|
use WebnetFr\DatabaseAnonymizer\ConfigGuesser\ConfigGuesser; |
11
|
|
|
use WebnetFr\DatabaseAnonymizerBundle\Command\AnonymizeCommand; |
12
|
|
|
use WebnetFr\DatabaseAnonymizerBundle\Config\AnnotationConfigFactory; |
13
|
|
|
use WebnetFr\DatabaseAnonymizerBundle\DependencyInjection\Configuration; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Vlad Riabchenko <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class AnonymizeCommandPass implements CompilerPassInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
public function process(ContainerBuilder $container) |
24
|
|
|
{ |
25
|
|
|
if (!$container->has(AnonymizeCommand::class)) { |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$anonymizeCommandDefinition = $container->findDefinition(AnonymizeCommand::class); |
30
|
|
|
|
31
|
|
|
// Pass default anonymizer configuration to the command. |
32
|
|
|
$configuration = new Configuration(); |
33
|
|
|
$processor = new Processor(); |
34
|
|
|
$defaultConfig = $processor->processConfiguration( |
35
|
|
|
$configuration, |
36
|
|
|
$container->getExtensionConfig('webnet_fr_database_anonymizer') |
37
|
|
|
); |
38
|
|
|
$anonymizeCommandDefinition->addMethodCall('setDefaultConfig', [$defaultConfig]); |
39
|
|
|
|
40
|
|
|
// Pass the Doctrine registry to the command if it exists. |
41
|
|
|
if ($container->has('doctrine')) { |
42
|
|
|
$anonymizeCommandDefinition->addMethodCall('setRegistry', [new Reference('doctrine')]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Enable Doctrine annotations. |
46
|
|
|
if ($container->has('annotations.reader')) { |
47
|
|
|
$annotationConfigFactoryDefinition = new Definition( |
48
|
|
|
AnnotationConfigFactory::class, |
49
|
|
|
[ |
50
|
|
|
new Reference('annotations.reader'), |
51
|
|
|
new Reference(ConfigGuesser::class), |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
$container->setDefinition(AnnotationConfigFactory::class, $annotationConfigFactoryDefinition); |
55
|
|
|
|
56
|
|
|
$anonymizeCommandDefinition->addMethodCall('enableAnnotations', [new Reference(AnnotationConfigFactory::class)]); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|