@@ -33,45 +33,45 @@ public function process(ContainerBuilder $container): void
3333 // Models now use PHP attributes, so we need to use AttributeDriver
3434 // Create attribute driver if it doesn't exist (fallback if Extension didn't create it)
3535 $ attributeDriverId = 'lexik_translation.orm.metadata.attribute ' ;
36-
36+
3737 // Ensure attribute driver exists - create it if Extension didn't create it
3838 if (!$ container ->hasDefinition ($ attributeDriverId )) {
3939 // Calculate bundle path using ReflectionClass
4040 $ bundleReflection = new \ReflectionClass (\Lexik \Bundle \TranslationBundle \LexikTranslationBundle::class);
4141 $ bundleDir = dirname ($ bundleReflection ->getFileName ());
4242 $ modelPath = $ bundleDir . '/Model ' ;
43-
43+
4444 // Try to get realpath
4545 $ realModelPath = realpath ($ modelPath );
4646 if ($ realModelPath ) {
4747 $ modelPath = $ realModelPath ;
4848 }
49-
49+
5050 // Create AttributeDriver service
5151 $ driverDefinition = new Definition (AttributeDriver::class, [
5252 [$ modelPath ]
5353 ]);
5454 $ driverDefinition ->setPublic (false );
5555 $ container ->setDefinition ($ attributeDriverId , $ driverDefinition );
5656 }
57-
57+
5858 // Register attribute driver for models namespace
5959 // IMPORTANT: We need to check if it's already registered to avoid duplicates
6060 $ ormDriver = $ container ->getDefinition ($ ormDriverId );
6161 $ methodCalls = $ ormDriver ->getMethodCalls ();
62-
62+
6363 // Check if attribute driver is already registered
6464 $ attributeDriverRegistered = false ;
6565 foreach ($ methodCalls as $ call ) {
66- if ($ call [0 ] === 'addDriver ' &&
67- isset ($ call [1 ][0 ]) &&
66+ if ($ call [0 ] === 'addDriver ' &&
67+ isset ($ call [1 ][0 ]) &&
6868 $ call [1 ][0 ] instanceof Reference &&
6969 (string )$ call [1 ][0 ] === $ attributeDriverId ) {
7070 $ attributeDriverRegistered = true ;
7171 break ;
7272 }
7373 }
74-
74+
7575 // Register XML driver for Entity namespace FIRST (entities use XML mapping)
7676 // This must be registered before Model namespace to ensure entities are recognized
7777 // Create XML driver for entities if it doesn't exist
@@ -81,14 +81,18 @@ public function process(ContainerBuilder $container): void
8181 $ bundleReflection = new \ReflectionClass (\Lexik \Bundle \TranslationBundle \LexikTranslationBundle::class);
8282 $ bundleDir = dirname ($ bundleReflection ->getFileName ());
8383 $ doctrinePath = $ bundleDir . '/Resources/config/doctrine ' ;
84-
84+
8585 $ realDoctrinePath = realpath ($ doctrinePath );
8686 if ($ realDoctrinePath ) {
8787 $ doctrinePath = $ realDoctrinePath ;
8888 }
89-
90- // Create XML driver for entities using the same class as the model XML driver
91- $ xmlDriverClass = $ container ->getParameter ('doctrine.orm.metadata.xml.class ' );
89+
90+ // Create XML driver for entities using SimplifiedXmlDriver
91+ if (class_exists (SimplifiedXmlDriver::class)) {
92+ $ xmlDriverClass = SimplifiedXmlDriver::class;
93+ } else {
94+ $ xmlDriverClass = $ container ->getParameter ('doctrine.orm.metadata.xml.class ' );
95+ }
9296 $ entityDriverDefinition = new Definition ($ xmlDriverClass , [
9397 [$ doctrinePath => 'Lexik\Bundle\TranslationBundle\Entity ' ],
9498 SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION ,
@@ -97,18 +101,18 @@ public function process(ContainerBuilder $container): void
97101 $ entityDriverDefinition ->setPublic (false );
98102 $ container ->setDefinition ($ entityXmlDriverId , $ entityDriverDefinition );
99103 }
100-
104+
101105 // Register XML driver for Entity namespace FIRST
102106 $ entityDriverRegistered = false ;
103107 foreach ($ methodCalls as $ call ) {
104- if ($ call [0 ] === 'addDriver ' &&
105- isset ($ call [1 ][1 ]) &&
108+ if ($ call [0 ] === 'addDriver ' &&
109+ isset ($ call [1 ][1 ]) &&
106110 $ call [1 ][1 ] === 'Lexik\Bundle\TranslationBundle\Entity ' ) {
107111 $ entityDriverRegistered = true ;
108112 break ;
109113 }
110114 }
111-
115+
112116 if (!$ entityDriverRegistered && $ container ->hasDefinition ($ entityXmlDriverId )) {
113117 // Insert at the beginning to ensure Entity namespace is processed first
114118 $ newMethodCalls = [[
@@ -121,15 +125,15 @@ public function process(ContainerBuilder $container): void
121125 $ ormDriver ->setMethodCalls ($ newMethodCalls );
122126 $ methodCalls = $ newMethodCalls ; // Update for next checks
123127 }
124-
128+
125129 // Register attribute driver if not already registered
126130 if (!$ attributeDriverRegistered && $ container ->hasDefinition ($ attributeDriverId )) {
127131 // Remove any existing registration for the Model namespace (XML driver)
128132 $ newMethodCalls = [];
129133 foreach ($ methodCalls as $ call ) {
130134 // Skip XML driver registration for Model namespace
131- if ($ call [0 ] === 'addDriver ' &&
132- isset ($ call [1 ][1 ]) &&
135+ if ($ call [0 ] === 'addDriver ' &&
136+ isset ($ call [1 ][1 ]) &&
133137 $ call [1 ][1 ] === 'Lexik\Bundle\TranslationBundle\Model ' &&
134138 isset ($ call [1 ][0 ]) &&
135139 $ call [1 ][0 ] instanceof Reference &&
@@ -139,13 +143,13 @@ public function process(ContainerBuilder $container): void
139143 }
140144 $ newMethodCalls [] = $ call ;
141145 }
142-
146+
143147 // Add attribute driver for Model namespace
144148 $ newMethodCalls [] = [
145149 'addDriver ' ,
146150 [new Reference ($ attributeDriverId ), 'Lexik\Bundle\TranslationBundle\Model ' ]
147151 ];
148-
152+
149153 // Update method calls
150154 $ ormDriver ->setMethodCalls ($ newMethodCalls );
151155 } elseif (!$ container ->hasDefinition ($ attributeDriverId ) && $ container ->hasDefinition ('lexik_translation.orm.metadata.xml ' )) {
0 commit comments