ContextRegistryPass::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ContextServiceExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace FriendsOfBehat\ContextServiceExtension\ServiceContainer\Scenario;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
/**
21
 * @internal
22
 */
23
final class ContextRegistryPass implements CompilerPassInterface
24
{
25
    const CONTEXT_SERVICE_TAG = 'fob.context_service';
26
27
    /**
28
     * @var Definition
29
     */
30
    private $contextRegistryDefinition;
31
32
    /**
33
     * @param Definition $contextRegistryDefinition
34
     */
35
    public function __construct(Definition $contextRegistryDefinition)
36
    {
37
        $this->contextRegistryDefinition = $contextRegistryDefinition;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function process(ContainerBuilder $container): void
44
    {
45
        $taggedServices = $container->findTaggedServiceIds(self::CONTEXT_SERVICE_TAG);
46
47
        foreach ($taggedServices as $id => $tags) {
48
            $container->getDefinition($id)->setPublic(true);
49
50
            $this->contextRegistryDefinition->addMethodCall(
51
                'add',
52
                [$id, $container->findDefinition($id)->getClass()]
53
            );
54
        }
55
    }
56
}
57