mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
@@ -23,34 +25,86 @@ use Symfony\Component\DependencyInjection\Reference;
|
||||
*/
|
||||
class DefinitionErrorExceptionPass extends AbstractRecursivePass
|
||||
{
|
||||
protected bool $skipScalars = true;
|
||||
|
||||
private array $erroredDefinitions = [];
|
||||
private array $sourceReferences = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$value instanceof Definition || !$value->hasErrors()) {
|
||||
try {
|
||||
parent::process($container);
|
||||
|
||||
$visitedIds = [];
|
||||
|
||||
foreach ($this->erroredDefinitions as $id => $definition) {
|
||||
if ($this->isErrorForRuntime($id, $visitedIds)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// only show the first error so the user can focus on it
|
||||
$errors = $definition->getErrors();
|
||||
|
||||
throw new RuntimeException(reset($errors));
|
||||
}
|
||||
} finally {
|
||||
$this->erroredDefinitions = [];
|
||||
$this->sourceReferences = [];
|
||||
}
|
||||
}
|
||||
|
||||
protected function processValue(mixed $value, bool $isRoot = false): mixed
|
||||
{
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
parent::processValue($value->getValues());
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
|
||||
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
|
||||
$this->sourceReferences[$targetId][$this->currentId] ??= true;
|
||||
} else {
|
||||
$this->sourceReferences[$targetId][$this->currentId] = false;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$value instanceof Definition || !$value->hasErrors() || $value->hasTag('container.error')) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
}
|
||||
|
||||
if ($isRoot && !$value->isPublic()) {
|
||||
$graph = $this->container->getCompiler()->getServiceReferenceGraph();
|
||||
$runtimeException = false;
|
||||
foreach ($graph->getNode($this->currentId)->getInEdges() as $edge) {
|
||||
if (!$edge->getValue() instanceof Reference || ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE !== $edge->getValue()->getInvalidBehavior()) {
|
||||
$runtimeException = false;
|
||||
break;
|
||||
}
|
||||
$runtimeException = true;
|
||||
$this->erroredDefinitions[$this->currentId] = $value;
|
||||
|
||||
return parent::processValue($value);
|
||||
}
|
||||
|
||||
private function isErrorForRuntime(string $id, array &$visitedIds): bool
|
||||
{
|
||||
if (!isset($this->sourceReferences[$id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($visitedIds[$id])) {
|
||||
return $visitedIds[$id];
|
||||
}
|
||||
|
||||
$visitedIds[$id] = true;
|
||||
|
||||
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
|
||||
if ($visitedIds[$sourceId] ?? $visitedIds[$sourceId] = $this->isErrorForRuntime($sourceId, $visitedIds)) {
|
||||
continue;
|
||||
}
|
||||
if ($runtimeException) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
||||
if (!$isRuntime) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// only show the first error so the user can focus on it
|
||||
$errors = $value->getErrors();
|
||||
$message = reset($errors);
|
||||
|
||||
throw new RuntimeException($message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user