File tree 2 files changed +29
-4
lines changed
src/Symfony/Component/OptionsResolver
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -798,7 +798,7 @@ public function offsetGet($option)
798
798
799
799
// Shortcut for resolved options
800
800
if (array_key_exists ($ option , $ this ->resolved )) {
801
- if (isset ($ this ->deprecated [$ option ])) {
801
+ if (isset ($ this ->deprecated [$ option ]) && '' !== $ this -> deprecated [ $ option ] ) {
802
802
@trigger_error (strtr ($ this ->deprecated [$ option ], array ('%name% ' => $ option )), E_USER_DEPRECATED );
803
803
}
804
804
@@ -948,14 +948,14 @@ public function offsetGet($option)
948
948
} finally {
949
949
unset($ this ->calling [$ option ]);
950
950
}
951
+
952
+ // Deprecation based on the value must be triggered once
953
+ $ this ->deprecated [$ option ] = '' ;
951
954
}
952
955
953
956
if ('' !== $ deprecationMessage ) {
954
957
@trigger_error (strtr ($ deprecationMessage , array ('%name% ' => $ option )), E_USER_DEPRECATED );
955
958
}
956
-
957
- // Store result for next calls
958
- $ this ->deprecated [$ option ] = $ deprecationMessage ?: null ;
959
959
}
960
960
961
961
// Normalize the validated option
Original file line number Diff line number Diff line change @@ -651,6 +651,31 @@ function (OptionsResolver $resolver) {
651
651
1 ,
652
652
);
653
653
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
+
654
679
yield 'It ignores deprecation for missing option without default value ' => array (
655
680
function (OptionsResolver $ resolver ) {
656
681
$ resolver
You can’t perform that action at this time.
0 commit comments