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 | 2 | $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 | 2 | }; |
|
57 | 2 | $builder->children() |
|
58 | 2 | ->booleanNode('debug_mode') |
|
59 | 2 | ->beforeNormalization() |
|
60 | 2 | ->always() |
|
61 | 2 | ->then($castToBool) |
|
62 | 2 | ->end() |
|
63 | 2 | ->defaultFalse() |
|
64 | 2 | ->end() |
|
65 | 2 | ->end(); |
|
66 | 2 | $builder->append((new KernelConfiguration())->getConfigNode()); |
|
67 | 2 | } |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 5 | public function load(ContainerBuilder $container, array $config) |
|
73 | { |
||
74 | 5 | $config = $this->normalizeConfig($config); |
|
75 | 5 | $this->bindConfigToContainer($container, $config); |
|
76 | |||
77 | 5 | $loader = new XmlFileLoader( |
|
78 | 5 | $container, |
|
79 | 5 | new FileLocator(__DIR__.'/../Resources/config') |
|
80 | 5 | ); |
|
81 | |||
82 | 5 | $loader->load('client.xml'); |
|
83 | 5 | $loader->load('kernel.xml'); |
|
84 | 5 | $loader->load('initializer.xml'); |
|
85 | 5 | if (true === $config['kernel']['reboot']) { |
|
86 | 5 | $loader->load('kernel_auto_reboot.xml'); |
|
87 | 5 | } |
|
88 | 5 | if (true === $config['kernel']['debug']) { |
|
89 | 5 | $loader->load('kernel_debug_mode.xml'); |
|
90 | |||
91 | // Override log level parameter |
||
92 | 5 | $this->checkUtilsExtensionAlreadyLoaded($container); |
|
93 | 5 | $container->setParameter('behat_utils_extension.logger.level', Logger::DEBUG); |
|
94 | 5 | } |
|
95 | 5 | } |
|
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function process(ContainerBuilder $container) |
||
101 | { |
||
102 | $bootstrapPath = $container->getParameter('behat3_symfony_extension.kernel.bootstrap'); |
||
103 | if ($bootstrapPath) { |
||
104 | require_once($this->normalizePath($container, $bootstrapPath)); |
||
105 | } |
||
106 | |||
107 | // load kernel |
||
108 | $container->getDefinition(self::KERNEL_SERVICE_ID) |
||
109 | ->setFile( |
||
110 | $this->normalizePath( |
||
111 | $container, |
||
112 | $container->getParameter('behat3_symfony_extension.kernel.path') |
||
113 | ) |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param ContainerBuilder $container |
||
119 | * @param string $path |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function normalizePath(ContainerBuilder $container, $path) |
||
124 | { |
||
125 | $basePath = $container->getParameter('paths.base'); |
||
126 | $pathUnderBasePath = sprintf('%s/%s', $basePath, $path); |
||
127 | if (file_exists($pathUnderBasePath)) { |
||
128 | $path = $pathUnderBasePath; |
||
129 | } |
||
130 | |||
131 | return $path; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @param ContainerBuilder $container |
||
136 | * @param array $config |
||
137 | * @param string $baseId |
||
138 | */ |
||
139 | 5 | protected function bindConfigToContainer( |
|
156 | |||
157 | /** |
||
158 | * @param array $config |
||
159 | * @return array |
||
160 | */ |
||
161 | 5 | protected function normalizeConfig(array $config) |
|
169 | |||
170 | /** |
||
171 | * @param ContainerBuilder $container |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | 5 | protected function checkUtilsExtensionAlreadyLoaded(ContainerBuilder $container) |
|
180 | } |
||
181 |