CompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 3
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