Completed
Pull Request — master (#14)
by Jacob
02:21
created

EventSubscribersPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace As3\Bundle\ModlrBundle\DependencyInjection\Compiler;
4
5
use As3\Bundle\ModlrBundle\DependencyInjection\Utility;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Adds event subscribers to the event dispatcher.
12
 *
13
 * @author  Jacob Bare <[email protected]>
14
 */
15
class EventSubscribersPass implements CompilerPassInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function process(ContainerBuilder $container)
21
    {
22
        $dispatcher = $container->getDefinition(Utility::getAliasedName('event_dispatcher'));
23
24
        $tagged = $container->findTaggedServiceIds(Utility::getAliasedName('event_subscriber'));
25
        foreach ($tagged as $id => $tags) {
26
            $dispatcher->addMethodCall('addSubscriber', [new Reference($id)]);
27
        }
28
    }
29
}
30