Magento2InitExtension::configure()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 27
nc 1
nop 1
1
<?php
2
3
namespace Bex\Behat\Magento2InitExtension\ServiceContainer;
4
5
use Behat\Testwork\ServiceContainer\Extension;
6
use Behat\Testwork\ServiceContainer\ExtensionManager;
7
use Bex\Behat\Magento2InitExtension\ServiceContainer\Config;
8
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
9
use Symfony\Component\Config\FileLocator;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
12
13
class Magento2InitExtension implements Extension
14
{
15
    const CONFIG_KEY = 'magento2init';
16
17
     /**
18
     * {@inheritdoc}
19
     */
20
    public function getConfigKey()
21
    {
22
        return self::CONFIG_KEY;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container)
29
    {
30
        // nothing to do here
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function initialize(ExtensionManager $extensionManager)
37
    {
38
        // nothing to do here
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function configure(ArrayNodeDefinition $builder)
45
    {
46
        $builder
47
            ->children()
48
                ->scalarNode(Config::CONFIG_KEY_MAGENTO_BOOTSTRAP_PATH)
49
                    ->defaultValue(getcwd() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'bootstrap.php')
50
                ->end()
51
                ->arrayNode(Config::CONFIG_KEY_MAGENTO_CONFIGS)
52
                    ->prototype('array')
53
                        ->children()
54
                            ->scalarNode('path')
55
                                ->isRequired()
56
                                ->cannotBeEmpty()
57
                            ->end()
58
                            ->scalarNode('value')
59
                                ->isRequired()
60
                            ->end()
61
                            ->enumNode('scope_type')
62
                                ->values(array('default', 'stores', 'websites'))
63
                                ->defaultValue('default')
64
                            ->end()
65
                            ->scalarNode('scope_code')
66
                                ->defaultValue(null)
67
                            ->end()
68
                        ->end()
69
                    ->end()
70
                ->end()
71
            ->end();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function load(ContainerBuilder $container, array $config)
78
    {
79
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
80
        $loader->load('services.xml');
81
82
        $extensionConfig = new Config($config);
83
        $container->set('bex.magento2_init_extension.config', $extensionConfig);
84
    }
85
}
86