Skip to content

Commit bca7365

Browse files
2binfreeGuilhemN
authored andcommitted
Test the presence of OptionsResolver when the body_converter validation option is enabled (#1912)
* #1909 test the presence of OptionsResolver when the body_converter validation option is enabled * use class constant and fix some coding styles * fix spelling
1 parent 8dbd244 commit bca7365

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Config\Definition\ConfigurationInterface;
1717
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1818
use Symfony\Component\HttpFoundation\Response;
19+
use Symfony\Component\OptionsResolver\OptionsResolver;
1920

2021
/**
2122
* This class contains the configuration information for the bundle.
@@ -110,7 +111,17 @@ public function getConfigTreeBuilder()
110111
->arrayNode('body_converter')
111112
->canBeEnabled()
112113
->children()
113-
->scalarNode('validate')->defaultFalse()->end()
114+
->scalarNode('validate')
115+
->defaultFalse()
116+
->beforeNormalization()
117+
->ifTrue()
118+
->then(function () {
119+
if (!class_exists(OptionsResolver::class)) {
120+
throw new InvalidConfigurationException("'body_converter.validate: true' requires OptionsResolver component installation ( composer require symfony/options-resolver )");
121+
}
122+
})
123+
->end()
124+
->end()
114125
->scalarNode('validation_errors_argument')->defaultValue('validationErrors')->end()
115126
->end()
116127
->end()

0 commit comments

Comments
 (0)