Skip to content

Commit f3d2ef8

Browse files
authored
Merge pull request #323 from php-http/cleanup-config-validation
simplify configuration validation
2 parents 6a74d86 + ea815db commit f3d2ef8

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,11 @@ public function getConfigTreeBuilder()
141141
->end()
142142
->scalarNode('formatter')->defaultNull()->end()
143143
->scalarNode('captured_body_length')
144-
->beforeNormalization()
145-
->always(function ($maxLength) {
146-
if (null === $maxLength) {
147-
return null;
148-
}
149-
150-
if (!is_int($maxLength)) {
151-
$invalidConfiguration = new InvalidConfigurationException('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null.');
152-
$invalidConfiguration->setPath('httplug.profiling');
153-
154-
throw $invalidConfiguration;
155-
}
156-
157-
return $maxLength;
144+
->validate()
145+
->ifTrue(function ($v) {
146+
return null !== $v && !is_int($v);
158147
})
148+
->thenInvalid('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null ("%s" given).')
159149
->end()
160150
->defaultValue(0)
161151
->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).')

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function testLimitlessCapturedBodyLength()
406406

407407
/**
408408
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
409-
* @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null.
409+
* @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null
410410
*/
411411
public function testInvalidCapturedBodyLengthString()
412412
{

0 commit comments

Comments
 (0)