Skip to content

Commit e665c92

Browse files
committed
minor #6629 Update options_resolver.rst (atailouloute)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #6629). Discussion ---------- Update options_resolver.rst The old code will not work as expected if the `host` option starts with `https`, the `substr` function will return `https:/` and not `https://`. ```php $resolver = new Symfony\Component\OptionsResolver\OptionsResolver; $resolver->setDefined(['host', 'encryption']); $resolver->setNormalizer('host', function (Options $options, $value) { if (!in_array(substr($value, 0, 7), array('http://', 'https://'))) { if ('ssl' === $options['encryption']) { $value = 'https://'.$value; } else { $value = 'http://'.$value; } } return $value; });; $options = $resolver->resolve(array( 'host' => 'https://symfony.com/', 'encryption' => 'ssl' )); echo $options['host']; // Expected value : https://symfony.com/ // Result : https://https://symfony.com/ ``` Commits ------- a474785 Update options_resolver.rst
2 parents 78da6d5 + a474785 commit e665c92

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

components/options_resolver.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ if you need to use other options during normalization::
464464
{
465465
// ...
466466
$resolver->setNormalizer('host', function (Options $options, $value) {
467-
if (!in_array(substr($value, 0, 7), array('http://', 'https://'))) {
467+
if ('http://' !== substr($value, 0, 7) && 'https://' !== substr($value, 0, 8)) {
468468
if ('ssl' === $options['encryption']) {
469469
$value = 'https://'.$value;
470470
} else {

0 commit comments

Comments
 (0)