Skip to content

Commit 00d424b

Browse files
committed
Merge branch '2.7'
Conflicts: src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php
2 parents f537b8d + 510c096 commit 00d424b

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

OptionsResolver.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,23 @@ public function setNormalizer($option, \Closure $normalizer)
424424
}
425425

426426
/**
427-
* {@inheritdoc}
427+
* Sets the normalizers for an array of options.
428+
*
429+
* @param array $normalizers An array of closures
430+
*
431+
* @return OptionsResolver This instance
432+
*
433+
* @throws UndefinedOptionsException If the option is undefined
434+
* @throws AccessException If called from a lazy option or normalizer
435+
*
436+
* @see setNormalizer()
437+
*
438+
* @deprecated since version 2.6, to be removed in 3.0.
428439
*/
429440
public function setNormalizers(array $normalizers)
430441
{
442+
trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use setNormalizer() instead.', E_USER_DEPRECATED);
443+
431444
foreach ($normalizers as $option => $normalizer) {
432445
$this->setNormalizer($option, $normalizer);
433446
}
@@ -464,6 +477,8 @@ public function setAllowedValues($option, $allowedValues = null)
464477

465478
// BC
466479
if (is_array($option) && null === $allowedValues) {
480+
trigger_error('Calling the '.__METHOD__.' method with an array of options is deprecated since version 2.6 and will be removed in 3.0. Use the new signature with a single option instead.', E_USER_DEPRECATED);
481+
467482
foreach ($option as $optionName => $optionValues) {
468483
$this->setAllowedValues($optionName, $optionValues);
469484
}
@@ -479,7 +494,7 @@ public function setAllowedValues($option, $allowedValues = null)
479494
));
480495
}
481496

482-
$this->allowedValues[$option] = $allowedValues instanceof \Closure ? array($allowedValues) : (array) $allowedValues;
497+
$this->allowedValues[$option] = is_array($allowedValues) ? $allowedValues : array($allowedValues);
483498

484499
// Make sure the option is processed
485500
unset($this->resolved[$option]);
@@ -518,6 +533,8 @@ public function addAllowedValues($option, $allowedValues = null)
518533

519534
// BC
520535
if (is_array($option) && null === $allowedValues) {
536+
trigger_error('Calling the '.__METHOD__.' method with an array of options is deprecated since version 2.6 and will be removed in 3.0. Use the new signature with a single option instead.', E_USER_DEPRECATED);
537+
521538
foreach ($option as $optionName => $optionValues) {
522539
$this->addAllowedValues($optionName, $optionValues);
523540
}
@@ -533,12 +550,14 @@ public function addAllowedValues($option, $allowedValues = null)
533550
));
534551
}
535552

536-
if ($allowedValues instanceof \Closure) {
537-
$this->allowedValues[$option][] = $allowedValues;
538-
} elseif (!isset($this->allowedValues[$option])) {
539-
$this->allowedValues[$option] = (array) $allowedValues;
553+
if (!is_array($allowedValues)) {
554+
$allowedValues = array($allowedValues);
555+
}
556+
557+
if (!isset($this->allowedValues[$option])) {
558+
$this->allowedValues[$option] = $allowedValues;
540559
} else {
541-
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], (array) $allowedValues);
560+
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], $allowedValues);
542561
}
543562

544563
// Make sure the option is processed
@@ -570,6 +589,8 @@ public function setAllowedTypes($option, $allowedTypes = null)
570589

571590
// BC
572591
if (is_array($option) && null === $allowedTypes) {
592+
trigger_error('Calling the '.__METHOD__.' method with an array of options is deprecated since version 2.6 and will be removed in 3.0. Use the new signature with a single option instead.', E_USER_DEPRECATED);
593+
573594
foreach ($option as $optionName => $optionTypes) {
574595
$this->setAllowedTypes($optionName, $optionTypes);
575596
}
@@ -618,6 +639,8 @@ public function addAllowedTypes($option, $allowedTypes = null)
618639

619640
// BC
620641
if (is_array($option) && null === $allowedTypes) {
642+
trigger_error('Calling the '.__METHOD__.' method with an array of options is deprecated since version 2.6 and will be removed in 3.0. Use the new signature with a single option instead.', E_USER_DEPRECATED);
643+
621644
foreach ($option as $optionName => $optionTypes) {
622645
$this->addAllowedTypes($optionName, $optionTypes);
623646
}

Tests/OptionsResolver2Dot6Test.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ public function testResolveSucceedsIfValidValue()
724724
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
725725
}
726726

727+
public function testResolveSucceedsIfValidValueIsNull()
728+
{
729+
$this->resolver->setDefault('foo', null);
730+
$this->resolver->setAllowedValues('foo', null);
731+
732+
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
733+
}
734+
727735
/**
728736
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
729737
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
@@ -847,6 +855,14 @@ public function testResolveSucceedsIfValidAddedValue()
847855
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
848856
}
849857

858+
public function testResolveSucceedsIfValidAddedValueIsNull()
859+
{
860+
$this->resolver->setDefault('foo', null);
861+
$this->resolver->addAllowedValues('foo', null);
862+
863+
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
864+
}
865+
850866
/**
851867
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
852868
*/

0 commit comments

Comments
 (0)