2020use Symfony \Component \DependencyInjection \Parameter ;
2121use Symfony \Component \DependencyInjection \Definition ;
2222use Symfony \Component \DependencyInjection \ContainerBuilder ;
23- use Symfony \Component \DependencyInjection \Loader ;
2423use Symfony \Component \Finder \Finder ;
2524use Symfony \Component \HttpKernel \Kernel ;
2625
@@ -63,9 +62,6 @@ public function load(array $configs, ContainerBuilder $container): void
6362
6463 $ objectManager = $ config ['storage ' ]['object_manager ' ] ?? null ;
6564
66- // Translator is now handled via service decoration in services.yaml
67- // buildTranslatorDefinition() is deprecated and no longer needed for Symfony 8
68- // $this->buildTranslatorDefinition($container);
6965 $ this ->buildTranslationStorageDefinition ($ container , $ config ['storage ' ]['type ' ], $ objectManager );
7066
7167 if (true === $ config ['auto_cache_clean ' ]) {
@@ -79,44 +75,6 @@ public function load(array $configs, ContainerBuilder $container): void
7975 $ this ->registerTranslatorConfiguration ($ config , $ container );
8076 }
8177
82- public function buildTranslatorDefinition (ContainerBuilder $ container )
83- {
84- $ translator = new Definition ();
85- $ translator ->setClass ('%lexik_translation.translator.class% ' );
86-
87- if (Kernel::VERSION_ID >= 30400 ) {
88- $ arguments = [
89- new Reference ('service_container ' ), // Will be replaced by service locator
90- new Reference ('translator.formatter.default ' ),
91- new Parameter ('kernel.default_locale ' ),
92- [], // translation loaders
93- new Parameter ('lexik_translation.translator.options ' )
94- ];
95- $ translator ->setPublic (true );
96- } elseif (Kernel::VERSION_ID >= 30300 ) {
97- $ arguments = [
98- new Reference ('service_container ' ), // Will be replaced by service locator
99- new Reference ('translator.selector ' ),
100- new Parameter ('kernel.default_locale ' ),
101- [], // translation loaders
102- new Parameter ('lexik_translation.translator.options ' )
103- ];
104- } else {
105- $ arguments = [
106- new Reference ('service_container ' ),
107- new Reference ('translator.selector ' ),
108- [], // translation loaders
109- new Parameter ('lexik_translation.translator.options ' )
110- ];
111- }
112-
113- $ translator ->setArguments ($ arguments );
114- $ translator ->addMethodCall ('setConfigCacheFactory ' , [new Reference ('config_cache_factory ' )]);
115- $ translator ->addTag ('kernel.locale_aware ' );
116-
117- $ container ->setDefinition ('lexik_translation.translator ' , $ translator );
118- }
119-
12078 /**
12179 * @param int $cacheInterval
12280 */
@@ -167,7 +125,7 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container
167125
168126 // Create XML driver for backward compatibility
169127 $ this ->createDoctrineMappingDriver ($ container , 'lexik_translation.orm.metadata.xml ' , '%doctrine.orm.metadata.xml.class% ' );
170-
128+
171129 // Create attribute driver for models (MappedSuperclass) that now use PHP attributes
172130 $ this ->createDoctrineAttributeDriver ($ container , 'lexik_translation.orm.metadata.attribute ' );
173131
@@ -208,7 +166,7 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container
208166 protected function createDoctrineMappingDriver (ContainerBuilder $ container , $ driverId , $ driverClass )
209167 {
210168 $ driverDefinition = new Definition ($ driverClass , [
211- [realpath (__DIR__ . ' /../ Resources/config/model ') => 'Lexik\Bundle\TranslationBundle\Model ' ],
169+ [dirname (__DIR__ ) . ' / Resources/config/model ' => 'Lexik\Bundle\TranslationBundle\Model ' ],
212170 SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION , true
213171 ]);
214172 $ driverDefinition ->setPublic (false );
@@ -229,20 +187,20 @@ protected function createDoctrineAttributeDriver(ContainerBuilder $container, $d
229187 $ bundleReflection = new \ReflectionClass (\Lexik \Bundle \TranslationBundle \LexikTranslationBundle::class);
230188 $ bundleDir = dirname ($ bundleReflection ->getFileName ());
231189 $ modelPath = $ bundleDir . '/Model ' ;
232-
190+
233191 // Try to get realpath, but use the calculated path if it fails
234192 $ realModelPath = realpath ($ modelPath );
235193 if ($ realModelPath ) {
236194 $ modelPath = $ realModelPath ;
237195 }
238-
196+
239197 // AttributeDriver constructor expects an array of paths (directories to scan)
240198 // It will automatically detect classes with #[ORM\MappedSuperclass] or #[ORM\Entity] attributes
241199 $ driverDefinition = new Definition (AttributeDriver::class, [
242200 [$ modelPath ]
243201 ]);
244202 $ driverDefinition ->setPublic (false );
245-
203+
246204 // Always set/override the definition to ensure it exists with correct arguments
247205 $ container ->setDefinition ($ driverId , $ driverDefinition );
248206 }
@@ -270,19 +228,16 @@ protected function registerTranslatorConfiguration(array $config, ContainerBuild
270228 {
271229 // use the Lexik translator decorator as default translator service
272230 $ alias = $ container ->setAlias ('translator ' , 'lexik_translation.translator ' );
273-
274- if (Kernel::VERSION_ID >= 30400 ) {
275- $ alias ->setPublic (true );
276- }
231+ $ alias ->setPublic (true );
277232
278233 // Get the inner translator (the actual Symfony translator) for adding resources
279234 // The decorator will delegate to it
280235 $ innerTranslator = $ container ->hasDefinition ('lexik_translation.translator.inner ' )
281236 ? $ container ->findDefinition ('lexik_translation.translator.inner ' )
282237 : $ container ->findDefinition ('translator ' );
283-
238+
284239 $ innerTranslator ->addMethodCall ('setFallbackLocales ' , [$ config ['fallback_locale ' ]]);
285-
240+
286241 // For adding file resources, we'll add them to the inner translator
287242 $ translator = $ innerTranslator ;
288243
0 commit comments