[DI] fix casting AutowiringFailedException to string when its callback throws

This commit is contained in:
Nicolas Grekas 2019-03-17 10:46:08 +01:00
parent d7fdcb1a5d
commit d57a148b8b
3 changed files with 21 additions and 3 deletions

View File

@ -226,7 +226,16 @@ class AutowirePass extends AbstractRecursivePass
if ($parameter->isDefaultValueAvailable()) {
$value = $parameter->getDefaultValue();
} elseif (!$parameter->allowsNull()) {
throw new AutowiringFailedException($this->currentId, $failureMessage);
if (\function_exists('xdebug_disable')) {
xdebug_disable();
}
try {
throw new AutowiringFailedException($this->currentId, $failureMessage);
} finally {
if (\function_exists('xdebug_enable')) {
xdebug_enable();
}
}
}
}

View File

@ -84,10 +84,15 @@ class PassConfig
new RemoveUnusedDefinitionsPass(),
new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
new AnalyzeServiceReferencesPass(),
new DefinitionErrorExceptionPass(),
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new ResolveHotPathPass(),
]];
$this->afterRemovingPasses = [
100 => [
new DefinitionErrorExceptionPass(),
],
];
}
/**

View File

@ -47,7 +47,11 @@ class AutowiringFailedException extends RuntimeException
$messageCallback = $this->messageCallback;
$this->messageCallback = null;
return $this->message = $messageCallback();
try {
return $this->message = $messageCallback();
} catch (\Throwable $e) {
return $this->message = $e->getMessage();
}
}
};
}