Completed
Pull Request — master (#244)
by Łukasz
11:47
created

ContextPass::process()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 7
nop 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminBundle\DependencyInjection\Compiler;
11
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
15
/**
16
 * @author Norbert Orzechowicz <[email protected]>
17
 */
18
class ContextPass implements CompilerPassInterface
19
{
20
    /**
21
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
22
     */
23
    public function process(ContainerBuilder $container)
24
    {
25
        if (!$container->hasDefinition('admin.context.manager')) {
26
            return;
27
        }
28
29
        $contexts = array();
30
        foreach ($container->findTaggedServiceIds('admin.context') as $id => $tags) {
31
            $priority = isset($tags[0]['priority']) ? $tags[0]['priority'] : 0;
32
            $contexts[$priority][] = $container->findDefinition($id);
33
        }
34
35
        if (empty($contexts)) {
36
            return;
37
        }
38
        krsort($contexts);
39
        $contexts = call_user_func_array('array_merge', $contexts);
40
41
        $container->findDefinition('admin.context.manager')->replaceArgument(0, $contexts);
42
    }
43
}
44