Skip to content

Commit 2fdb511

Browse files
committed
Merge branch '2.8'
* 2.8: (23 commits) [Validator] added BIC (SWIFT-BIC) validation constraint [TwigBridge] Foundation form layout integration [Security] Deprecated supportsAttribute and supportsClass methods bumped Symfony version to 2.7.6 updated VERSION for 2.7.5 updated CHANGELOG for 2.7.5 bumped Symfony version to 2.3.34 updated VERSION for 2.3.33 update CONTRIBUTORS for 2.3.33 updated CHANGELOG for 2.3.33 [Console] Fix transient HHVM test [OptionsResolver] Fix catched exception along the dependency tree mistakenly detects cyclic dependencies fixed tests [DI] Support deprecated definitions in decorators [DI] Allow to change the deprecation message in Definition [DI] Trigger a deprecated error on the container builder [DI] Dump the deprecated status [DI] Supports the deprecated tag in loaders [DI] Add a deprecated status to definitions Fixing test locations ...
2 parents 07da60a + 4a4f45f commit 2fdb511

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

OptionsResolver.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,13 @@ public function offsetGet($option)
779779
// dependency
780780
// BEGIN
781781
$this->calling[$option] = true;
782-
foreach ($this->lazy[$option] as $closure) {
783-
$value = $closure($this, $value);
782+
try {
783+
foreach ($this->lazy[$option] as $closure) {
784+
$value = $closure($this, $value);
785+
}
786+
} catch (\Exception $e) {
787+
unset($this->calling[$option]);
788+
throw $e;
784789
}
785790
unset($this->calling[$option]);
786791
// END
@@ -878,7 +883,12 @@ public function offsetGet($option)
878883
// dependency
879884
// BEGIN
880885
$this->calling[$option] = true;
881-
$value = $normalizer($this, $value);
886+
try {
887+
$value = $normalizer($this, $value);
888+
} catch (\Exception $e) {
889+
unset($this->calling[$option]);
890+
throw $e;
891+
}
882892
unset($this->calling[$option]);
883893
// END
884894
}

Tests/OptionsResolverTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,56 @@ public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption()
11031103
$this->resolver->resolve();
11041104
}
11051105

1106+
public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver()
1107+
{
1108+
$throw = true;
1109+
1110+
$this->resolver->setDefaults(array('catcher' => null, 'thrower' => null));
1111+
1112+
$this->resolver->setNormalizer('catcher', function (Options $options) {
1113+
try {
1114+
return $options['thrower'];
1115+
} catch(\Exception $e) {
1116+
return false;
1117+
}
1118+
});
1119+
1120+
$this->resolver->setNormalizer('thrower', function (Options $options) use (&$throw) {
1121+
if ($throw) {
1122+
$throw = false;
1123+
throw new \UnexpectedValueException('throwing');
1124+
}
1125+
1126+
return true;
1127+
});
1128+
1129+
$this->resolver->resolve();
1130+
}
1131+
1132+
public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver()
1133+
{
1134+
$throw = true;
1135+
1136+
$this->resolver->setDefault('catcher', function (Options $options) {
1137+
try {
1138+
return $options['thrower'];
1139+
} catch(\Exception $e) {
1140+
return false;
1141+
}
1142+
});
1143+
1144+
$this->resolver->setDefault('thrower', function (Options $options) use (&$throw) {
1145+
if ($throw) {
1146+
$throw = false;
1147+
throw new \UnexpectedValueException('throwing');
1148+
}
1149+
1150+
return true;
1151+
});
1152+
1153+
$this->resolver->resolve();
1154+
}
1155+
11061156
public function testInvokeEachNormalizerOnlyOnce()
11071157
{
11081158
$calls = 0;

0 commit comments

Comments
 (0)