Skip to content

Commit 4bc7f93

Browse files
committed
[OptionsResolver] Fix force prepend normalizer
1 parent ecb5f7c commit 4bc7f93

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP
531531
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptions([$option]), implode('", "', array_keys($this->defined))));
532532
}
533533

534+
$this->normalizers[$option] = $this->normalizers[$option] ?? [];
534535
if ($forcePrepend) {
535536
array_unshift($this->normalizers[$option], $normalizer);
536537
} else {

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,17 @@ public function testForcePrependNormalizerClosure()
15061506
$this->assertEquals(['foo' => '2nd-normalized-1st-normalized-bar'], $this->resolver->resolve());
15071507
}
15081508

1509+
public function testForcePrependNormalizerForResolverWithoutPreviousNormalizers()
1510+
{
1511+
// defined by superclass
1512+
$this->resolver->setDefault('foo', 'bar');
1513+
$this->resolver->addNormalizer('foo', function (Options $options, $value) {
1514+
return '1st-normalized-'.$value;
1515+
}, true);
1516+
1517+
$this->assertEquals(['foo' => '1st-normalized-bar'], $this->resolver->resolve());
1518+
}
1519+
15091520
public function testAddNormalizerFailsIfUnknownOption()
15101521
{
15111522
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy