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:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -20,10 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
*/
class AddAnnotationsCachedReaderPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
// "annotations.cached_reader" is wired late so that any passes using
// "annotation_reader" at build time don't get any cache

View File

@@ -17,6 +17,9 @@ use Symfony\Component\DependencyInjection\Reference;
class AddDebugLogProcessorPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('profiler')) {
@@ -29,13 +32,19 @@ class AddDebugLogProcessorPass implements CompilerPassInterface
return;
}
$definition = $container->getDefinition('monolog.logger_prototype');
$definition->setConfigurator([__CLASS__, 'configureLogger']);
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
$container->getDefinition('monolog.logger_prototype')
->setConfigurator([new Reference('debug.debug_logger_configurator'), 'pushDebugLogger']);
}
public static function configureLogger($logger)
/**
* @deprecated since Symfony 6.4, use HttpKernel's DebugLoggerConfigurator instead
*
* @return void
*/
public static function configureLogger(mixed $logger)
{
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s()" method is deprecated, use HttpKernel\'s DebugLoggerConfigurator instead.', __METHOD__);
if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$logger->removeDebugLogger();
}

View File

@@ -15,15 +15,19 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AddExpressionLanguageProvidersPass::class, \Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass::class);
/**
* Registers the expression language providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 6.4, use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass instead.
*/
class AddExpressionLanguageProvidersPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
* @return void
*/
public function process(ContainerBuilder $container)
{

View File

@@ -18,6 +18,9 @@ use Symfony\Component\DependencyInjection\Reference;
class AssetsContextPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('assets.context')) {

View File

@@ -25,8 +25,15 @@ use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
*/
class ContainerBuilderDebugDumpPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->getParameter('debug.container.dump')) {
return;
}
$cache = new ConfigCache($container->getParameter('debug.container.dump'), true);
if (!$cache->isFresh()) {
$cache->write((new XmlDumper($container))->dump(), $container->getResources());

View File

@@ -13,12 +13,20 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Translation\TranslatorBagInterface;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', DataCollectorTranslatorPass::class, \Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass::class);
/**
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
*
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass instead.
*/
class DataCollectorTranslatorPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('translator')) {
@@ -27,7 +35,7 @@ class DataCollectorTranslatorPass implements CompilerPassInterface
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
if (!is_subclass_of($translatorClass, 'Symfony\Component\Translation\TranslatorBagInterface')) {
if (!is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
$container->removeDefinition('translator.data_collector');
$container->removeDefinition('data_collector.translation');
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use argument $debug of HttpKernel\'s Logger instead.', EnableLoggerDebugModePass::class);
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Log\Logger;
/**
* @deprecated since Symfony 6.4, use argument $debug of HttpKernel's Logger instead
*/
final class EnableLoggerDebugModePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('profiler') || !$container->hasDefinition('logger')) {
return;
}
$loggerDefinition = $container->getDefinition('logger');
if (Logger::class === $loggerDefinition->getClass()) {
$loggerDefinition->setConfigurator([__CLASS__, 'configureLogger']);
}
}
public static function configureLogger(Logger $logger): void
{
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$logger->enableDebug();
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* @internal
*/
class ErrorLoggerCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('debug.error_handler_configurator')) {
return;
}
$definition = $container->getDefinition('debug.error_handler_configurator');
if ($container->hasDefinition('monolog.logger.php')) {
$definition->replaceArgument(0, new Reference('monolog.logger.php'));
}
if ($container->hasDefinition('monolog.logger.deprecation')) {
$definition->replaceArgument(5, new Reference('monolog.logger.deprecation'));
}
}
}

View File

