diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index 7c890af6..04a9e672 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -107,17 +107,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 472f3dbf..eda7d70b 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. @@ -50,24 +49,16 @@ public function process(ContainerBuilder $container): void if ($translatorId && $container->hasDefinition($translatorId)) { $translatorDef = $container->findDefinition($translatorId); - - if (Kernel::VERSION_ID >= 30300) { - $serviceRefs = [...$loadersReferencesById, ...['event_dispatcher' => new Reference('event_dispatcher')]]; - // Use named arguments if available, otherwise use numeric indices - if ($translatorDef->getArguments() && array_key_exists('$container', $translatorDef->getArguments())) { - $translatorDef->replaceArgument('$container', ServiceLocatorTagPass::register($container, $serviceRefs)); - $translatorDef->replaceArgument('$loaderIds', $loaders); - } else { - $translatorDef->replaceArgument(0, ServiceLocatorTagPass::register($container, $serviceRefs)); - $translatorDef->replaceArgument(3, $loaders); - } + $serviceRefs = [...$loadersReferencesById, ...['event_dispatcher' => new Reference('event_dispatcher')]]; + + // Use named arguments if available, otherwise use numeric indices + if ($translatorDef->getArguments() && array_key_exists('$container', $translatorDef->getArguments())) { + $translatorDef->replaceArgument('$container', ServiceLocatorTagPass::register($container, $serviceRefs)); + $translatorDef->replaceArgument('$loaderIds', $loaders); } else { - if ($translatorDef->getArguments() && array_key_exists('$loaderIds', $translatorDef->getArguments())) { - $translatorDef->replaceArgument('$loaderIds', $loaders); - } else { - $translatorDef->replaceArgument(2, $loaders); - } + $translatorDef->replaceArgument(0, ServiceLocatorTagPass::register($container, $serviceRefs)); + $translatorDef->replaceArgument(3, $loaders); } } diff --git a/DependencyInjection/LexikTranslationExtension.php b/DependencyInjection/LexikTranslationExtension.php index 33589d5e..54846d6d 100644 --- a/DependencyInjection/LexikTranslationExtension.php +++ b/DependencyInjection/LexikTranslationExtension.php @@ -20,7 +20,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; @@ -63,9 +62,6 @@ public function load(array $configs, ContainerBuilder $container): void $objectManager = $config['storage']['object_manager'] ?? null; - // Translator is now handled via service decoration in services.yaml - // buildTranslatorDefinition() is deprecated and no longer needed for Symfony 8 - // $this->buildTranslatorDefinition($container); $this->buildTranslationStorageDefinition($container, $config['storage']['type'], $objectManager); if (true === $config['auto_cache_clean']) { @@ -79,44 +75,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 */ @@ -167,7 +125,7 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container // Create XML driver for backward compatibility $this->createDoctrineMappingDriver($container, 'lexik_translation.orm.metadata.xml', '%doctrine.orm.metadata.xml.class%'); - + // Create attribute driver for models (MappedSuperclass) that now use PHP attributes $this->createDoctrineAttributeDriver($container, 'lexik_translation.orm.metadata.attribute'); @@ -208,7 +166,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); @@ -229,20 +187,20 @@ protected function createDoctrineAttributeDriver(ContainerBuilder $container, $d $bundleReflection = new \ReflectionClass(\Lexik\Bundle\TranslationBundle\LexikTranslationBundle::class); $bundleDir = dirname($bundleReflection->getFileName()); $modelPath = $bundleDir . '/Model'; - + // Try to get realpath, but use the calculated path if it fails $realModelPath = realpath($modelPath); if ($realModelPath) { $modelPath = $realModelPath; } - + // AttributeDriver constructor expects an array of paths (directories to scan) // It will automatically detect classes with #[ORM\MappedSuperclass] or #[ORM\Entity] attributes $driverDefinition = new Definition(AttributeDriver::class, [ [$modelPath] ]); $driverDefinition->setPublic(false); - + // Always set/override the definition to ensure it exists with correct arguments $container->setDefinition($driverId, $driverDefinition); } @@ -270,19 +228,16 @@ protected function registerTranslatorConfiguration(array $config, ContainerBuild { // use the Lexik translator decorator as default translator service $alias = $container->setAlias('translator', 'lexik_translation.translator'); - - if (Kernel::VERSION_ID >= 30400) { - $alias->setPublic(true); - } + $alias->setPublic(true); // Get the inner translator (the actual Symfony translator) for adding resources // The decorator will delegate to it $innerTranslator = $container->hasDefinition('lexik_translation.translator.inner') ? $container->findDefinition('lexik_translation.translator.inner') : $container->findDefinition('translator'); - + $innerTranslator->addMethodCall('setFallbackLocales', [$config['fallback_locale']]); - + // For adding file resources, we'll add them to the inner translator $translator = $innerTranslator; 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% + + + + - + 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 diff --git a/composer.json b/composer.json index fe3a4e09..dd3b1d3c 100644 --- a/composer.json +++ b/composer.json @@ -73,4 +73,3 @@ "sort-packages": true } } -