1 | <?php |
||
15 | class Behat3SymfonyExtension implements Extension |
||
16 | { |
||
17 | const TEST_CLIENT_SERVICE_ID = 'behat3_symfony_extension.test.client'; |
||
18 | const KERNEL_SERVICE_ID = 'behat3_symfony_extension.kernel'; |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | 1 | public function getConfigKey() |
|
27 | |||
28 | // @codeCoverageIgnoreStart |
||
29 | /** |
||
30 | * (Not possible to cover this because ExtensionManager is a final class) |
||
31 | * |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function initialize(ExtensionManager $extensionManager) |
||
41 | // @codeCoverageIgnoreEnd |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function configure(ArrayNodeDefinition $builder) |
||
47 | { |
||
48 | $castToBool = function ($value) { |
||
49 | $filtered = filter_var( |
||
50 | $value, |
||
51 | FILTER_VALIDATE_BOOLEAN, |
||
52 | FILTER_NULL_ON_FAILURE |
||
53 | ); |
||
54 | |||
55 | return (null === $filtered) ? (bool) $value : $filtered; |
||
56 | }; |
||
57 | $builder->children() |
||
58 | ->booleanNode('debug_mode') |
||
59 | ->beforeNormalization() |
||
60 | ->always() |
||
61 | ->then($castToBool) |
||
62 | ->end() |
||
63 | ->defaultFalse() |
||
64 | ->end() |
||
65 | ->end(); |
||
66 | $builder->append((new KernelConfiguration())->getConfigTreeBuilder()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function load(ContainerBuilder $container, array $config) |
||
73 | { |
||
74 | $config = $this->normalizeConfig($config); |
||
75 | $this->bindConfigToContainer($container, $config); |
||
76 | |||
77 | $loader = new XmlFileLoader( |
||
78 | $container, |
||
79 | new FileLocator(__DIR__.'/../Resources/config') |
||
80 | ); |
||
81 | |||
82 | $loader->load('client.xml'); |
||
83 | $loader->load('kernel.xml'); |
||
84 | $loader->load('initializer.xml'); |
||
85 | if (true === $config['kernel']['reboot']) { |
||
86 | $loader->load('kernel_auto_reboot.xml'); |
||
87 | } |
||
88 | if (true === $config['kernel']['debug']) { |
||
89 | $loader->load('kernel_debug_mode.xml'); |
||
90 | |||
91 | // Override log level parameter |
||
92 | $this->checkUtilsExtensionAlreadyLoaded($container); |
||
93 | $container->setParameter('behat_utils_extension.logger.level', Logger::DEBUG); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 3 | public function process(ContainerBuilder $container) |
|
116 | |||
117 | /** |
||
118 | * @param ContainerBuilder $container |
||
119 | * @param string $path |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 3 | protected function normalizePath(ContainerBuilder $container, $path) |
|
133 | |||
134 | /** |
||
135 | * @param ContainerBuilder $container |
||
136 | * @param array $config |
||
137 | * @param string $baseId |
||
138 | */ |
||
139 | protected function bindConfigToContainer( |
||
156 | |||
157 | /** |
||
158 | * @param array $config |
||
159 | * @return array |
||
160 | */ |
||
161 | protected function normalizeConfig(array $config) |
||
169 | |||
170 | /** |
||
171 | * @param ContainerBuilder $container |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | protected function checkUtilsExtensionAlreadyLoaded(ContainerBuilder $container) |
||
180 | } |
||
181 |