TaggedServicesCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
namespace Kaliop\eZObjectWrapperBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class TaggedServicesCompilerPass implements CompilerPassInterface
10
{
11
    protected $entityManagerService = 'ezobject_wrapper.entity_manager';
12
13
    public function process(ContainerBuilder $container)
14
    {
15
        if (!$container->hasDefinition($this->entityManagerService)) {
16
            return;
17
        }
18
        $definition = $container->getDefinition($this->entityManagerService);
19
        $taggedServices = $container->findTaggedServiceIds('ezobject_wrapper.repository');
20
        foreach ($taggedServices as $id => $tags) {
21
            foreach ($tags as $attributes) {
22
                /// @todo validate the keys in $attributes, for courtesy to users
23
                $definition->addMethodCall(
24
                    'registerService',
25
                    array(new Reference($id), @$attributes["content_type"])
26
                );
27
            }
28
        }
29
    }
30
}
31