Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ed0fda

Browse filesBrowse files
committed
Trigger deprecation each time it's evaluated
1 parent aeef730 commit 2ed0fda
Copy full SHA for 2ed0fda

File tree

2 files changed

+24
-10
lines changed
Filter options

2 files changed

+24
-10
lines changed

‎src/Symfony/Component/OptionsResolver/OptionsResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,6 @@ public function resolve(array $options = array())
766766
// Lock the container
767767
$clone->locked = true;
768768

769-
if ($clone->defaults && $clone->deprecated) {
770-
// Deprecated options must be evaluated last
771-
uksort($clone->defaults, function ($option) use ($clone): int {
772-
return (int) isset($clone->deprecated[$option]);
773-
});
774-
}
775-
776769
// Now process the individual options. Use offsetGet(), which resolves
777770
// the option itself and any options that the option depends on
778771
foreach ($clone->defaults as $option => $_) {
@@ -805,6 +798,10 @@ public function offsetGet($option)
805798

806799
// Shortcut for resolved options
807800
if (array_key_exists($option, $this->resolved)) {
801+
if (isset($this->deprecated[$option])) {
802+
@trigger_error(strtr($this->deprecated[$option], array('%name%' => $option)), E_USER_DEPRECATED);
803+
}
804+
808805
return $this->resolved[$option];
809806
}
810807

@@ -956,6 +953,9 @@ public function offsetGet($option)
956953
if ('' !== $deprecationMessage) {
957954
@trigger_error(strtr($deprecationMessage, array('%name%' => $option)), E_USER_DEPRECATED);
958955
}
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public function testLazyDeprecationFailsIfInvalidDeprecationMessageType()
501501

502502
/**
503503
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
504-
* @expectedExceptionMessage The options "bar", "foo" have a cyclic dependency.
504+
* @expectedExceptionMessage The options "foo", "bar" have a cyclic dependency.
505505
*/
506506
public function testFailsIfCyclicDependencyBetweenDeprecation()
507507
{
@@ -538,10 +538,15 @@ public function testIsNotDeprecatedIfEmptyString()
538538
/**
539539
* @dataProvider provideDeprecationData
540540
*/
541-
public function testDeprecationMessages(\Closure $configureOptions, array $options, ?array $expectedError)
541+
public function testDeprecationMessages(\Closure $configureOptions, array $options, ?array $expectedError, int $expectedCount)
542542
{
543+
$count = 0;
543544
error_clear_last();
544-
set_error_handler(function () { return false; });
545+
set_error_handler(function () use (&$count) {
546+
++$count;
547+
548+
return false;
549+
});
545550
$e = error_reporting(0);
546551

547552
$configureOptions($this->resolver);
@@ -554,6 +559,7 @@ public function testDeprecationMessages(\Closure $configureOptions, array $optio
554559
unset($lastError['file'], $lastError['line']);
555560

556561
$this->assertSame($expectedError, $lastError);
562+
$this->assertSame($expectedCount, $count);
557563
}
558564

559565
public function provideDeprecationData()
@@ -570,6 +576,7 @@ function (OptionsResolver $resolver) {
570576
'type' => E_USER_DEPRECATED,
571577
'message' => 'The option "foo" is deprecated.',
572578
),
579+
1,
573580
);
574581

575582
yield 'It deprecates an option with custom message' => array(
@@ -587,6 +594,7 @@ function (OptionsResolver $resolver) {
587594
'type' => E_USER_DEPRECATED,
588595
'message' => 'The option "foo" is deprecated, use "bar" option instead.',
589596
),
597+
2,
590598
);
591599

592600
yield 'It does not deprecates a missing option with default value' => array(
@@ -598,6 +606,7 @@ function (OptionsResolver $resolver) {
598606
},
599607
array(),
600608
null,
609+
0,
601610
);
602611

603612
yield 'It deprecates an option evaluated in another definition' => array(
@@ -617,6 +626,7 @@ function (OptionsResolver $resolver) {
617626
'type' => E_USER_DEPRECATED,
618627
'message' => 'The option "foo" is deprecated.',
619628
),
629+
1,
620630
);
621631

622632
yield 'It deprecates allowed type and value' => array(
@@ -638,6 +648,7 @@ function (OptionsResolver $resolver) {
638648
'type' => E_USER_DEPRECATED,
639649
'message' => 'Passing an instance of "stdClass" to option "foo" is deprecated, pass its FQCN instead.',
640650
),
651+
1,
641652
);
642653

643654
yield 'It ignores deprecation for missing option without default value' => array(
@@ -649,6 +660,7 @@ function (OptionsResolver $resolver) {
649660
},
650661
array('bar' => 'baz'),
651662
null,
663+
0,
652664
);
653665

654666
yield 'It ignores deprecation if closure returns an empty string' => array(
@@ -662,6 +674,7 @@ function (OptionsResolver $resolver) {
662674
},
663675
array('foo' => Bar::class),
664676
null,
677+
0,
665678
);
666679

667680
yield 'It deprecates value depending on other option value' => array(
@@ -683,6 +696,7 @@ function (OptionsResolver $resolver) {
683696
'type' => E_USER_DEPRECATED,
684697
'message' => 'Using the "date_format" option when the "widget" option is set to "single_text" is deprecated.',
685698
),
699+
1,
686700
);
687701
}
688702

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.