Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c47fd5f

Browse files
committed
Explicitly ignores a depreciation (useful for BC layer)
1 parent 44870ef commit c47fd5f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/Symfony/Component/OptionsResolver/Options.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
* @author Bernhard Schussek <[email protected]>
1818
* @author Tobias Schultze <http://tobion.de>
19+
*
20+
* @method mixed offsetGet(string $option, bool $triggerDeprecation = true)
1921
*/
2022
interface Options extends \ArrayAccess, \Countable
2123
{

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,17 @@ public function resolve(array $options = array())
790790
* @throws OptionDefinitionException If there is a cyclic dependency between
791791
* lazy options and/or normalizers
792792
*/
793-
public function offsetGet($option)
793+
public function offsetGet($option/*, bool $triggerDeprecation = true*/)
794794
{
795795
if (!$this->locked) {
796796
throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
797797
}
798798

799+
$triggerDeprecation = 1 === \func_num_args() || \func_get_arg(1);
800+
799801
// Shortcut for resolved options
800802
if (array_key_exists($option, $this->resolved)) {
801-
if (isset($this->deprecated[$option]) && \is_string($this->deprecated[$option])) {
803+
if ($triggerDeprecation && isset($this->deprecated[$option]) && \is_string($this->deprecated[$option])) {
802804
@trigger_error(strtr($this->deprecated[$option], array('%name%' => $option)), E_USER_DEPRECATED);
803805
}
804806

@@ -931,7 +933,7 @@ public function offsetGet($option)
931933

932934
// Check whether the option is deprecated
933935
// and it is provided by the user or is being called from a lazy evaluation
934-
if (isset($this->deprecated[$option]) && (isset($this->given[$option]) || $this->calling)) {
936+
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || $this->calling)) {
935937
$deprecationMessage = $this->deprecated[$option];
936938

937939
if ($deprecationMessage instanceof \Closure) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,21 @@ function (OptionsResolver $resolver) {
750750
null,
751751
0,
752752
);
753+
754+
yield 'It explicitly ignores a depreciation.' => array(
755+
function (OptionsResolver $resolver) {
756+
$resolver
757+
->setDefault('foo', null)
758+
->setDeprecated('foo')
759+
->setDefault('bar', function (Options $options) {
760+
return $options->offsetGet('foo', false);
761+
})
762+
;
763+
},
764+
array(),
765+
null,
766+
0,
767+
);
753768
}
754769

755770
/**

0 commit comments

Comments
 (0)