mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 05:28: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,7 @@
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
|
||||
/**
|
||||
* Looks for definitions with autowiring enabled and registers their corresponding "@required" methods as setters.
|
||||
@@ -23,7 +24,7 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
$value = parent::processValue($value, $isRoot);
|
||||
|
||||
@@ -35,8 +36,9 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
$alreadyCalledMethods = [];
|
||||
$withers = [];
|
||||
|
||||
foreach ($value->getMethodCalls() as list($method)) {
|
||||
foreach ($value->getMethodCalls() as [$method]) {
|
||||
$alreadyCalledMethods[strtolower($method)] = true;
|
||||
}
|
||||
|
||||
@@ -48,9 +50,21 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (\PHP_VERSION_ID >= 80000 && $r->getAttributes(Required::class)) {
|
||||
if ($this->isWither($r, $r->getDocComment() ?: '')) {
|
||||
$withers[] = [$r->name, [], true];
|
||||
} else {
|
||||
$value->addMethodCall($r->name, []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (false !== $doc = $r->getDocComment()) {
|
||||
if (false !== stripos($doc, '@required') && preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc)) {
|
||||
$value->addMethodCall($reflectionMethod->name);
|
||||
if ($this->isWither($reflectionMethod, $doc)) {
|
||||
$withers[] = [$reflectionMethod->name, [], true];
|
||||
} else {
|
||||
$value->addMethodCall($reflectionMethod->name, []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (false === stripos($doc, '@inheritdoc') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+(?:\{@inheritdoc\}|@inheritdoc)(?:\s|\*/$)#i', $doc)) {
|
||||
@@ -65,6 +79,31 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
|
||||
}
|
||||
}
|
||||
|
||||
if ($withers) {
|
||||
// Prepend withers to prevent creating circular loops
|
||||
$setters = $value->getMethodCalls();
|
||||
$value->setMethodCalls($withers);
|
||||
foreach ($setters as $call) {
|
||||
$value->addMethodCall($call[0], $call[1], $call[2] ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function isWither(\ReflectionMethod $reflectionMethod, string $doc): bool
|
||||
{
|
||||
$match = preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@return\s++(static|\$this)[\s\*]#i', $doc, $matches);
|
||||
if ($match && 'static' === $matches[1]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($match && '$this' === $matches[1]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$reflectionType = $reflectionMethod->hasReturnType() ? $reflectionMethod->getReturnType() : null;
|
||||
|
||||
return $reflectionType instanceof \ReflectionNamedType && 'static' === $reflectionType->getName();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user