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:
bdalsass
2022-06-16 09:13:24 +02:00
committed by GitHub
parent abb13b70b9
commit 79da71ecf8
2178 changed files with 87439 additions and 59451 deletions

View File

@@ -13,6 +13,10 @@ namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Reference;
/**
* Overwrites a service but keeps the overridden one.
@@ -21,8 +25,19 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
* @author Fabien Potencier <fabien@symfony.com>
* @author Diego Saint Esteben <diego@saintesteben.me>
*/
class DecoratorServicePass implements CompilerPassInterface
class DecoratorServicePass extends AbstractRecursivePass
{
private $innerId = '.inner';
public function __construct(?string $innerId = '.inner')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}
$this->innerId = $innerId;
}
public function process(ContainerBuilder $container)
{
$definitions = new \SplPriorityQueue();
@@ -36,8 +51,14 @@ class DecoratorServicePass implements CompilerPassInterface
}
$decoratingDefinitions = [];
foreach ($definitions as list($id, $definition)) {
list($inner, $renamedId) = $definition->getDecoratedService();
$tagsToKeep = $container->hasParameter('container.behavior_describing_tags')
? $container->getParameter('container.behavior_describing_tags')
: ['container.do_not_inline', 'container.service_locator', 'container.service_subscriber'];
foreach ($definitions as [$id, $definition]) {
$decoratedService = $definition->getDecoratedService();
[$inner, $renamedId] = $decoratedService;
$invalidBehavior = $decoratedService[3] ?? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
$definition->setDecoratedService(null);
@@ -45,37 +66,68 @@ class DecoratorServicePass implements CompilerPassInterface
$renamedId = $id.'.inner';
}
$this->currentId = $renamedId;
$this->processValue($definition);
$definition->innerServiceId = $renamedId;
$definition->decorationOnInvalid = $invalidBehavior;
// we create a new alias/service for the service we are replacing
// to be able to reference it in the new one
if ($container->hasAlias($inner)) {
$alias = $container->getAlias($inner);
$public = $alias->isPublic();
$private = $alias->isPrivate();
$container->setAlias($renamedId, new Alias($container->normalizeId($alias), false));
} else {
$container->setAlias($renamedId, new Alias((string) $alias, false));
$decoratedDefinition = $container->findDefinition($alias);
} elseif ($container->hasDefinition($inner)) {
$decoratedDefinition = $container->getDefinition($inner);
$public = $decoratedDefinition->isPublic();
$private = $decoratedDefinition->isPrivate();
$decoratedDefinition->setPublic(false);
$container->setDefinition($renamedId, $decoratedDefinition);
$decoratingDefinitions[$inner] = $decoratedDefinition;
} elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {
$container->removeDefinition($id);
continue;
} elseif (ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
$public = $definition->isPublic();
$decoratedDefinition = null;
} else {
throw new ServiceNotFoundException($inner, $id);
}
if ($decoratedDefinition && $decoratedDefinition->isSynthetic()) {
throw new InvalidArgumentException(sprintf('A synthetic service cannot be decorated: service "%s" cannot decorate "%s".', $id, $inner));
}
if (isset($decoratingDefinitions[$inner])) {
$decoratingDefinition = $decoratingDefinitions[$inner];
$definition->setTags(array_merge($decoratingDefinition->getTags(), $definition->getTags()));
$autowiringTypes = $decoratingDefinition->getAutowiringTypes(false);
if ($types = array_merge($autowiringTypes, $definition->getAutowiringTypes(false))) {
$definition->setAutowiringTypes($types);
}
$decoratingDefinition->setTags([]);
if ($autowiringTypes) {
$decoratingDefinition->setAutowiringTypes([]);
$decoratingTags = $decoratingDefinition->getTags();
$resetTags = [];
// Behavior-describing tags must not be transferred out to decorators
foreach ($tagsToKeep as $containerTag) {
if (isset($decoratingTags[$containerTag])) {
$resetTags[$containerTag] = $decoratingTags[$containerTag];
unset($decoratingTags[$containerTag]);
}
}
$definition->setTags(array_merge($decoratingTags, $definition->getTags()));
$decoratingDefinition->setTags($resetTags);
$decoratingDefinitions[$inner] = $definition;
}
$container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
$container->setAlias($inner, $id)->setPublic($public);
}
}
protected function processValue($value, bool $isRoot = false)
{
if ($value instanceof Reference && $this->innerId === (string) $value) {
return new Reference($this->currentId, $value->getInvalidBehavior());
}
return parent::processValue($value, $isRoot);
}
}