Complex classes like Configuration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Configuration, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class Configuration implements ConfigurationInterface |
||
33 | { |
||
34 | /** |
||
35 | * Whether to use the debug mode. |
||
36 | * |
||
37 | * @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41 |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $debug; |
||
42 | |||
43 | /** |
||
44 | * @param bool $debug |
||
45 | */ |
||
46 | 50 | public function __construct($debug) |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 50 | public function getConfigTreeBuilder() |
|
55 | { |
||
56 | 50 | $treeBuilder = new TreeBuilder('httplug'); |
|
57 | // Keep compatibility with symfony/config < 4.2 |
||
58 | 50 | if (!method_exists($treeBuilder, 'getRootNode')) { |
|
59 | $rootNode = $treeBuilder->root('httplug'); |
||
|
|||
60 | } else { |
||
61 | 50 | $rootNode = $treeBuilder->getRootNode(); |
|
62 | } |
||
63 | |||
64 | 50 | $this->configureClients($rootNode); |
|
65 | 50 | $this->configureSharedPlugins($rootNode); |
|
66 | |||
67 | $rootNode |
||
68 | 50 | ->validate() |
|
69 | ->ifTrue(function ($v) { |
||
70 | 43 | return !empty($v['classes']['client']) |
|
71 | 40 | || !empty($v['classes']['message_factory']) |
|
72 | 40 | || !empty($v['classes']['uri_factory']) |
|
73 | 43 | || !empty($v['classes']['stream_factory']); |
|
74 | 50 | }) |
|
75 | ->then(function ($v) { |
||
76 | 3 | foreach ($v['classes'] as $key => $class) { |
|
77 | 3 | if (null !== $class && !class_exists($class)) { |
|
78 | 1 | throw new InvalidConfigurationException(sprintf( |
|
79 | 1 | 'Class %s specified for httplug.classes.%s does not exist.', |
|
80 | $class, |
||
81 | $key |
||
82 | )); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | 2 | return $v; |
|
87 | 50 | }) |
|
88 | 50 | ->end() |
|
89 | 50 | ->beforeNormalization() |
|
90 | ->ifTrue(function ($v) { |
||
91 | 50 | return is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']); |
|
92 | 50 | }) |
|
93 | ->then(function ($v) { |
||
94 | 4 | if (array_key_exists('profiling', $v)) { |
|
95 | 1 | throw new InvalidConfigurationException('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".'); |
|
96 | } |
||
97 | |||
98 | 3 | @trigger_error('"httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use "httplug.profiling" instead.', E_USER_DEPRECATED); |
|
99 | |||
100 | 3 | if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) { |
|
101 | 1 | @trigger_error('"auto" value in "httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use a boolean value instead.', E_USER_DEPRECATED); |
|
102 | 1 | $v['toolbar']['enabled'] = $this->debug; |
|
103 | } |
||
104 | |||
105 | 3 | $v['profiling'] = $v['toolbar']; |
|
106 | |||
107 | 3 | unset($v['toolbar']); |
|
108 | |||
109 | 3 | return $v; |
|
110 | 50 | }) |
|
111 | 50 | ->end() |
|
112 | 50 | ->fixXmlConfig('client') |
|
113 | 50 | ->children() |
|
114 | 50 | ->booleanNode('default_client_autowiring') |
|
115 | 50 | ->defaultTrue() |
|
116 | 50 | ->info('Set to false to not autowire HttpClient and HttpAsyncClient.') |
|
117 | 50 | ->end() |
|
118 | 50 | ->arrayNode('main_alias') |
|
119 | 50 | ->addDefaultsIfNotSet() |
|
120 | 50 | ->info('Configure which service the main alias point to.') |
|
121 | 50 | ->children() |
|
122 | 50 | ->scalarNode('client')->defaultValue('httplug.client.default')->end() |
|
123 | 50 | ->scalarNode('message_factory')->defaultValue('httplug.message_factory.default')->end() |
|
124 | 50 | ->scalarNode('uri_factory')->defaultValue('httplug.uri_factory.default')->end() |
|
125 | 50 | ->scalarNode('stream_factory')->defaultValue('httplug.stream_factory.default')->end() |
|
126 | 50 | ->end() |
|
127 | 50 | ->end() |
|
128 | 50 | ->arrayNode('classes') |
|
129 | 50 | ->addDefaultsIfNotSet() |
|
130 | 50 | ->info('Overwrite a service class instead of using the discovery mechanism.') |
|
131 | 50 | ->children() |
|
132 | 50 | ->scalarNode('client')->defaultNull()->end() |
|
133 | 50 | ->scalarNode('message_factory')->defaultNull()->end() |
|
134 | 50 | ->scalarNode('uri_factory')->defaultNull()->end() |
|
135 | 50 | ->scalarNode('stream_factory')->defaultNull()->end() |
|
136 | 50 | ->end() |
|
137 | 50 | ->end() |
|
138 | 50 | ->arrayNode('profiling') |
|
139 | 50 | ->addDefaultsIfNotSet() |
|
140 | 50 | ->treatFalseLike(['enabled' => false]) |
|
141 | 50 | ->treatTrueLike(['enabled' => true]) |
|
142 | 50 | ->treatNullLike(['enabled' => $this->debug]) |
|
143 | 50 | ->info('Extend the debug profiler with information about requests.') |
|
144 | 50 | ->children() |
|
145 | 50 | ->booleanNode('enabled') |
|
146 | 50 | ->info('Turn the toolbar on or off. Defaults to kernel debug mode.') |
|
147 | 50 | ->defaultValue($this->debug) |
|
148 | 50 | ->end() |
|
149 | 50 | ->scalarNode('formatter')->defaultNull()->end() |
|
150 | 50 | ->scalarNode('captured_body_length') |
|
151 | 50 | ->validate() |
|
152 | ->ifTrue(function ($v) { |
||
153 | 4 | return null !== $v && !is_int($v); |
|
154 | 50 | }) |
|
155 | 50 | ->thenInvalid('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null ("%s" given).') |
|
156 | 50 | ->end() |
|
157 | 50 | ->defaultValue(0) |
|
158 | 50 | ->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. If null the body will not be truncated. Only available with the default formatter (FullHttpMessageFormatter).') |
|
159 | 50 | ->end() |
|
160 | 50 | ->end() |
|
161 | 50 | ->end() |
|
162 | 50 | ->arrayNode('discovery') |
|
163 | 50 | ->addDefaultsIfNotSet() |
|
164 | 50 | ->info('Control what clients should be found by the discovery.') |
|
165 | 50 | ->children() |
|
166 | 50 | ->scalarNode('client') |
|
167 | 50 | ->defaultValue('auto') |
|
168 | 50 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
169 | 50 | ->end() |
|
170 | 50 | ->scalarNode('async_client') |
|
171 | 50 | ->defaultNull() |
|
172 | 50 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
173 | 50 | ->end() |
|
174 | 50 | ->end() |
|
175 | 50 | ->end() |
|
176 | 50 | ->end(); |
|
177 | |||
178 | 50 | return $treeBuilder; |
|
179 | } |
||
180 | |||
181 | 50 | private function configureClients(ArrayNodeDefinition $root) |
|
182 | { |
||
183 | 50 | $root->children() |
|
184 | 50 | ->arrayNode('clients') |
|
185 | 50 | ->useAttributeAsKey('name') |
|
186 | 50 | ->prototype('array') |
|
187 | 50 | ->fixXmlConfig('plugin') |
|
188 | 50 | ->validate() |
|
189 | ->ifTrue(function ($config) { |
||
190 | // Make sure we only allow one of these to be true |
||
191 | 27 | return (bool) $config['flexible_client'] + (bool) $config['http_methods_client'] + (bool) $config['batch_client'] >= 2; |
|
192 | 50 | }) |
|
193 | 50 | ->thenInvalid('A http client can\'t be decorated with several of FlexibleHttpClient, HttpMethodsClient and BatchClient. Only one of the following options can be true. ("flexible_client", "http_methods_client", "batch_client")') |
|
194 | 50 | ->end() |
|
195 | 50 | ->validate() |
|
196 | ->ifTrue(function ($config) { |
||
197 | 27 | return 'httplug.factory.auto' === $config['factory'] && !empty($config['config']); |
|
198 | 50 | }) |
|
199 | 50 | ->thenInvalid('If you want to use the "config" key you must also specify a valid "factory".') |
|
200 | 50 | ->end() |
|
201 | 50 | ->validate() |
|
202 | ->ifTrue(function ($config) { |
||
203 | 27 | return !empty($config['service']) && ('httplug.factory.auto' !== $config['factory'] || !empty($config['config'])); |
|
204 | 50 | }) |
|
205 | 50 | ->thenInvalid('If you want to use the "service" key you cannot specify "factory" or "config".') |
|
206 | 50 | ->end() |
|
207 | 50 | ->children() |
|
208 | 50 | ->scalarNode('factory') |
|
209 | 50 | ->defaultValue('httplug.factory.auto') |
|
210 | 50 | ->cannotBeEmpty() |
|
211 | 50 | ->info('The service id of a factory to use when creating the adapter.') |
|
212 | 50 | ->end() |
|
213 | 50 | ->scalarNode('service') |
|
214 | 50 | ->defaultNull() |
|
215 | 50 | ->info('The service id of the client to use.') |
|
216 | 50 | ->end() |
|
217 | 50 | ->booleanNode('public') |
|
218 | 50 | ->defaultNull() |
|
219 | 50 | ->info('Set to true if you really cannot use dependency injection and need to make the client service public.') |
|
220 | 50 | ->end() |
|
221 | 50 | ->booleanNode('flexible_client') |
|
222 | 50 | ->defaultFalse() |
|
223 | 50 | ->info('Set to true to get the client wrapped in a FlexibleHttpClient which emulates async or sync behavior.') |
|
224 | 50 | ->end() |
|
225 | 50 | ->booleanNode('http_methods_client') |
|
226 | 50 | ->defaultFalse() |
|
227 | 50 | ->info('Set to true to get the client wrapped in a HttpMethodsClient which emulates provides functions for HTTP verbs.') |
|
228 | 50 | ->end() |
|
229 | 50 | ->booleanNode('batch_client') |
|
230 | 50 | ->defaultFalse() |
|
231 | 50 | ->info('Set to true to get the client wrapped in a BatchClient which allows you to send multiple request at the same time.') |
|
232 | 50 | ->end() |
|
233 | 50 | ->variableNode('config')->defaultValue([])->end() |
|
234 | 50 | ->append($this->createClientPluginNode()) |
|
235 | 50 | ->end() |
|
236 | 50 | ->end() |
|
237 | 50 | ->end(); |
|
238 | 50 | } |
|
239 | |||
240 | /** |
||
241 | * @param ArrayNodeDefinition $root |
||
242 | */ |
||
243 | 50 | private function configureSharedPlugins(ArrayNodeDefinition $root) |
|
254 | |||
255 | /** |
||
256 | * Createplugins node of a client. |
||
257 | * |
||
258 | * @return ArrayNodeDefinition The plugin node |
||
259 | */ |
||
260 | 50 | private function createClientPluginNode() |
|
261 | { |
||
262 | 50 | $treeBuilder = new TreeBuilder('plugins'); |
|
263 | // Keep compatibility with symfony/config < 4.2 |
||
264 | 50 | if (!method_exists($treeBuilder, 'getRootNode')) { |
|
265 | $node = $treeBuilder->root('plugins'); |
||
266 | } else { |
||
267 | 50 | $node = $treeBuilder->getRootNode(); |
|
268 | } |
||
269 | |||
270 | /** @var ArrayNodeDefinition $pluginList */ |
||
271 | $pluginList = $node |
||
272 | 50 | ->info('A list of plugin service ids and client specific plugin definitions. The order is important.') |
|
273 | 50 | ->prototype('array') |
|
274 | ; |
||
275 | $pluginList |
||
276 | // support having just a service id in the list |
||
277 | 50 | ->beforeNormalization() |
|
278 | ->always(function ($plugin) { |
||
279 | 18 | if (is_string($plugin)) { |
|
280 | return [ |
||
281 | 'reference' => [ |
||
282 | 10 | 'enabled' => true, |
|
283 | 10 | 'id' => $plugin, |
|
284 | ], |
||
285 | ]; |
||
286 | } |
||
287 | |||
288 | 15 | return $plugin; |
|
289 | 50 | }) |
|
290 | 50 | ->end() |
|
291 | |||
292 | 50 | ->validate() |
|
293 | ->always(function ($plugins) { |
||
294 | 16 | foreach ($plugins as $name => $definition) { |
|
295 | 16 | if ('authentication' === $name) { |
|
296 | 16 | if (!count($definition)) { |
|
297 | 16 | unset($plugins['authentication']); |
|
298 | } |
||
299 | 16 | } elseif (!$definition['enabled']) { |
|
300 | 16 | unset($plugins[$name]); |
|
301 | } |
||
302 | } |
||
303 | |||
304 | 16 | return $plugins; |
|
305 | 50 | }) |
|
306 | 50 | ->end() |
|
307 | ; |
||
308 | 50 | $this->addSharedPluginNodes($pluginList, true); |
|
309 | |||
310 | $pluginList |
||
311 | 50 | ->children() |
|
312 | 50 | ->arrayNode('reference') |
|
313 | 50 | ->canBeEnabled() |
|
314 | 50 | ->info('Reference to a plugin service') |
|
315 | 50 | ->children() |
|
316 | 50 | ->scalarNode('id') |
|
317 | 50 | ->info('Service id of a plugin') |
|
318 | 50 | ->isRequired() |
|
319 | 50 | ->cannotBeEmpty() |
|
320 | 50 | ->end() |
|
321 | 50 | ->end() |
|
322 | 50 | ->end() |
|
323 | 50 | ->arrayNode('add_host') |
|
324 | 50 | ->canBeEnabled() |
|
325 | 50 | ->addDefaultsIfNotSet() |
|
326 | 50 | ->info('Set scheme, host and port in the request URI.') |
|
327 | 50 | ->children() |
|
328 | 50 | ->scalarNode('host') |
|
329 | 50 | ->info('Host name including protocol and optionally the port number, e.g. https://api.local:8000') |
|
330 | 50 | ->isRequired() |
|
331 | 50 | ->cannotBeEmpty() |
|
332 | 50 | ->end() |
|
333 | 50 | ->scalarNode('replace') |
|
334 | 50 | ->info('Whether to replace the host if request already specifies one') |
|
335 | 50 | ->defaultValue(false) |
|
336 | 50 | ->end() |
|
337 | 50 | ->end() |
|
338 | 50 | ->end() |
|
339 | 50 | ->arrayNode('add_path') |
|
340 | 50 | ->canBeEnabled() |
|
341 | 50 | ->addDefaultsIfNotSet() |
|
342 | 50 | ->info('Add a base path to the request.') |
|
343 | 50 | ->children() |
|
344 | 50 | ->scalarNode('path') |
|
345 | 50 | ->info('Path to be added, e.g. /api/v1') |
|
346 | 50 | ->isRequired() |
|
347 | 50 | ->cannotBeEmpty() |
|
348 | 50 | ->end() |
|
349 | 50 | ->end() |
|
350 | 50 | ->end() |
|
351 | 50 | ->arrayNode('base_uri') |
|
352 | 50 | ->canBeEnabled() |
|
353 | 50 | ->addDefaultsIfNotSet() |
|
354 | 50 | ->info('Set a base URI to the request.') |
|
355 | 50 | ->children() |
|
356 | 50 | ->scalarNode('uri') |
|
357 | 50 | ->info('Base Uri including protocol, optionally the port number and prepend path, e.g. https://api.local:8000/api') |
|
358 | 50 | ->isRequired() |
|
359 | 50 | ->cannotBeEmpty() |
|
360 | 50 | ->end() |
|
361 | 50 | ->scalarNode('replace') |
|
362 | 50 | ->info('Whether to replace the host if request already specifies one') |
|
363 | 50 | ->defaultValue(false) |
|
364 | 50 | ->end() |
|
365 | 50 | ->end() |
|
366 | 50 | ->end() |
|
367 | 50 | ->arrayNode('content_type') |
|
368 | 50 | ->canBeEnabled() |
|
369 | 50 | ->info('Detect the content type of a request body and set the Content-Type header if it is not already set.') |
|
370 | 50 | ->children() |
|
371 | 50 | ->booleanNode('skip_detection') |
|
372 | 50 | ->info('Whether to skip detection when request body is larger than size_limit') |
|
373 | 50 | ->defaultFalse() |
|
374 | 50 | ->end() |
|
375 | 50 | ->scalarNode('size_limit') |
|
376 | 50 | ->info('Skip content type detection if request body is larger than size_limit bytes') |
|
377 | 50 | ->end() |
|
378 | 50 | ->end() |
|
379 | 50 | ->end() |
|
380 | 50 | ->arrayNode('header_append') |
|
381 | 50 | ->canBeEnabled() |
|
382 | 50 | ->info('Append headers to the request. If the header already exists the value will be appended to the current value.') |
|
383 | 50 | ->fixXmlConfig('header') |
|
384 | 50 | ->children() |
|
385 | 50 | ->arrayNode('headers') |
|
386 | 50 | ->info('Keys are the header names, values the header values') |
|
387 | 50 | ->normalizeKeys(false) |
|
388 | 50 | ->useAttributeAsKey('name') |
|
389 | 50 | ->prototype('scalar')->end() |
|
390 | 50 | ->end() |
|
391 | 50 | ->end() |
|
392 | 50 | ->end() |
|
393 | 50 | ->arrayNode('header_defaults') |
|
394 | 50 | ->canBeEnabled() |
|
395 | 50 | ->info('Set header to default value if it does not exist.') |
|
396 | 50 | ->fixXmlConfig('header') |
|
397 | 50 | ->children() |
|
398 | 50 | ->arrayNode('headers') |
|
399 | 50 | ->info('Keys are the header names, values the header values') |
|
400 | 50 | ->normalizeKeys(false) |
|
401 | 50 | ->useAttributeAsKey('name') |
|
402 | 50 | ->prototype('scalar')->end() |
|
403 | 50 | ->end() |
|
404 | 50 | ->end() |
|
405 | 50 | ->end() |
|
406 | 50 | ->arrayNode('header_set') |
|
407 | 50 | ->canBeEnabled() |
|
408 | 50 | ->info('Set headers to requests. If the header does not exist it wil be set, if the header already exists it will be replaced.') |
|
409 | 50 | ->fixXmlConfig('header') |
|
410 | 50 | ->children() |
|
411 | 50 | ->arrayNode('headers') |
|
412 | 50 | ->info('Keys are the header names, values the header values') |
|
413 | 50 | ->normalizeKeys(false) |
|
414 | 50 | ->useAttributeAsKey('name') |
|
415 | 50 | ->prototype('scalar')->end() |
|
416 | 50 | ->end() |
|
417 | 50 | ->end() |
|
418 | 50 | ->end() |
|
419 | 50 | ->arrayNode('header_remove') |
|
420 | 50 | ->canBeEnabled() |
|
421 | 50 | ->info('Remove headers from requests.') |
|
422 | 50 | ->fixXmlConfig('header') |
|
423 | 50 | ->children() |
|
424 | 50 | ->arrayNode('headers') |
|
425 | 50 | ->info('List of header names to remove') |
|
426 | 50 | ->prototype('scalar')->end() |
|
427 | 50 | ->end() |
|
428 | 50 | ->end() |
|
429 | 50 | ->end() |
|
430 | 50 | ->arrayNode('query_defaults') |
|
431 | 50 | ->canBeEnabled() |
|
432 | 50 | ->info('Sets query parameters to default value if they are not present in the request.') |
|
433 | 50 | ->fixXmlConfig('parameter') |
|
434 | 50 | ->children() |
|
435 | 50 | ->arrayNode('parameters') |
|
436 | 50 | ->info('List of query parameters. Names and values must not be url encoded as the plugin will encode them.') |
|
437 | 50 | ->normalizeKeys(false) |
|
438 | 50 | ->useAttributeAsKey('name') |
|
439 | 50 | ->prototype('scalar')->end() |
|
440 | 50 | ->end() |
|
441 | 50 | ->end() |
|
442 | 50 | ->end() |
|
443 | 50 | ->arrayNode('vcr') |
|
444 | 50 | ->canBeEnabled() |
|
445 | 50 | ->addDefaultsIfNotSet() |
|
446 | 50 | ->info('Record response to be replayed during tests or development cycle.') |
|
447 | 50 | ->validate() |
|
448 | ->ifTrue(function ($config) { |
||
449 | 5 | return 'filesystem' === $config['recorder'] && empty($config['fixtures_directory']); |
|
450 | 50 | }) |
|
451 | 50 | ->thenInvalid('If you want to use the "filesystem" recorder you must also specify a "fixtures_directory".') |
|
452 | 50 | ->end() |
|
453 | 50 | ->children() |
|
454 | 50 | ->enumNode('mode') |
|
455 | 50 | ->info('What should be the behavior of the plugin?') |
|
456 | 50 | ->values(['record', 'replay', 'replay_or_record']) |
|
457 | 50 | ->isRequired() |
|
458 | 50 | ->cannotBeEmpty() |
|
459 | 50 | ->end() |
|
460 | 50 | ->scalarNode('recorder') |
|
461 | 50 | ->info(sprintf('Which recorder to use. Can be "in_memory", "filesystem" or the ID of your service implementing %s and %s. When using filesystem, specify "fixtures_directory" as well.', RecorderInterface::class, PlayerInterface::class)) |
|
462 | 50 | ->defaultValue('filesystem') |
|
463 | 50 | ->cannotBeEmpty() |
|
464 | 50 | ->end() |
|
465 | 50 | ->scalarNode('naming_strategy') |
|
466 | 50 | ->info(sprintf('Which naming strategy to use. Add the ID of your service implementing %s to override the default one.', NamingStrategyInterface::class)) |
|
467 | 50 | ->defaultValue('default') |
|
468 | 50 | ->cannotBeEmpty() |
|
469 | 50 | ->end() |
|
470 | 50 | ->arrayNode('naming_strategy_options') |
|
471 | 50 | ->info('See http://docs.php-http.org/en/latest/plugins/vcr.html#the-naming-strategy for more details') |
|
472 | 50 | ->children() |
|
473 | 50 | ->arrayNode('hash_headers') |
|
474 | 50 | ->info('List of header(s) that make the request unique (Ex: ‘Authorization’)') |
|
475 | 50 | ->prototype('scalar')->end() |
|
476 | 50 | ->end() |
|
477 | 50 | ->arrayNode('hash_body_methods') |
|
478 | 50 | ->info('for which request methods the body makes requests distinct.') |
|
479 | 50 | ->prototype('scalar')->end() |
|
480 | 50 | ->end() |
|
481 | 50 | ->end() |
|
482 | 50 | ->end() // End naming_strategy_options |
|
483 | 50 | ->scalarNode('fixtures_directory') |
|
484 | 50 | ->info('Where the responses will be stored and replay from when using the filesystem recorder. Should be accessible to your VCS.') |
|
485 | 50 | ->end() |
|
486 | 50 | ->end() |
|
487 | 50 | ->end() |
|
488 | 50 | ->end(); |
|
489 | |||
490 | 50 | return $node; |
|
491 | } |
||
492 | |||
493 | /** |
||
494 | * Add the definitions for shared plugin configurations. |
||
495 | * |
||
496 | * @param ArrayNodeDefinition $pluginNode the node to add to |
||
497 | * @param bool $disableAll Some shared plugins are enabled by default. On the client, all are disabled by default. |
||
498 | */ |
||
499 | 50 | private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableAll = false) |
|
590 | |||
591 | /** |
||
592 | * Create configuration for authentication plugin. |
||
593 | * |
||
594 | * @return NodeDefinition definition for the authentication node in the plugins list |
||
595 | */ |
||
596 | 50 | private function createAuthenticationPluginNode() |
|
597 | { |
||
598 | 50 | $treeBuilder = new TreeBuilder('authentication'); |
|
599 | // Keep compatibility with symfony/config < 4.2 |
||
600 | 50 | if (!method_exists($treeBuilder, 'getRootNode')) { |
|
601 | $node = $treeBuilder->root('authentication'); |
||
602 | } else { |
||
603 | 50 | $node = $treeBuilder->getRootNode(); |
|
604 | } |
||
605 | |||
606 | $node |
||
607 | 50 | ->useAttributeAsKey('name') |
|
608 | 50 | ->prototype('array') |
|
609 | 50 | ->validate() |
|
610 | 50 | ->always() |
|
611 | ->then(function ($config) { |
||
612 | 8 | switch ($config['type']) { |
|
613 | 8 | case 'basic': |
|
614 | 7 | $this->validateAuthenticationType(['username', 'password'], $config, 'basic'); |
|
615 | |||
616 | 7 | break; |
|
617 | 2 | case 'bearer': |
|
618 | 1 | $this->validateAuthenticationType(['token'], $config, 'bearer'); |
|
619 | |||
620 | 1 | break; |
|
621 | 2 | case 'service': |
|
622 | 2 | $this->validateAuthenticationType(['service'], $config, 'service'); |
|
623 | |||
624 | 1 | break; |
|
625 | 1 | case 'wsse': |
|
626 | 1 | $this->validateAuthenticationType(['username', 'password'], $config, 'wsse'); |
|
627 | |||
628 | 1 | break; |
|
629 | case 'query_param': |
||
630 | $this->validateAuthenticationType(['params'], $config, 'query_param'); |
||
631 | |||
632 | break; |
||
633 | } |
||
634 | |||
635 | 7 | return $config; |
|
636 | 50 | }) |
|
637 | 50 | ->end() |
|
638 | 50 | ->children() |
|
639 | 50 | ->enumNode('type') |
|
640 | 50 | ->values(['basic', 'bearer', 'wsse', 'service', 'query_param']) |
|
641 | 50 | ->isRequired() |
|
642 | 50 | ->cannotBeEmpty() |
|
643 | 50 | ->end() |
|
644 | 50 | ->scalarNode('username')->end() |
|
645 | 50 | ->scalarNode('password')->end() |
|
646 | 50 | ->scalarNode('token')->end() |
|
647 | 50 | ->scalarNode('service')->end() |
|
648 | 50 | ->arrayNode('params')->prototype('scalar')->end() |
|
649 | 50 | ->end() |
|
650 | 50 | ->end() |
|
651 | 50 | ->end(); // End authentication plugin |
|
652 | |||
653 | 50 | return $node; |
|
654 | } |
||
655 | |||
656 | /** |
||
657 | * Validate that the configuration fragment has the specified keys and none other. |
||
658 | * |
||
659 | * @param array $expected Fields that must exist |
||
660 | * @param array $actual Actual configuration hashmap |
||
661 | * @param string $authName Name of authentication method for error messages |
||
662 | * |
||
663 | * @throws InvalidConfigurationException If $actual does not have exactly the keys specified in $expected (plus 'type') |
||
664 | */ |
||
665 | 8 | private function validateAuthenticationType(array $expected, array $actual, $authName) |
|
687 | |||
688 | /** |
||
689 | * Create configuration for cache plugin. |
||
690 | * |
||
691 | * @return NodeDefinition definition for the cache node in the plugins list |
||
692 | */ |
||
693 | 50 | private function createCachePluginNode() |
|
806 | } |
||
807 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.