File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace DependencyInjection ;
4+
5+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
6+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
7+ use Symfony \Component \DependencyInjection \Reference ;
8+
9+ /**
10+ * Compiler pass which collects worker services.
11+ *
12+ * @author @wachterjohannes <johannes.wachter@massiveart.com>
13+ */
14+ class WorkerCompilerPass implements CompilerPassInterface
15+ {
16+ const TASK_RUNNER_ID = 'task.runner ' ;
17+ const WORKER_TAG = 'task.worker ' ;
18+ const ADD_FUNCTION_NAME = 'addWorker ' ;
19+
20+ /**
21+ * {@inheritdoc}
22+ */
23+ public function process (ContainerBuilder $ container )
24+ {
25+ if (!$ container ->has (self ::TASK_RUNNER_ID )) {
26+ return ;
27+ }
28+
29+ $ definition = $ container ->findDefinition (self ::TASK_RUNNER_ID );
30+
31+ $ taggedServices = $ container ->findTaggedServiceIds (self ::WORKER_TAG );
32+ foreach ($ taggedServices as $ id => $ tags ) {
33+ $ definition ->addMethodCall (self ::ADD_FUNCTION_NAME , array (new Reference ($ id )));
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 22
33namespace Task \TaskBundle ;
44
5+ use DependencyInjection \WorkerCompilerPass ;
6+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
57use Symfony \Component \HttpKernel \Bundle \Bundle ;
68
79/**
1113 */
1214class TaskBundle extends Bundle
1315{
16+ public function build (ContainerBuilder $ container )
17+ {
18+ parent ::build ($ container );
19+
20+ $ container ->addCompilerPass (new WorkerCompilerPass ());
21+ }
1422
1523}
You can’t perform that action at this time.
0 commit comments