Skip to content

Commit e347291

Browse files
committed
Fix the validation of incompatible options
All clients must be validated, not only the first one (which was the case due to returning during the first iteration of the loop over clients). The easiest way to handle it is to put the validation inside the prototype node, so that each client is validated separately. This also allows to have a better error message (as the error message will tell you which client is invalid as the error will be inside the client configuration node). The error message is also fixed to talk about the third incompatible features.
1 parent 6c8dc49 commit e347291

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

DependencyInjection/Configuration.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,16 @@ private function configureClients(ArrayNodeDefinition $root)
155155
{
156156
$root->children()
157157
->arrayNode('clients')
158-
->validate()
159-
->ifTrue(function ($clients) {
160-
foreach ($clients as $name => $config) {
161-
// Make sure we only allow one of these to be true
162-
return (bool) $config['flexible_client'] + (bool) $config['http_methods_client'] + (bool) $config['batch_client'] >= 2;
163-
}
164-
165-
return false;
166-
})
167-
->thenInvalid('A http client can\'t be decorated with both FlexibleHttpClient and HttpMethodsClient. Only one of the following options can be true. ("flexible_client", "http_methods_client")')->end()
168158
->useAttributeAsKey('name')
169159
->prototype('array')
170160
->fixXmlConfig('plugin')
161+
->validate()
162+
->ifTrue(function ($config) {
163+
// Make sure we only allow one of these to be true
164+
return (bool) $config['flexible_client'] + (bool) $config['http_methods_client'] + (bool) $config['batch_client'] >= 2;
165+
})
166+
->thenInvalid('A http client can\'t be decorated with both FlexibleHttpClient and HttpMethodsClient. Only one of the following options can be true. ("flexible_client", "http_methods_client", "batch_client")')
167+
->end()
171168
->children()
172169
->scalarNode('factory')
173170
->isRequired()

0 commit comments

Comments
 (0)