ContainerAwareCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.2
cc 4
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace BenTools\ContainerAwareBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ContainerAwareCompilerPass implements CompilerPassInterface
10
{
11
12
    /**
13
     * @inheritDoc
14
     */
15
    public function process(ContainerBuilder $container)
16
    {
17
        foreach ($container->getServiceIds() as $serviceId) {
18
            $definition = $container->findDefinition($serviceId);
19
            $class = $definition->getClass();
20
            if (is_a($class, 'Symfony\Component\DependencyInjection\ContainerAwareInterface', true)) {
21
                if (!$definition->hasMethodCall('setContainer')) {
22
                    $definition->addMethodCall('setContainer', array(new Reference('service_container')));
23
                }
24
            }
25
        }
26
    }
27
}
28