Commit e665c92
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.rst1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
| |||
0 commit comments