mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 13:38:44 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Target;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
@@ -39,8 +42,39 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
try {
|
||||
parent::process($container);
|
||||
|
||||
foreach ($this->unusedBindings as list($key, $serviceId)) {
|
||||
$message = sprintf('Unused binding "%s" in service "%s".', $key, $serviceId);
|
||||
foreach ($this->unusedBindings as [$key, $serviceId, $bindingType, $file]) {
|
||||
$argumentType = $argumentName = $message = null;
|
||||
|
||||
if (str_contains($key, ' ')) {
|
||||
[$argumentType, $argumentName] = explode(' ', $key, 2);
|
||||
} elseif ('$' === $key[0]) {
|
||||
$argumentName = $key;
|
||||
} else {
|
||||
$argumentType = $key;
|
||||
}
|
||||
|
||||
if ($argumentType) {
|
||||
$message .= sprintf('of type "%s" ', $argumentType);
|
||||
}
|
||||
|
||||
if ($argumentName) {
|
||||
$message .= sprintf('named "%s" ', $argumentName);
|
||||
}
|
||||
|
||||
if (BoundArgument::DEFAULTS_BINDING === $bindingType) {
|
||||
$message .= 'under "_defaults"';
|
||||
} elseif (BoundArgument::INSTANCEOF_BINDING === $bindingType) {
|
||||
$message .= 'under "_instanceof"';
|
||||
} else {
|
||||
$message .= sprintf('for service "%s"', $serviceId);
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
$message .= sprintf(' in file "%s"', $file);
|
||||
}
|
||||
|
||||
$message = sprintf('A binding is configured for an argument %s, but no corresponding argument has been found. It may be unused and should be removed, or it may have a typo.', $message);
|
||||
|
||||
if ($this->errorMessages) {
|
||||
$message .= sprintf("\nCould be related to%s:", 1 < \count($this->errorMessages) ? ' one of' : '');
|
||||
}
|
||||
@@ -59,11 +93,16 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof TypedReference && $value->getType() === $this->container->normalizeId($value)) {
|
||||
if ($value instanceof TypedReference && $value->getType() === (string) $value) {
|
||||
// Already checked
|
||||
$bindings = $this->container->getDefinition($this->currentId)->getBindings();
|
||||
$name = $value->getName();
|
||||
|
||||
if (isset($name, $bindings[$name = $value.' $'.$name])) {
|
||||
return $this->getBindingValue($bindings[$name]);
|
||||
}
|
||||
|
||||
if (isset($bindings[$value->getType()])) {
|
||||
return $this->getBindingValue($bindings[$value->getType()]);
|
||||
@@ -76,21 +115,32 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
return parent::processValue($value, $isRoot);
|
||||
}
|
||||
|
||||
$bindingNames = [];
|
||||
|
||||
foreach ($bindings as $key => $binding) {
|
||||
list($bindingValue, $bindingId, $used) = $binding->getValues();
|
||||
[$bindingValue, $bindingId, $used, $bindingType, $file] = $binding->getValues();
|
||||
if ($used) {
|
||||
$this->usedBindings[$bindingId] = true;
|
||||
unset($this->unusedBindings[$bindingId]);
|
||||
} elseif (!isset($this->usedBindings[$bindingId])) {
|
||||
$this->unusedBindings[$bindingId] = [$key, $this->currentId];
|
||||
$this->unusedBindings[$bindingId] = [$key, $this->currentId, $bindingType, $file];
|
||||
}
|
||||
|
||||
if (isset($key[0]) && '$' === $key[0]) {
|
||||
if (preg_match('/^(?:(?:array|bool|float|int|string|iterable|([^ $]++)) )\$/', $key, $m)) {
|
||||
$bindingNames[substr($key, \strlen($m[0]))] = $binding;
|
||||
}
|
||||
|
||||
if (!isset($m[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of "%s" or an instance of "%s", "%s" given.', $key, $this->currentId, Reference::class, Definition::class, \gettype($bindingValue)));
|
||||
if (is_subclass_of($m[1], \UnitEnum::class)) {
|
||||
$bindingNames[substr($key, \strlen($m[0]))] = $binding;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected "%s", "%s", "%s", "%s" or null, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, ServiceLocatorArgument::class, get_debug_type($bindingValue)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +162,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
foreach ($calls as $i => $call) {
|
||||
list($method, $arguments) = $call;
|
||||
[$method, $arguments] = $call;
|
||||
|
||||
if ($method instanceof \ReflectionFunctionAbstract) {
|
||||
$reflectionMethod = $method;
|
||||
@@ -132,19 +182,32 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\array_key_exists('$'.$parameter->name, $bindings)) {
|
||||
$arguments[$key] = $this->getBindingValue($bindings['$'.$parameter->name]);
|
||||
$typeHint = ProxyHelper::getTypeHint($reflectionMethod, $parameter);
|
||||
$name = Target::parseName($parameter);
|
||||
|
||||
if ($typeHint && \array_key_exists($k = ltrim($typeHint, '\\').' $'.$name, $bindings)) {
|
||||
$arguments[$key] = $this->getBindingValue($bindings[$k]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$typeHint = ProxyHelper::getTypeHint($reflectionMethod, $parameter, true);
|
||||
if (\array_key_exists('$'.$name, $bindings)) {
|
||||
$arguments[$key] = $this->getBindingValue($bindings['$'.$name]);
|
||||
|
||||
if (!isset($bindings[$typeHint])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$arguments[$key] = $this->getBindingValue($bindings[$typeHint]);
|
||||
if ($typeHint && '\\' === $typeHint[0] && isset($bindings[$typeHint = substr($typeHint, 1)])) {
|
||||
$arguments[$key] = $this->getBindingValue($bindings[$typeHint]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($bindingNames[$name]) || isset($bindingNames[$parameter->name])) {
|
||||
$bindingKey = array_search($binding, $bindings, true);
|
||||
$argumentType = substr($bindingKey, 0, strpos($bindingKey, ' '));
|
||||
$this->errorMessages[] = sprintf('Did you forget to add the type "%s" to argument "$%s" of method "%s::%s()"?', $argumentType, $parameter->name, $reflectionMethod->class, $reflectionMethod->name);
|
||||
}
|
||||
}
|
||||
|
||||
if ($arguments !== $call[1]) {
|
||||
@@ -154,7 +217,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
if ($constructor) {
|
||||
list(, $arguments) = array_pop($calls);
|
||||
[, $arguments] = array_pop($calls);
|
||||
|
||||
if ($arguments !== $value->getArguments()) {
|
||||
$value->setArguments($arguments);
|
||||
@@ -168,9 +231,12 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
return parent::processValue($value, $isRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function getBindingValue(BoundArgument $binding)
|
||||
{
|
||||
list($bindingValue, $bindingId) = $binding->getValues();
|
||||
[$bindingValue, $bindingId] = $binding->getValues();
|
||||
|
||||
$this->usedBindings[$bindingId] = true;
|
||||
unset($this->unusedBindings[$bindingId]);
|
||||
|
||||
Reference in New Issue
Block a user