MiddlewareCompilerPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use BrainExe\Core\Application\AppKernel;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
/**
12
 * @CompilerPass
13
 */
14
class MiddlewareCompilerPass implements CompilerPassInterface
15
{
16
17
    const TAG = 'middleware';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 2
    public function process(ContainerBuilder $container)
23
    {
24 2
        $appKernel   = $container->findDefinition(AppKernel::class);
25 2
        $middlewares = $container->getParameter('application.middlewares');
26
27 2
        $references  = [];
28 2
        foreach ($middlewares as $serviceId) {
29 1
            $references[] = new Reference($serviceId);
30
        }
31
32 2
        $appKernel->addArgument($references);
33 2
        $container->getParameterBag()->remove('application.middlewares');
34 2
    }
35
}
36