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:
@@ -31,13 +31,14 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
*/
|
||||
protected $container;
|
||||
protected $currentId;
|
||||
protected bool $skipScalars = false;
|
||||
|
||||
private $processExpressions = false;
|
||||
private $expressionLanguage;
|
||||
private $inExpression = false;
|
||||
private bool $processExpressions = false;
|
||||
private ExpressionLanguage $expressionLanguage;
|
||||
private bool $inExpression = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
@@ -50,6 +51,9 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function enableExpressionProcessing()
|
||||
{
|
||||
$this->processExpressions = true;
|
||||
@@ -68,15 +72,19 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
/**
|
||||
* Processes a value found in a definition tree.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
protected function processValue(mixed $value, bool $isRoot = false)
|
||||
{
|
||||
if (\is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
if ((!$v || \is_scalar($v)) && $this->skipScalars) {
|
||||
continue;
|
||||
}
|
||||
if ($isRoot) {
|
||||
if ($v->hasTag('container.excluded')) {
|
||||
continue;
|
||||
}
|
||||
$this->currentId = $k;
|
||||
}
|
||||
if ($v !== $processedValue = $this->processValue($v, $isRoot)) {
|
||||
@@ -86,7 +94,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
} elseif ($value instanceof ArgumentInterface) {
|
||||
$value->setValues($this->processValue($value->getValues()));
|
||||
} elseif ($value instanceof Expression && $this->processExpressions) {
|
||||
$this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']);
|
||||
$this->getExpressionLanguage()->compile((string) $value, ['this' => 'container', 'args' => 'args']);
|
||||
} elseif ($value instanceof Definition) {
|
||||
$value->setArguments($this->processValue($value->getArguments()));
|
||||
$value->setProperties($this->processValue($value->getProperties()));
|
||||
@@ -94,7 +102,16 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
|
||||
$changes = $value->getChanges();
|
||||
if (isset($changes['factory'])) {
|
||||
$value->setFactory($this->processValue($value->getFactory()));
|
||||
if (\is_string($factory = $value->getFactory()) && str_starts_with($factory, '@=')) {
|
||||
if (!class_exists(Expression::class)) {
|
||||
throw new LogicException('Expressions cannot be used in service factories without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
|
||||
}
|
||||
$factory = new Expression(substr($factory, 2));
|
||||
}
|
||||
if (($factory = $this->processValue($factory)) instanceof Expression) {
|
||||
$factory = '@='.$factory;
|
||||
}
|
||||
$value->setFactory($factory);
|
||||
}
|
||||
if (isset($changes['configurator'])) {
|
||||
$value->setConfigurator($this->processValue($value->getConfigurator()));
|
||||
@@ -105,17 +122,19 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \ReflectionFunctionAbstract|null
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function getConstructor(Definition $definition, bool $required)
|
||||
protected function getConstructor(Definition $definition, bool $required): ?\ReflectionFunctionAbstract
|
||||
{
|
||||
if ($definition->isSynthetic()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (\is_string($factory = $definition->getFactory())) {
|
||||
if (str_starts_with($factory, '@=')) {
|
||||
return new \ReflectionFunction(static function (...$args) {});
|
||||
}
|
||||
|
||||
if (!\function_exists($factory)) {
|
||||
throw new RuntimeException(sprintf('Invalid service "%s": function "%s" does not exist.', $this->currentId, $factory));
|
||||
}
|
||||
@@ -141,8 +160,8 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
} elseif ($class instanceof Definition) {
|
||||
$class = $class->getClass();
|
||||
} elseif (null === $class) {
|
||||
$class = $definition->getClass();
|
||||
} else {
|
||||
$class ??= $definition->getClass();
|
||||
}
|
||||
|
||||
return $this->getReflectionMethod(new Definition($class), $method);
|
||||
@@ -176,10 +195,8 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*
|
||||
* @return \ReflectionFunctionAbstract
|
||||
*/
|
||||
protected function getReflectionMethod(Definition $definition, string $method)
|
||||
protected function getReflectionMethod(Definition $definition, string $method): \ReflectionFunctionAbstract
|
||||
{
|
||||
if ('__construct' === $method) {
|
||||
return $this->getConstructor($definition, true);
|
||||
@@ -215,7 +232,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
|
||||
private function getExpressionLanguage(): ExpressionLanguage
|
||||
{
|
||||
if (null === $this->expressionLanguage) {
|
||||
if (!isset($this->expressionLanguage)) {
|
||||
if (!class_exists(ExpressionLanguage::class)) {
|
||||
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user