CompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 18
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\Symfony\Facades\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
use function array_keys;
10
11
class CompilerPass implements CompilerPassInterface
12
{
13
    /**
14
     * @inheritDoc
15
     */
16
    public function process(ContainerBuilder $container)
17
    {
18
        if(!$container->hasDefinition('lagdo.facades.service_locator'))
19
        {
20
            return;
21
        }
22
23
        $serviceLocatorDefinition = $container->getDefinition('lagdo.facades.service_locator');
24
25
        // Append the tagged services to the service locator first argument.
26
        $locatedServices = $serviceLocatorDefinition->getArguments()[0] ?? [];
27
        $services = $container->findTaggedServiceIds('lagdo.facades.service');
28
        foreach(array_keys($services) as $service)
29
        {
30
            $locatedServices[$service] = new Reference($service);
31
        }
32
33
        $serviceLocatorDefinition->replaceArgument(0, $locatedServices);
34
    }
35
}
36