|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use OldSound\RabbitMqBundle\Logger\ExtraContextLogger; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
class ExtraContextLoggerCompilerPass implements CompilerPassInterface |
|
12
|
|
|
{ |
|
13
|
|
|
private $tags = [ |
|
|
|
|
|
|
14
|
|
|
'old_sound_rabbit_mq.producer', |
|
15
|
|
|
'old_sound_rabbit_mq.consumer', |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
public function process(ContainerBuilder $container) |
|
19
|
|
|
{ |
|
20
|
|
|
$taggedProducers = $container->findTaggedServiceIds('old_sound_rabbit_mq.producer'); |
|
21
|
|
|
$taggedConsumers = $container->findTaggedServiceIds('old_sound_rabbit_mq.consumer'); |
|
22
|
|
|
|
|
23
|
|
|
foreach ($taggedProducers as $id => $tags) { |
|
24
|
|
|
$producerName = $tags[0]['producer']; |
|
25
|
|
|
$originLogger = $id . '.logger'; |
|
26
|
|
|
|
|
27
|
|
|
if ($container->hasDefinition($originLogger)) { |
|
28
|
|
|
$consumerDef = $container->getDefinition($id); |
|
29
|
|
|
$consumerDef->removeMethodCall('setLogger'); |
|
30
|
|
|
$loggerDef = new Definition(ExtraContextLogger::class, [new Reference($originLogger), ['producer' => $producerName]]); |
|
31
|
|
|
$consumerDef->addMethodCall('setLogger', [$loggerDef]); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
foreach ($taggedConsumers as $id => $tags) { |
|
36
|
|
|
$consumerName = $tags[0]['consumer']; |
|
37
|
|
|
$originLogger = $id . '.logger'; |
|
38
|
|
|
|
|
39
|
|
|
if ($container->hasDefinition($originLogger)) { |
|
40
|
|
|
$consumerDef = $container->getDefinition($id); |
|
41
|
|
|
$consumerDef->removeMethodCall('setLogger'); |
|
42
|
|
|
$loggerDef = new Definition(ExtraContextLogger::class, [new Reference($originLogger), ['consumer' => $consumerName]]); |
|
43
|
|
|
$consumerDef->addMethodCall('setLogger', [$loggerDef]); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|