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