minor #28839 [LDAP] Revamp LDAP options with nested options definition (yceruto)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[LDAP] Revamp LDAP options with nested options definition
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Next move after https://github.com/symfony/symfony/pull/27291 :)
This will work exactly that before, nothing change regarding behavior, BUT now we've *less code* and *intuitive definition of nested options*.
Commits
-------
a26c284d2d
Revamp LDAP options with nested definition
This commit is contained in:
commit
60aaa808c1
@ -93,31 +93,17 @@ class Connection extends AbstractConnection
|
||||
$resolver->setAllowedTypes('debug', 'bool');
|
||||
$resolver->setDefault('referrals', false);
|
||||
$resolver->setAllowedTypes('referrals', 'bool');
|
||||
$resolver->setDefault('options', function (OptionsResolver $options, Options $parent) {
|
||||
$options->setDefined(array_map('strtolower', array_keys((new \ReflectionClass(ConnectionOptions::class))->getConstants())));
|
||||
|
||||
$resolver->setNormalizer('options', function (Options $options, $value) {
|
||||
if (true === $options['debug']) {
|
||||
$value['debug_level'] = 7;
|
||||
if (true === $parent['debug']) {
|
||||
$options->setDefault('debug_level', 7);
|
||||
}
|
||||
|
||||
if (!isset($value['protocol_version'])) {
|
||||
$value['protocol_version'] = $options['version'];
|
||||
}
|
||||
|
||||
if (!isset($value['referrals'])) {
|
||||
$value['referrals'] = $options['referrals'];
|
||||
}
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$resolver->setAllowedValues('options', function (array $values) {
|
||||
foreach ($values as $name => $value) {
|
||||
if (!ConnectionOptions::isOption($name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
$options->setDefaults(array(
|
||||
'protocol_version' => $parent['version'],
|
||||
'referrals' => $parent['referrals'],
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,12 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/options-resolver": "~3.4|~4.0",
|
||||
"symfony/options-resolver": "~4.2",
|
||||
"ext-ldap": "*"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/options-resolver": "<4.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\Ldap\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
|
Reference in New Issue
Block a user