mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -50,22 +50,22 @@ class YamlDumper extends Dumper
|
||||
|
||||
$this->dumper ??= new YmlDumper();
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices());
|
||||
return $this->addParameters()."\n".$this->addServices();
|
||||
}
|
||||
|
||||
private function addService(string $id, Definition $definition): string
|
||||
{
|
||||
$code = " $id:\n";
|
||||
$code = " {$this->dumper->dump($id)}:\n";
|
||||
if ($class = $definition->getClass()) {
|
||||
if (str_starts_with($class, '\\')) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$code .= sprintf(" class: %s\n", $this->dumper->dump($class));
|
||||
$code .= \sprintf(" class: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($class)));
|
||||
}
|
||||
|
||||
if (!$definition->isPrivate()) {
|
||||
$code .= sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
|
||||
$code .= \sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
$tagsCode = '';
|
||||
@@ -75,11 +75,11 @@ class YamlDumper extends Dumper
|
||||
foreach ($tags as $attributes) {
|
||||
$att = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
$att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
|
||||
$att[] = \sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
|
||||
}
|
||||
$att = $att ? ': { '.implode(', ', $att).' }' : '';
|
||||
|
||||
$tagsCode .= sprintf(" - %s%s\n", $this->dumper->dump($name), $att);
|
||||
$tagsCode .= \sprintf(" - %s%s\n", $this->dumper->dump($name), $att);
|
||||
}
|
||||
}
|
||||
if ($tagsCode) {
|
||||
@@ -87,7 +87,7 @@ class YamlDumper extends Dumper
|
||||
}
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$code .= sprintf(" file: %s\n", $this->dumper->dump($definition->getFile()));
|
||||
$code .= \sprintf(" file: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($definition->getFile())));
|
||||
}
|
||||
|
||||
if ($definition->isSynthetic()) {
|
||||
@@ -98,7 +98,7 @@ class YamlDumper extends Dumper
|
||||
$code .= " deprecated:\n";
|
||||
foreach ($definition->getDeprecation('%service_id%') as $key => $value) {
|
||||
if ('' !== $value) {
|
||||
$code .= sprintf(" %s: %s\n", $key, $this->dumper->dump($value));
|
||||
$code .= \sprintf(" %s: %s\n", $key, $this->dumper->dump($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,15 +120,15 @@ class YamlDumper extends Dumper
|
||||
}
|
||||
|
||||
if ($definition->getArguments()) {
|
||||
$code .= sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
|
||||
$code .= \sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getProperties()) {
|
||||
$code .= sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
|
||||
$code .= \sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getMethodCalls()) {
|
||||
$code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
|
||||
$code .= \sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
|
||||
}
|
||||
|
||||
if (!$definition->isShared()) {
|
||||
@@ -137,31 +137,31 @@ class YamlDumper extends Dumper
|
||||
|
||||
if (null !== $decoratedService = $definition->getDecoratedService()) {
|
||||
[$decorated, $renamedId, $priority] = $decoratedService;
|
||||
$code .= sprintf(" decorates: %s\n", $decorated);
|
||||
$code .= \sprintf(" decorates: %s\n", $decorated);
|
||||
if (null !== $renamedId) {
|
||||
$code .= sprintf(" decoration_inner_name: %s\n", $renamedId);
|
||||
$code .= \sprintf(" decoration_inner_name: %s\n", $renamedId);
|
||||
}
|
||||
if (0 !== $priority) {
|
||||
$code .= sprintf(" decoration_priority: %s\n", $priority);
|
||||
$code .= \sprintf(" decoration_priority: %s\n", $priority);
|
||||
}
|
||||
|
||||
$decorationOnInvalid = $decoratedService[3] ?? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
if (\in_array($decorationOnInvalid, [ContainerInterface::IGNORE_ON_INVALID_REFERENCE, ContainerInterface::NULL_ON_INVALID_REFERENCE])) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE === $decorationOnInvalid ? 'null' : 'ignore';
|
||||
$code .= sprintf(" decoration_on_invalid: %s\n", $invalidBehavior);
|
||||
$code .= \sprintf(" decoration_on_invalid: %s\n", $invalidBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
if (\is_array($callable) && ['Closure', 'fromCallable'] !== $callable && $definition->getClass() === $callable[0]) {
|
||||
$code .= sprintf(" constructor: %s\n", $callable[1]);
|
||||
$code .= \sprintf(" constructor: %s\n", $callable[1]);
|
||||
} else {
|
||||
$code .= sprintf(" factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
$code .= \sprintf(" factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
}
|
||||
}
|
||||
|
||||
if ($callable = $definition->getConfigurator()) {
|
||||
$code .= sprintf(" configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
$code .= \sprintf(" configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
}
|
||||
|
||||
return $code;
|
||||
@@ -176,20 +176,20 @@ class YamlDumper extends Dumper
|
||||
|
||||
foreach ($id->getDeprecation('%alias_id%') as $key => $value) {
|
||||
if ('' !== $value) {
|
||||
$deprecated .= sprintf(" %s: %s\n", $key, $value);
|
||||
$deprecated .= \sprintf(" %s: %s\n", $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id->isDeprecated() && $id->isPrivate()) {
|
||||
return sprintf(" %s: '@%s'\n", $alias, $id);
|
||||
return \sprintf(" %s: '@%s'\n", $alias, $id);
|
||||
}
|
||||
|
||||
if ($id->isPublic()) {
|
||||
$deprecated = " public: true\n".$deprecated;
|
||||
}
|
||||
|
||||
return sprintf(" %s:\n alias: %s\n%s", $alias, $id, $deprecated);
|
||||
return \sprintf(" %s:\n alias: %s\n%s", $alias, $id, $deprecated);
|
||||
}
|
||||
|
||||
private function addServices(): string
|
||||
@@ -238,7 +238,7 @@ class YamlDumper extends Dumper
|
||||
}
|
||||
}
|
||||
|
||||
return $callable;
|
||||
return $this->container->resolveEnvPlaceholders($callable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +290,7 @@ class YamlDumper extends Dumper
|
||||
} elseif ($value instanceof ServiceLocatorArgument) {
|
||||
$tag = 'service_locator';
|
||||
} else {
|
||||
throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', get_debug_type($value)));
|
||||
throw new RuntimeException(\sprintf('Unspecified Yaml tag for type "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
return new TaggedValue($tag, $this->dumpValue($value->getValues()));
|
||||
@@ -299,7 +299,7 @@ class YamlDumper extends Dumper
|
||||
if (\is_array($value)) {
|
||||
$code = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$code[$k] = $this->dumpValue($v);
|
||||
$code[$this->container->resolveEnvPlaceholders($k)] = $this->dumpValue($v);
|
||||
}
|
||||
|
||||
return $code;
|
||||
@@ -312,38 +312,38 @@ class YamlDumper extends Dumper
|
||||
} elseif ($value instanceof Definition) {
|
||||
return new TaggedValue('service', (new Parser())->parse("_:\n".$this->addService('_', $value), Yaml::PARSE_CUSTOM_TAGS)['_']['_']);
|
||||
} elseif ($value instanceof \UnitEnum) {
|
||||
return new TaggedValue('php/const', sprintf('%s::%s', $value::class, $value->name));
|
||||
return new TaggedValue('php/const', \sprintf('%s::%s', $value::class, $value->name));
|
||||
} elseif ($value instanceof AbstractArgument) {
|
||||
return new TaggedValue('abstract', $value->getText());
|
||||
} elseif (\is_object($value) || \is_resource($value)) {
|
||||
throw new RuntimeException(sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
|
||||
throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $this->container->resolveEnvPlaceholders($value);
|
||||
}
|
||||
|
||||
private function getServiceCall(string $id, Reference $reference = null): string
|
||||
private function getServiceCall(string $id, ?Reference $reference = null): string
|
||||
{
|
||||
if (null !== $reference) {
|
||||
switch ($reference->getInvalidBehavior()) {
|
||||
case ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: break;
|
||||
case ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE: break;
|
||||
case ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE: return sprintf('@!%s', $id);
|
||||
default: return sprintf('@?%s', $id);
|
||||
case ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE: return \sprintf('@!%s', $id);
|
||||
default: return \sprintf('@?%s', $id);
|
||||
}
|
||||
}
|
||||
|
||||
return sprintf('@%s', $id);
|
||||
return \sprintf('@%s', $id);
|
||||
}
|
||||
|
||||
private function getParameterCall(string $id): string
|
||||
{
|
||||
return sprintf('%%%s%%', $id);
|
||||
return \sprintf('%%%s%%', $id);
|
||||
}
|
||||
|
||||
private function getExpressionCall(string $expression): string
|
||||
{
|
||||
return sprintf('@=%s', $expression);
|
||||
return \sprintf('@=%s', $expression);
|
||||
}
|
||||
|
||||
private function prepareParameters(array $parameters, bool $escape = true): array
|
||||
@@ -359,7 +359,7 @@ class YamlDumper extends Dumper
|
||||
$filtered[$key] = $value;
|
||||
}
|
||||
|
||||
return $escape ? $this->escape($filtered) : $filtered;
|
||||
return $escape ? $this->container->resolveEnvPlaceholders($this->escape($filtered)) : $filtered;
|
||||
}
|
||||
|
||||
private function escape(array $arguments): array
|
||||
|
||||
Reference in New Issue
Block a user