Extension::getConfigKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Fidry\AliceBundleExtension package.
5
 *
6
 * (c) Théo FIDRY <[email protected]>
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 Fidry\AliceBundleExtension;
13
14
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
15
use Behat\Testwork\ServiceContainer\ExtensionManager;
16
use Hautelook\AliceBundle\DependencyInjection\Configuration as HautelookAliceBundleConfiguration;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21
22
/**
23
 * @author Théo FIDRY <[email protected]>
24
 */
25
class Extension implements ExtensionInterface
26
{
27
    const LIFETIME_FEATURE = 'feature';
28
    const LIFETIME_SCENARIO = 'scenario';
29
30
    /**
31
     * Returns the extension config key.
32
     *
33
     * @return string
34
     */
35
    public function getConfigKey()
36
    {
37
        return 'alice_fixtures_extension';
38
    }
39
40
    /**
41
     * Setups configuration for the extension.
42
     *
43
     * @param ArrayNodeDefinition $builder
44
     */
45
    public function configure(ArrayNodeDefinition $builder)
46
    {
47
        $builder
48
            ->children()
49
                ->scalarNode('fixtures_base_path')
50
                    ->defaultValue(null)
51
                ->end()
52
                ->arrayNode('db_drivers')
53
                    ->info('The list of enabled drivers.')
54
                    ->addDefaultsIfNotSet()
55
                    ->cannotBeOverwritten()
56
                    ->children()
57
                        ->booleanNode(HautelookAliceBundleConfiguration::ORM_DRIVER)
58
                            ->defaultValue(null)
59
                        ->end()
60
                        ->booleanNode(HautelookAliceBundleConfiguration::MONGODB_DRIVER)
61
                            ->defaultValue(null)
62
                        ->end()
63
                            ->booleanNode(HautelookAliceBundleConfiguration::PHPCR_DRIVER)
64
                                ->defaultValue(null)
65
                        ->end()
66
                    ->end()
67
                ->end()
68
                ->scalarNode('lifetime')
69
                    ->defaultValue(null)
70
                    ->validate()
71
                        ->ifNotInArray([self::LIFETIME_FEATURE, self::LIFETIME_SCENARIO, null])
72
                        ->thenInvalid('Invalid fixtures lifetime "%s"')
73
                    ->end()
74
                ->end()
75
            ->end()
76
        ;
77
    }
78
79
    /**
80
     * Loads extension services into temporary container.
81
     *
82
     * @param ContainerBuilder $container Behat container, does not contains the definitions of the Symfony application.
83
     * @param array            $config    Extension configuration.
84
     */
85
    public function load(ContainerBuilder $container, array $config)
86
    {
87
        if (null === $config['fixtures_base_path']) {
88
            $config['fixtures_base_path'] = sprintf('%s/features/fixtures', $container->getParameter('paths.base'));
89
        }
90
91
        foreach ($config as $key => $value) {
92
            $container->setParameter(sprintf('behat.%s.%s', $this->getConfigKey(), $key), $value);
93
        }
94
95
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/Resources/config'));
96
        $loader->load('services.xml');
97
    }
98
99
    /**
100
     * You can modify the container here before it is dumped to PHP code.
101
     *
102
     * @param ContainerBuilder $container
103
     *
104
     * @api
105
     */
106
    public function process(ContainerBuilder $container)
107
    {
108
    }
109
110
    /**
111
     * Initializes other extensions.
112
     *
113
     * This method is called immediately after all extensions are activated but
114
     * before any extension `configure()` method is called. This allows extensions
115
     * to hook into the configuration of other extensions providing such an
116
     * extension point.
117
     *
118
     * @param ExtensionManager $extensionManager
119
     */
120
    public function initialize(ExtensionManager $extensionManager)
121
    {
122
    }
123
}
124