Completed
Pull Request — master (#3)
by Kamil
02:07
created

ServiceContainerExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the ServiceContainerExtension package.
5
 *
6
 * (c) FriendsOfBehat
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FriendsOfBehat\ServiceContainerExtension\ServiceContainer;
13
14
use Behat\Testwork\ServiceContainer\Extension;
15
use Behat\Testwork\ServiceContainer\ExtensionManager;
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\FileLocator;
18
use Symfony\Component\Config\Loader\DelegatingLoader;
19
use Symfony\Component\Config\Loader\LoaderInterface;
20
use Symfony\Component\Config\Loader\LoaderResolver;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
23
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
24
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
25
26
/**
27
 * @author Kamil Kokot <[email protected]>
28
 */
29
final class ServiceContainerExtension implements Extension
30
{
31
    /**
32
     * @var callable<ContainerBuilder, array>:LoaderInterface
33
     */
34
    private $loaderCallable;
35
36
    public function __construct()
37
    {
38
        $this->loaderCallable = function (ContainerBuilder $container, array $config) {
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...
39
            $fileLocator = new FileLocator($container->getParameter('paths.base'));
40
41
            return new DelegatingLoader(new LoaderResolver([
42
                new XmlFileLoader($container, $fileLocator),
43
                new YamlFileLoader($container, $fileLocator),
44
                new PhpFileLoader($container, $fileLocator),
45
            ]));
46
        };
47
    }
48
49
    /**
50
     * @api
51
     *
52
     * @param callable<ContainerBuilder, array>:LoaderInterface $loaderCallable
53
     */
54
    public function setLoaderCallable(callable $loaderCallable)
55
    {
56
        $this->loaderCallable = $loaderCallable;
57
    }
58
59
    /**
60
     * @internal
61
     *
62
     * {@inheritdoc}
63
     */
64
    public function getConfigKey()
65
    {
66
        return 'fob_service_container';
67
    }
68
69
    /**
70
     * @internal
71
     *
72
     * {@inheritdoc}
73
     */
74
    public function initialize(ExtensionManager $extensionManager)
75
    {
76
77
    }
78
79
    /**
80
     * @internal
81
     *
82
     * {@inheritdoc}
83
     */
84
    public function configure(ArrayNodeDefinition $builder)
85
    {
86
        $builder
87
            ->children()
88
                ->arrayNode('imports')
89
                    ->performNoDeepMerging()
90
                    ->prototype('scalar')
91
        ;
92
    }
93
94
    /**
95
     * @internal
96
     *
97
     * {@inheritdoc}
98
     */
99
    public function load(ContainerBuilder $container, array $config)
100
    {
101
        $loaderCallable = $this->loaderCallable;
102
103
        /** @var LoaderInterface $loader */
104
        $loader = $loaderCallable($container, $config);
105
106
        foreach ($config['imports'] as $file) {
107
            $loader->load($file);
108
        }
109
    }
110
111
    /**
112
     * @internal
113
     *
114
     * {@inheritdoc}
115
     */
116
    public function process(ContainerBuilder $container)
117
    {
118
119
    }
120
}
121