Completed
Pull Request — master (#90)
by Arnaud
02:08
created

ActionCompilerPass::process()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 16
nc 5
nop 1
crap 4
1
<?php
2
3
namespace LAG\AdminBundle\DependencyInjection\CompilerPass;
4
5
use LAG\AdminBundle\LAGAdminBundle;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class ActionCompilerPass implements CompilerPassInterface
11
{
12
    /**
13
     * @param ContainerBuilder $builder
14
     */
15 2
    public function process(ContainerBuilder $builder)
16
    {
17 2
        if (!$builder->hasDefinition(LAGAdminBundle::SERVICE_ID_ACTION_REGISTRY)) {
18 1
            //die('pas service');
19
            return;
20 1
        }
21 1
        $actionRegistry = $builder->getDefinition(LAGAdminBundle::SERVICE_ID_ACTION_REGISTRY);
22
        $defaultActions = LAGAdminBundle::getDefaultActionServiceMapping();
23
    
24
        foreach ($defaultActions as $id) {
25 1
            $actionRegistry
26
                ->addMethodCall('add', [
27 1
                        $id,
28 1
                        new Reference($id),
29 1
                    ]
30
                );
31
        }
32
        $actions = $builder->findTaggedServiceIds(LAGAdminBundle::SERVICE_TAG_ACTION);
33 1
        
34
        foreach ($actions as $id => $attributes) {
35
            $actionRegistry
36
                ->addMethodCall('add', [
37
                    $id,
38
                    new Reference($id),
39
                ]
40
            );
41
        }
42
    }
43
}
44