8000 Deprecation based on the value must be triggered once · symfony/symfony@c19026d · GitHub
[go: up one dir, main page]

Skip to content

Commit c19026d

Browse files
committed
Deprecation based on the value must be triggered once
1 parent 2ed0fda commit c19026d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ public function offsetGet($option)
798798

799799
// Shortcut for resolved options
800800
if (array_key_exists($option, $this->resolved)) {
801-
if (isset($this->deprecated[$option])) {
801+
if (isset($this->deprecated[$option]) && '' !== $this->deprecated[$option]) {
802802
@trigger_error(strtr($this->deprecated[$option], array('%name%' => $option)), E_USER_DEPRECATED);
803803
}
804804

@@ -948,14 +948,14 @@ public function offsetGet($option)
948948
} finally {
949949
unset($this->calling[$option]);
950950
}
951+
952+
// Deprecation based on the value must be triggered once
953+
$this->deprecated[$option] = '';
951954
}
952955

953956
if ('' !== $deprecationMessage) {
954957
@trigger_error(strtr($deprecationMessage, array('%name%' => $option)), E_USER_DEPRECATED);
955958
}
956-
957-
// Store result for next calls
958-
$this->deprecated[$option] = $deprecationMessage ?: null;
959959
}
960960

961961
// Normalize the validated option

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,31 @@ function (OptionsResolver $resolver) {
651651
1,
652652
);
653653

654+
yield 'It trigger deprecation based on the value once' => array(
655+
function (OptionsResolver $resolver) {
656+
$resolver
657+
->setDefined('foo')
658+
->setAllowedTypes('foo', array('null', 'bool'))
659+
->setDeprecated('foo', function (Options $options, $value) {
660+
if (!\is_bool($value)) {
661+
return 'Passing a value different than true or false is deprecated.';
662+
}
663+
664+
return '';
665+
})
666+
->setDefault('bar', function (Options $options) {
667+
return $options['foo'];
668+
})
669+
;
670+
},
671+
array('foo' => null),
672+
array(
673+
'type' => E_USER_DEPRECATED,
674+
'message' => 'Passing a value different than true or false is deprecated.',
675+
),
676+
1,
677+
);
678+
654679
yield 'It ignores deprecation for missing option without default value' => array(
655680
function (OptionsResolver $resolver) {
656681
$resolver

0 commit comments

Comments
 (0)
0