From 8dbf54f4310b4f7e46345855923604d6e687dc67 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 7 Jan 2026 14:55:54 +0100 Subject: [PATCH 1/3] Fix services configuration, remove code for old SF kernels. --- Command/ImportTranslationsCommand.php | 10 ---- .../Compiler/TranslatorPass.php | 13 ++--- .../LexikTranslationExtension.php | 47 +------------------ Resources/config/services.xml | 28 +++++------ 4 files changed, 19 insertions(+), 79 deletions(-) diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index daaa12cd..c0880e95 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -84,17 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $bundleName = $this->input->getArgument('bundle'); if ($bundleName) { $bundle = $this->getApplication()->getKernel()->getBundle($bundleName); - - if (Kernel::VERSION_ID < 40000 && null !== $bundle->getParent()) { - // due to symfony's bundle inheritance if a bundle has a parent it is fetched first. - // so we tell getBundle to NOT fetch the first if a parent is present - $bundles = $this->getApplication()->getKernel()->getBundle($bundle->getParent(), false); - $bundle = $bundles[1]; - $this->output->writeln('Using: ' . $bundle->getName() . ' as bundle to lookup translations files for.'); - } - $this->importBundleTranslationFiles($bundle, $locales, $domains, (bool)$this->input->getOption('globals')); - } else { if (!$this->input->getOption('import-path')) { diff --git a/DependencyInjection/Compiler/TranslatorPass.php b/DependencyInjection/Compiler/TranslatorPass.php index 2c4f8740..49a7b702 100644 --- a/DependencyInjection/Compiler/TranslatorPass.php +++ b/DependencyInjection/Compiler/TranslatorPass.php @@ -8,7 +8,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\Kernel; /** * Translator compiler pass to automatically pass loader to the other services. @@ -39,15 +38,11 @@ public function process(ContainerBuilder $container): void } if ($container->hasDefinition('lexik_translation.translator')) { - if (Kernel::VERSION_ID >= 30300) { - $serviceRefs = [...$loadersReferencesById, ...['event_dispatcher' => new Reference('event_dispatcher')]]; + $serviceRefs = [...$loadersReferencesById, ...['event_dispatcher' => new Reference('event_dispatcher')]]; - $container->findDefinition('lexik_translation.translator') - ->replaceArgument(0, ServiceLocatorTagPass::register($container, $serviceRefs)) - ->replaceArgument(3, $loaders); - } else { - $container->findDefinition('lexik_translation.translator')->replaceArgument(2, $loaders); - } + $container->findDefinition('lexik_translation.translator') + ->replaceArgument(0, ServiceLocatorTagPass::register($container, $serviceRefs)) + ->replaceArgument(3, $loaders); } if ($container->hasDefinition(FileImporter::class)) { diff --git a/DependencyInjection/LexikTranslationExtension.php b/DependencyInjection/LexikTranslationExtension.php index e51bed1a..b7af40ef 100644 --- a/DependencyInjection/LexikTranslationExtension.php +++ b/DependencyInjection/LexikTranslationExtension.php @@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\Kernel; @@ -62,7 +61,6 @@ public function load(array $configs, ContainerBuilder $container): void $objectManager = $config['storage']['object_manager'] ?? null; - $this->buildTranslatorDefinition($container); $this->buildTranslationStorageDefinition($container, $config['storage']['type'], $objectManager); if (true === $config['auto_cache_clean']) { @@ -76,44 +74,6 @@ public function load(array $configs, ContainerBuilder $container): void $this->registerTranslatorConfiguration($config, $container); } - public function buildTranslatorDefinition(ContainerBuilder $container) - { - $translator = new Definition(); - $translator->setClass('%lexik_translation.translator.class%'); - - if (Kernel::VERSION_ID >= 30400) { - $arguments = [ - new Reference('service_container'), // Will be replaced by service locator - new Reference('translator.formatter.default'), - new Parameter('kernel.default_locale'), - [], // translation loaders - new Parameter('lexik_translation.translator.options') - ]; - $translator->setPublic(true); - } elseif (Kernel::VERSION_ID >= 30300) { - $arguments = [ - new Reference('service_container'), // Will be replaced by service locator - new Reference('translator.selector'), - new Parameter('kernel.default_locale'), - [], // translation loaders - new Parameter('lexik_translation.translator.options') - ]; - } else { - $arguments = [ - new Reference('service_container'), - new Reference('translator.selector'), - [], // translation loaders - new Parameter('lexik_translation.translator.options') - ]; - } - - $translator->setArguments($arguments); - $translator->addMethodCall('setConfigCacheFactory', [new Reference('config_cache_factory')]); - $translator->addTag('kernel.locale_aware'); - - $container->setDefinition('lexik_translation.translator', $translator); - } - /** * @param int $cacheInterval */ @@ -201,7 +161,7 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container protected function createDoctrineMappingDriver(ContainerBuilder $container, $driverId, $driverClass) { $driverDefinition = new Definition($driverClass, [ - [realpath(__DIR__.'/../Resources/config/model') => 'Lexik\Bundle\TranslationBundle\Model'], + [dirname(__DIR__) . '/Resources/config/model' => 'Lexik\Bundle\TranslationBundle\Model'], SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION, true ]); $driverDefinition->setPublic(false); @@ -232,10 +192,7 @@ protected function registerTranslatorConfiguration(array $config, ContainerBuild { // use the Lexik translator as default translator service $alias = $container->setAlias('translator', 'lexik_translation.translator'); - - if (Kernel::VERSION_ID >= 30400) { - $alias->setPublic(true); - } + $alias->setPublic(true); $translator = $container->findDefinition('lexik_translation.translator'); $translator->addMethodCall('setFallbackLocales', [$config['fallback_locale']]); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 4b587f5c..52ad7914 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -5,7 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Lexik\Bundle\TranslationBundle\Translation\Translator Lexik\Bundle\TranslationBundle\Translation\Loader\DatabaseLoader Lexik\Bundle\TranslationBundle\Manager\TransUnitManager Lexik\Bundle\TranslationBundle\Manager\FileManager @@ -48,29 +47,28 @@ false 15 - - - %kernel.cache_dir%/translations - %kernel.debug% - %lexik_translation.resources_type% - - - - - - - - %kernel.cache_dir% + + + + + + + %kernel.cache_dir%/translations %kernel.debug% + %lexik_translation.resources_type% + + + + - + From f706db48925ef40f0276052c12c2c097cfee052b Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 7 Jan 2026 15:21:49 +0100 Subject: [PATCH 2/3] Add symfony/var-exporter in require-dev to fix lazy objects error in tests --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 52d0b386..b74da684 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,8 @@ "mongodb/mongodb": "^1.21.0 || ^2.0.0", "phpunit/phpunit": "^9.5|^10.0", "rector/jack": "^0.2.3", - "rector/rector": "^0.14.8|^0.15" + "rector/rector": "^0.14.8|^0.15", + "symfony/var-exporter": "^7.0" }, "autoload": { "psr-4": { @@ -72,4 +73,3 @@ "sort-packages": true } } - From 0e96cf1d14e9b479eea1ecf212e3d18823b9d4bf Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 26 Jan 2026 23:42:21 +0100 Subject: [PATCH 3/3] Fix conflicts --- Resources/config/services.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index 91080d8b..3219ba58 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -43,32 +43,34 @@ parameters: lexik_translation.importer.case_insensitive: false lexik_translation.token_finder.limit: 15 - lexik_translation.translator.options: - cache_dir: '%kernel.cache_dir%/translations' - debug: '%kernel.debug%' - resources_type: '%lexik_translation.resources_type%' - services: _defaults: autowire: true autoconfigure: true # Translator - Lexik\Bundle\TranslationBundle\Translation\Translator: + lexik_translation.translator: + class: Lexik\Bundle\TranslationBundle\Translation\Translator arguments: $container: '@service_container' $formatter: '@translator.formatter.default' $defaultLocale: '%kernel.default_locale%' $loaderIds: [] $options: - cache_dir: '%kernel.cache_dir%' + cache_dir: '%kernel.cache_dir%/translations' debug: '%kernel.debug%' resource_files: [] scanned_directories: [] cache_vary: [] + resources_type: '%lexik_translation.resources_type%' + calls: + - [setConfigCacheFactory, ['@config_cache_factory']] + tags: + - { name: kernel.locale_aware } + public: true - lexik_translation.translator: - alias: Lexik\Bundle\TranslationBundle\Translation\Translator + Lexik\Bundle\TranslationBundle\Translation\Translator: + alias: lexik_translation.translator public: true # TranslatorDecorator alias for backward compatibility