|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection\CompilerPass; |
|
4
|
|
|
|
|
5
|
|
|
use KGzocha\Bundle\SearcherBundle\DependencyInjection\Configuration; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Krzysztof Gzocha <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class SearcherCompilerPass extends AbstractCompilerPass |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
7 |
|
protected function processContext( |
|
18
|
|
|
$contextId, |
|
19
|
|
|
array &$context, |
|
20
|
|
|
ContainerBuilder $container |
|
21
|
|
|
) { |
|
22
|
7 |
|
$config = $context[self::SEARCHER_PARAMETER]; |
|
23
|
7 |
|
$this->validateParameters($contextId, $config); |
|
24
|
|
|
|
|
25
|
7 |
|
if (isset($config[self::SERVICE_PARAMETER])) { |
|
26
|
1 |
|
return $this->createFromService($container, $contextId, $config); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
6 |
|
$definition = new Definition($config[self::CLASS_PARAMETER]); |
|
30
|
6 |
|
if (Configuration::SEARCHER_CLASS == $config[self::CLASS_PARAMETER]) { |
|
31
|
|
|
$definition |
|
32
|
4 |
|
->addArgument($container->getDefinition( |
|
33
|
4 |
|
$this->buildServiceName($contextId, self::BUILDER_COLLECTION_PARAMETER) |
|
34
|
|
|
)) |
|
35
|
4 |
|
->addArgument($container->getDefinition( |
|
36
|
4 |
|
$this->buildServiceName($contextId, self::CONTEXT_PARAMETER) |
|
37
|
|
|
)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
6 |
|
if (isset($config[self::WRAPPER_CLASS_PARAMETER])) { |
|
41
|
4 |
|
$wrapperDefinition = new Definition($config[self::WRAPPER_CLASS_PARAMETER]); |
|
42
|
4 |
|
$wrapperDefinition->addArgument($definition); |
|
43
|
|
|
|
|
44
|
4 |
|
return $container->setDefinition( |
|
45
|
4 |
|
$this->buildServiceName($contextId, self::SEARCHER_PARAMETER), |
|
46
|
|
|
$wrapperDefinition |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
return $container->setDefinition( |
|
51
|
2 |
|
$this->buildServiceName($contextId, self::SEARCHER_PARAMETER), |
|
52
|
|
|
$definition |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param ContainerBuilder $container |
|
58
|
|
|
* @param string $contextId |
|
59
|
|
|
* @param array $config |
|
60
|
|
|
* |
|
61
|
|
|
* @return Definition |
|
62
|
|
|
*/ |
|
63
|
1 |
|
private function createFromService( |
|
64
|
|
|
ContainerBuilder $container, |
|
65
|
|
|
$contextId, |
|
66
|
|
|
array &$config |
|
67
|
|
|
) { |
|
68
|
1 |
|
$this->checkIfServiceExists( |
|
69
|
|
|
$container, |
|
70
|
|
|
$contextId, |
|
71
|
1 |
|
$config[self::SERVICE_PARAMETER] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
1 |
|
if (isset($config[self::WRAPPER_CLASS_PARAMETER])) { |
|
75
|
1 |
|
$definition = new Definition($config[self::WRAPPER_CLASS_PARAMETER]); |
|
76
|
1 |
|
$definition->addArgument( |
|
77
|
1 |
|
$container->getDefinition($config[self::SERVICE_PARAMETER]) |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
1 |
|
return $container->setDefinition( |
|
81
|
1 |
|
$this->buildServiceName($contextId, self::SEARCHER_PARAMETER), |
|
82
|
|
|
$definition |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $container->setDefinition( |
|
87
|
|
|
$this->buildServiceName($contextId, self::SEARCHER_PARAMETER), |
|
88
|
|
|
$container->getDefinition($config[self::SERVICE_PARAMETER]) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|