@@ -17,11 +17,18 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Translation\TranslatorBagInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', LoggingTranslatorPass::class, \Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass::class);
/**
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
*
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass instead.
*/
class LoggingTranslatorPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {

View File

@@ -24,6 +24,9 @@ use Symfony\Component\DependencyInjection\Reference;
*/
class ProfilerPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (false === $container->hasDefinition('profiler')) {
@@ -39,8 +42,7 @@ class ProfilerPass implements CompilerPassInterface
$template = null;
$collectorClass = $container->findDefinition($id)->getClass();
$isTemplateAware = is_subclass_of($collectorClass, TemplateAwareDataCollectorInterface::class);
if (isset($attributes[0]['template']) || $isTemplateAware) {
if (isset($attributes[0]['template']) || is_subclass_of($collectorClass, TemplateAwareDataCollectorInterface::class)) {
$idForTemplate = $attributes[0]['id'] ?? $collectorClass;
if (!$idForTemplate) {
throw new InvalidArgumentException(sprintf('Data collector service "%s" must have an id attribute in order to specify a template.', $id));

View File

@@ -19,6 +19,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
*/
class RemoveUnusedSessionMarshallingHandlerPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('session.marshalling_handler')) {

View File

@@ -1,72 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* @internal to be removed in 6.0
*/
class SessionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->has('session.factory')) {
return;
}
// BC layer: Make "session" an alias of ".session.do-not-use" when not overridden by the user
if (!$container->has('session')) {
$alias = $container->setAlias('session', '.session.do-not-use');
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
// restore previous behavior
$alias->setPublic(true);
return;
}
if ($container->hasDefinition('session')) {
$definition = $container->getDefinition('session');
$definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
} else {
$alias = $container->getAlias('session');
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.');
$definition = $container->findDefinition('session');
}
// Convert internal service `.session.do-not-use` into alias of `session`.
$container->setAlias('.session.do-not-use', 'session');
$bags = [
'session.flash_bag' => $container->hasDefinition('session.flash_bag') ? $container->getDefinition('session.flash_bag') : null,
'session.attribute_bag' => $container->hasDefinition('session.attribute_bag') ? $container->getDefinition('session.attribute_bag') : null,
];
foreach ($definition->getArguments() as $v) {
if (!$v instanceof Reference || !isset($bags[$bag = (string) $v]) || !\is_array($factory = $bags[$bag]->getFactory())) {
continue;
}
if ([0, 1] !== array_keys($factory) || !$factory[0] instanceof Reference || !\in_array((string) $factory[0], ['session', '.session.do-not-use'], true)) {
continue;
}
if ('get'.ucfirst(substr($bag, 8, -4)).'Bag' !== $factory[1]) {
continue;
}
$bags[$bag]->setFactory(null);
}
}
}

View File

@@ -21,6 +21,9 @@ use Symfony\Component\DependencyInjection\Reference;
*/
class TestServiceContainerRealRefPass implements CompilerPassInterface
{
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('test.private_services_locator')) {
@@ -30,10 +33,17 @@ class TestServiceContainerRealRefPass implements CompilerPassInterface
$privateContainer = $container->getDefinition('test.private_services_locator');
$definitions = $container->getDefinitions();
$privateServices = $privateContainer->getArgument(0);
$renamedIds = [];
foreach ($privateServices as $id => $argument) {
if (isset($definitions[$target = (string) $argument->getValues()[0]])) {
$argument->setValues([new Reference($target)]);
if ($id !== $target) {
$renamedIds[$id] = $target;
}
if ($inner = $definitions[$target]->getTag('container.decorator')[0]['inner'] ?? null) {
$renamedIds[$id] = $inner;
}
} else {
unset($privateServices[$id]);
}
@@ -47,8 +57,14 @@ class TestServiceContainerRealRefPass implements CompilerPassInterface
if ($definitions[$target]->hasTag('container.private')) {
$privateServices[$id] = new ServiceClosureArgument(new Reference($target));
}
$renamedIds[$id] = $target;
}
$privateContainer->replaceArgument(0, $privateServices);
if ($container->hasDefinition('test.service_container') && $renamedIds) {
$container->getDefinition('test.service_container')->setArgument(2, $renamedIds);
}
}
}

View File

@@ -14,7 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
/**
@@ -22,17 +21,9 @@ use Symfony\Component\DependencyInjection\Reference;
*/
class TestServiceContainerWeakRefPass implements CompilerPassInterface
{
private $privateTagName;
public function __construct(string $privateTagName = 'container.private')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/framework-bundle', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}
$this->privateTagName = $privateTagName;
}
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('test.private_services_locator')) {
@@ -41,10 +32,9 @@ class TestServiceContainerWeakRefPass implements CompilerPassInterface
$privateServices = [];
$definitions = $container->getDefinitions();
$hasErrors = method_exists(Definition::class, 'hasErrors') ? 'hasErrors' : 'getErrors';
foreach ($definitions as $id => $definition) {
if ($id && '.' !== $id[0] && (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) && !$definition->$hasErrors() && !$definition->isAbstract()) {
if ($id && '.' !== $id[0] && (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag('container.private')) && !$definition->hasErrors() && !$definition->isAbstract()) {
$privateServices[$id] = new Reference($id, ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE);
}
}
@@ -56,7 +46,7 @@ class TestServiceContainerWeakRefPass implements CompilerPassInterface
while (isset($aliases[$target = (string) $alias])) {
$alias = $aliases[$target];
}
if (isset($definitions[$target]) && !$definitions[$target]->$hasErrors() && !$definitions[$target]->isAbstract()) {
if (isset($definitions[$target]) && !$definitions[$target]->hasErrors() && !$definitions[$target]->isAbstract()) {
$privateServices[$id] = new Reference($target, ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE);
}
}

View File

@@ -24,15 +24,18 @@ class UnusedTagsPass implements CompilerPassInterface
private const KNOWN_TAGS = [
'annotations.cached_reader',
'assets.package',
'asset_mapper.compiler',
'auto_alias',
'cache.pool',
'cache.pool.clearer',
'cache.taggable',
'chatter.transport_factory',
'config_cache.resource_checker',
'console.command',
'container.do_not_inline',
'container.env_var_loader',
'container.env_var_processor',
'container.excluded',
'container.hot_path',
'container.no_preload',
'container.preload',
@@ -44,11 +47,13 @@ class UnusedTagsPass implements CompilerPassInterface
'container.stack',
'controller.argument_value_resolver',
'controller.service_arguments',
'controller.targeted_value_resolver',
'data_collector',
'event_dispatcher.dispatcher',
'form.type',
'form.type_extension',
'form.type_guesser',
'html_sanitizer',
'http_client.client',
'kernel.cache_clearer',
'kernel.cache_warmer',
@@ -71,13 +76,16 @@ class UnusedTagsPass implements CompilerPassInterface
'property_info.list_extractor',
'property_info.type_extractor',
'proxy',
'remote_event.consumer',
'routing.condition_service',
'routing.expression_language_function',
'routing.expression_language_provider',
'routing.loader',
'routing.route_loader',
'scheduler.schedule_provider',
'scheduler.task',
'security.authenticator.login_linker',
'security.expression_language_provider',
'security.remember_me_aware',
'security.remember_me_handler',
'security.voter',
'serializer.encoder',
@@ -85,6 +93,7 @@ class UnusedTagsPass implements CompilerPassInterface
'texter.transport_factory',
'translation.dumper',
'translation.extractor',
'translation.extractor.visitor',
'translation.loader',
'translation.provider_factory',
'twig.extension',
@@ -92,9 +101,14 @@ class UnusedTagsPass implements CompilerPassInterface
'twig.runtime',
'validator.auto_mapper',
'validator.constraint_validator',
'validator.group_provider',
'validator.initializer',
'workflow',
];
/**
* @return void
*/
public function process(ContainerBuilder $container)
{
$tags = array_unique(array_merge($container->findTags(), self::KNOWN_TAGS));
@@ -119,7 +133,7 @@ class UnusedTagsPass implements CompilerPassInterface
$services = array_keys($container->findTaggedServiceIds($tag));
$message = sprintf('Tag "%s" was defined on service(s) "%s", but was never used.', $tag, implode('", "', $services));
if (!empty($candidates)) {
if ($candidates) {
$message .= sprintf(' Did you mean "%s"?', implode('", "', $candidates));
}

View File

@@ -15,14 +15,18 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', WorkflowGuardListenerPass::class, \Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass::class);
/**
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @deprecated since Symfony 6.4, use Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass instead.
*/
class WorkflowGuardListenerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
* @return void
*/
public function process(ContainerBuilder $container)
{