1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Bundle\ObjectAgent\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
|
10
|
|
|
class ObjectAgentPass implements CompilerPassInterface |
11
|
|
|
{ |
12
|
|
|
public function process(ContainerBuilder $container) |
13
|
|
|
{ |
14
|
|
|
if (!$container->has('psi_object_agent.agent_finder')) { |
15
|
|
|
return; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$taggedIds = $container->findTaggedServiceIds('psi_object_agent.agent'); |
19
|
|
|
$registryDef = $container->getDefinition('psi_object_agent.agent_finder'); |
20
|
|
|
$enabledAgents = $container->getParameter('psi_object_agent.enabled_agents'); |
21
|
|
|
|
22
|
|
|
foreach ($taggedIds as $serviceId => $attributes) { |
23
|
|
|
var_dump($serviceId); |
|
|
|
|
24
|
|
|
$attributes = $attributes[0]; |
25
|
|
|
if (!isset($attributes['alias'])) { |
26
|
|
|
throw new InvalidArgumentException(sprintf( |
27
|
|
|
$this->context . ' "%s" has no "alias" attribute in its tag', |
|
|
|
|
28
|
|
|
$serviceId |
29
|
|
|
)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$alias = $attributes['alias']; |
33
|
|
|
|
34
|
|
|
$agents[$alias] = new Reference($serviceId); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($diff = array_diff($enabledAgents, array_keys($agents))) { |
|
|
|
|
38
|
|
|
throw new \RuntimeException(sprintf( |
39
|
|
|
'Unknown agent(s) "%s". Known agents: "%s"', |
40
|
|
|
implode('", "', $diff), implode('", "', array_keys($agents)) |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$agents = array_filter($agents, function ($key) use ($enabledAgents) { |
45
|
|
|
return in_array($key, $enabledAgents); |
46
|
|
|
}, ARRAY_FILTER_USE_KEY); |
47
|
|
|
|
48
|
|
|
$registryDef->replaceArgument(0, $agents); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|