-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathAsyncEventsPass.php
62 lines (51 loc) · 2.16 KB
/
AsyncEventsPass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Enqueue\Bundle\Events\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
class AsyncEventsPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (false == $container->hasDefinition('enqueue.events.async_listener')) {
return;
}
if (false == $container->hasDefinition('enqueue.events.registry')) {
return;
}
$registeredToEvent = [];
foreach ($container->findTaggedServiceIds('kernel.event_listener') as $serviceId => $tagAttributes) {
foreach ($tagAttributes as $tagAttribute) {
if (false == isset($tagAttribute['async'])) {
continue;
}
$service = $container->getDefinition($serviceId);
$service->clearTag('kernel.event_listener');
$service->addTag('enqueue.async_event_listener', $tagAttribute);
if (false == isset($registeredToEvent[$tagAttribute['event']])) {
$container->getDefinition('enqueue.events.async_listener')
->addTag('kernel.event_listener', [
'event' => $tagAttribute['event'],
'method' => 'onEvent',
])
;
$container->getDefinition('enqueue.events.async_processor')
->addTag('enqueue.client.processor', [
'topicName' => 'event.'.$tagAttribute['event'],
])
;
$registeredToEvent[$tagAttribute['event']] = true;
}
}
}
$registerListenersPass = new RegisterListenersPass(
'enqueue.events.event_dispatcher',
'enqueue.async_event_listener',
'enqueue.async_event_subscriber'
);
$registerListenersPass->process($container);
}
}