Completed
Push — master ( da25a8...3972c2 )
by Simonas
28:32
created

SetRouterPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 21
rs 9.0534
cc 4
eloc 12
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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 ONGR\RouterBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class SetRouterPass implements CompilerPassInterface
19
{
20
    public function process(ContainerBuilder $container)
21
    {
22
        // only replace the default router by overwriting the 'router' alias if config tells us to
23
        if ($container->hasParameter('ongr_router.enable') && $container->getParameter('ongr_router.enable')) {
24
            $container->setAlias('router', 'ongr_router.chain_router');
25
        }
26
27
        $container
28
            ->getDefinition('ongr_router.elasticsearch_route_provider')
29
            ->addMethodCall(
30
                'setManager',
31
                [new Reference($container->getParameter('ongr_router.manager'))]
32
            );
33
34
        $chainRouter = $container->getDefinition('ongr_router.chain_router');
35
        $routers = $container->getParameter('ongr_router.routers');
36
37
        foreach ($routers as $router => $priority) {
38
            $chainRouter->addMethodCall('add', [new Reference($router), $priority]);
39
        }
40
    }
41
}