|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Netgen\InformationCollection\Container\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Netgen\InformationCollection\API\Priority; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Exception\LogicException; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
class ActionsPass implements CompilerPassInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* {@inheritdoc} |
|
15
|
|
|
*/ |
|
16
|
|
|
public function process(ContainerBuilder $container) |
|
17
|
|
|
{ |
|
18
|
|
|
if (!$container->hasDefinition('netgen_information_collection.action.registry')) { |
|
19
|
|
|
return; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$actionAggregate = $container->getDefinition('netgen_information_collection.action.registry'); |
|
23
|
|
|
|
|
24
|
|
|
foreach ($container->findTaggedServiceIds('netgen_information_collection.action') as $id => $attributes) { |
|
25
|
|
|
foreach ($attributes as $attribute) { |
|
26
|
|
|
if (!isset($attribute['alias'])) { |
|
27
|
|
|
throw new LogicException( |
|
28
|
|
|
"'netgen_information_collection.action' service tag " . |
|
29
|
|
|
"needs an 'alias' attribute to identify the action. None given." |
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$priority = isset($attribute['priority']) ? $attribute['priority'] : Priority::DEFAULT_PRIORITY; |
|
34
|
|
|
|
|
35
|
|
|
if ($priority > Priority::MAX_PRIORITY && $attribute['alias'] !== 'database') { |
|
36
|
|
|
throw new LogicException( |
|
37
|
|
|
"Service {$id} uses priority greater than allowed. " . |
|
38
|
|
|
'Priority must be lower than or equal to ' . Priority::MAX_PRIORITY . '.' |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if ($priority < Priority::MIN_PRIORITY) { |
|
43
|
|
|
throw new LogicException( |
|
44
|
|
|
"Service {$id} uses priority less than allowed. " . |
|
45
|
|
|
'Priority must be greater than or equal to ' . Priority::MIN_PRIORITY . '.' |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$actionAggregate->addMethodCall( |
|
50
|
|
|
'addAction', |
|
51
|
|
|
array( |
|
52
|
|
|
$attribute['alias'], |
|
53
|
|
|
new Reference($id), |
|
54
|
|
|
$priority, |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|