JobCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace SfCod\QueueBundle\DependencyInjection\Compiler;
4
5
use SfCod\QueueBundle\Base\JobResolverInterface;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Class JobCompilerPass
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\QueueBundle\DependencyInjection\Compiler
16
 */
17
class JobCompilerPass implements CompilerPassInterface
18
{
19
    /**
20
     * Find all job handlers and mark them as public in case to work properly with job queue
21
     *
22
     * @param ContainerBuilder $container
23
     */
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(JobResolverInterface::class)) {
27
            return;
28
        }
29
30
        $jobResolver = $container->getDefinition(JobResolverInterface::class);
31
        $taggedServices = $container->findTaggedServiceIds('sfcod.jobqueue.job');
32
33
        foreach ($taggedServices as $id => $tags) {
34
            $jobResolver->addMethodCall('addJob', [$id, new Reference($id)]);
35
        }
36
    }
37
}
38