Completed
Pull Request — master (#311)
by Łukasz
05:40
created

ContextPass::process()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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