ServiceContainerExtension::getConfigKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ServiceContainerExtension 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\ServiceContainerExtension\ServiceContainer;
15
16
use Behat\Testwork\ServiceContainer\Extension;
17
use Behat\Testwork\ServiceContainer\ExtensionManager;
18
use FriendsOfBehat\CrossContainerExtension\ServiceContainer\CrossContainerExtension;
19
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
20
use Symfony\Component\Config\FileLocator;
21
use Symfony\Component\Config\Loader\DelegatingLoader;
22
use Symfony\Component\Config\Loader\LoaderInterface;
23
use Symfony\Component\Config\Loader\LoaderResolver;
24
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
25
use Symfony\Component\DependencyInjection\ContainerBuilder;
26
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
27
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
28
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
29
30
/**
31
 * @internal
32
 */
33
final class ServiceContainerExtension implements Extension
34
{
35
    /**
36
     * @var CompilerPassInterface|null
37
     */
38
    private $crossContainerProcessor;
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getConfigKey(): string
44
    {
45
        return 'fob_service_container';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function initialize(ExtensionManager $extensionManager): void
52
    {
53
        /** @var CrossContainerExtension $extension */
54
        $extension = $extensionManager->getExtension('fob_cross_container');
55
56
        if (null !== $extension) {
57
            $this->crossContainerProcessor = $extension->getCrossContainerProcessor();
58
        }
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function configure(ArrayNodeDefinition $builder): void
65
    {
66
        $builder
67
            ->children()
68
                ->arrayNode('imports')
69
                    ->performNoDeepMerging()
70
                    ->prototype('scalar')->end()
71
                ->end()
72
            ->end()
73
        ;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function load(ContainerBuilder $container, array $config): void
80
    {
81
        $loader = $this->createLoader($container, $config);
82
83
        foreach ($config['imports'] as $file) {
84
            $loader->load($file);
85
        }
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function process(ContainerBuilder $container): void
92
    {
93
        if (null !== $this->crossContainerProcessor) {
94
            $this->crossContainerProcessor->process($container);
95
        }
96
    }
97
98
    private function createLoader(ContainerBuilder $container, array $config): LoaderInterface
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
    {
100
        $fileLocator = new FileLocator($container->getParameter('paths.base'));
101
102
        return new DelegatingLoader(new LoaderResolver([
103
            new XmlFileLoader($container, $fileLocator),
104
            new YamlFileLoader($container, $fileLocator),
105
            new PhpFileLoader($container, $fileLocator),
106
        ]));
107
    }
108
}
109