Failed Conditions
Push — feature/extension ( 6c86ef...6608eb )
by Yo
03:49
created

AbstractSubExtension::load()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension;
3
4
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Yoanm\Behat3SymfonyExtension\ServiceContainer\Behat3SymfonyExtension;
9
10
abstract class AbstractSubExtension implements CompilerPassInterface
11
{
12
    /**
13
     * Returns the extension config key.
14
     *
15
     * @return string|false false in case no config
16
     */
17
    public function getConfigKey()
18
    {
19
        return false;
20
    }
21
22
    /**
23
     * Setups configuration for the extension.
24
     *
25
     * @param ArrayNodeDefinition $builder
26
     */
27
    public function configure(ArrayNodeDefinition $builder)
28
    {
29
30
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
31
32
    /**
33
     * Loads extension services into temporary container.
34
     *
35
     * @param ContainerBuilder $container
36
     * @param array            $config
37
     */
38
    abstract public function load(ContainerBuilder $container, array $config);
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function process(ContainerBuilder $container)
44
    {
45
46
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
47
48
    /**
49
     * @param string $key
50
     *
51
     * @return string
52
     */
53 10
    protected function getContainerParamOrServiceId($key)
54
    {
55 10
        return sprintf(
56 10
            '%s.%s',
57 10
            Behat3SymfonyExtension::BASE_CONTAINER_ID,
58
            $key
59 10
        );
60
    }
61
62
    /**
63
     * @param ContainerBuilder $container
64
     * @param string           $id
65
     * @param string           $class
66
     * @param array            $argumentList
67
     * @param array            $tagList
68
     * @param array            $addMethodCallList
69
     */
70 7
    protected function createService(
71
        ContainerBuilder $container,
72
        $id,
73
        $class,
74
        $argumentList = array(),
75
        $tagList = array(),
76
        $addMethodCallList = array()
77
    ) {
78 7
        $definition = new Definition($class, $argumentList);
79
80 7
        foreach ($tagList as $tag) {
81 4
            $definition->addTag($tag);
82 7
        }
83
84 7
        foreach ($addMethodCallList as $methodCall) {
85 1
            $definition->addMethodCall($methodCall[0], $methodCall[1]);
86 7
        }
87
88 7
        $container->setDefinition($this->getContainerParamOrServiceId($id), $definition);
89 7
    }
90
}
91