Completed
Push — ezp_30827 ( c6ab75...809fcf )
by
unknown
14:52
created

SiteAccessMatcherRegistryPass::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\SiteAccess\SiteAccessMatcherRegistry;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * The SiteAccessMatcherRegistryPass will register all services tagged as "ezplatform.siteaccess.matcher" to the registry.
18
 */
19
final class SiteAccessMatcherRegistryPass implements CompilerPassInterface
20
{
21
    public const MATCHER_TAG = 'ezplatform.siteaccess.matcher';
22
23
    /**
24
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
25
     */
26
    public function process(ContainerBuilder $container): void
27
    {
28
        if (!$container->hasDefinition(SiteAccessMatcherRegistry::class)) {
29
            return;
30
        }
31
32
        $matcherServiceRegistry = $container->getDefinition(SiteAccessMatcherRegistry::class);
33
34
        foreach ($container->findTaggedServiceIds(self::MATCHER_TAG) as $id => $attributes) {
35
            $matcherServiceRegistry->addMethodCall(
36
                'setMatcher',
37
                [
38
                    $id,
39
                    new Reference($id),
40
                ]
41
            );
42
        }
43
    }
44
}
45