Completed
Push — master ( ca8025...177d87 )
by Łukasz
14:26
created

ViewMatcherRegistryPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
10
11
use eZ\Bundle\EzPublishCoreBundle\Matcher\ViewMatcherRegistry;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * The MatcherServiceRegistryPass will register all services tagged as "ezplatform.view.matcher" to the registry.
18
 */
19
final class ViewMatcherRegistryPass implements CompilerPassInterface
20
{
21
    public const MATCHER_TAG = 'ezplatform.view.matcher';
22
23
    public function process(ContainerBuilder $container): void
24
    {
25
        if (!$container->hasDefinition(ViewMatcherRegistry::class)) {
26
            return;
27
        }
28
29
        $matcherServiceRegistry = $container->getDefinition(ViewMatcherRegistry::class);
30
31
        foreach ($container->findTaggedServiceIds(self::MATCHER_TAG) as $id => $attributes) {
32
            $matcherServiceRegistry->addMethodCall(
33
                'setMatcher',
34
                [
35
                    $id,
36
                    new Reference($id),
37
                ]
38
            );
39
        }
40
    }
41
}
42