|
5 | 5 | namespace Doctrine\Bundle\MongoDBBundle\DependencyInjection; |
6 | 6 |
|
7 | 7 | use Doctrine\Bundle\MongoDBBundle\Attribute\AsDocumentListener; |
| 8 | +use Doctrine\Bundle\MongoDBBundle\Attribute\MapDocument; |
8 | 9 | use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\FixturesCompilerPass; |
9 | 10 | use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; |
10 | 11 | use Doctrine\Bundle\MongoDBBundle\EventSubscriber\EventSubscriberInterface; |
|
18 | 19 | use InvalidArgumentException; |
19 | 20 | use Jean85\PrettyVersions; |
20 | 21 | use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; |
21 | | -use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
22 | 22 | use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; |
23 | 23 | use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; |
24 | 24 | use Symfony\Component\Cache\Adapter\ApcuAdapter; |
25 | 25 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
26 | 26 | use Symfony\Component\Cache\Adapter\MemcachedAdapter; |
27 | 27 | use Symfony\Component\Cache\Adapter\RedisAdapter; |
28 | 28 | use Symfony\Component\Config\FileLocator; |
| 29 | +use Symfony\Component\Config\Loader\FileLoader; |
29 | 30 | use Symfony\Component\DependencyInjection\Alias; |
30 | 31 | use Symfony\Component\DependencyInjection\ChildDefinition; |
31 | 32 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
@@ -149,39 +150,7 @@ public function load(array $configs, ContainerBuilder $container) |
149 | 150 |
|
150 | 151 | $this->loadMessengerServices($container); |
151 | 152 |
|
152 | | - // available in Symfony 6.2 and higher |
153 | | - if (! class_exists(EntityValueResolver::class)) { |
154 | | - $container->removeDefinition('doctrine_mongodb.odm.entity_value_resolver'); |
155 | | - $container->removeDefinition('doctrine_mongodb.odm.entity_value_resolver.expression_language'); |
156 | | - } else { |
157 | | - if (! class_exists(ExpressionLanguage::class)) { |
158 | | - $container->removeDefinition('doctrine_mongodb.odm.entity_value_resolver.expression_language'); |
159 | | - } |
160 | | - |
161 | | - $controllerResolverDefaults = []; |
162 | | - |
163 | | - if (! $config['controller_resolver']['enabled']) { |
164 | | - $controllerResolverDefaults['disabled'] = true; |
165 | | - } |
166 | | - |
167 | | - if (! $config['controller_resolver']['auto_mapping']) { |
168 | | - $controllerResolverDefaults['mapping'] = []; |
169 | | - } |
170 | | - |
171 | | - if ($controllerResolverDefaults) { |
172 | | - $container->getDefinition('doctrine_mongodb.odm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))->setArguments([ |
173 | | - null, |
174 | | - null, |
175 | | - null, |
176 | | - $controllerResolverDefaults['mapping'] ?? null, |
177 | | - null, |
178 | | - null, |
179 | | - null, |
180 | | - null, |
181 | | - $controllerResolverDefaults['disabled'] ?? false, |
182 | | - ])); |
183 | | - } |
184 | | - } |
| 153 | + $this->loadEntityValueResolverServices($container, $loader, $config); |
185 | 154 | } |
186 | 155 |
|
187 | 156 | /** |
@@ -432,6 +401,46 @@ private function loadMessengerServices(ContainerBuilder $container): void |
432 | 401 | $loader->load('messenger.xml'); |
433 | 402 | } |
434 | 403 |
|
| 404 | + /** @param array<string, mixed> $config */ |
| 405 | + private function loadEntityValueResolverServices(ContainerBuilder $container, FileLoader $loader, array $config): void |
| 406 | + { |
| 407 | + // available in Symfony 6.2 and higher |
| 408 | + if (! class_exists(EntityValueResolver::class)) { |
| 409 | + return; |
| 410 | + } |
| 411 | + |
| 412 | + $loader->load('value_resolver.xml'); |
| 413 | + |
| 414 | + if (! class_exists(ExpressionLanguage::class)) { |
| 415 | + $container->removeDefinition('doctrine_mongodb.odm.document_value_resolver.expression_language'); |
| 416 | + } |
| 417 | + |
| 418 | + $controllerResolverDefaults = []; |
| 419 | + |
| 420 | + if (! $config['controller_resolver']['enabled']) { |
| 421 | + $controllerResolverDefaults['disabled'] = true; |
| 422 | + } |
| 423 | + |
| 424 | + if (! $config['controller_resolver']['auto_mapping']) { |
| 425 | + $controllerResolverDefaults['mapping'] = []; |
| 426 | + } |
| 427 | + |
| 428 | + if ($controllerResolverDefaults === []) { |
| 429 | + return; |
| 430 | + } |
| 431 | + |
| 432 | + $container->getDefinition('doctrine_mongodb.odm.entity_value_resolver')->setArgument(2, (new Definition(MapDocument::class))->setArguments([ |
| 433 | + null, |
| 434 | + null, |
| 435 | + null, |
| 436 | + $controllerResolverDefaults['mapping'] ?? null, |
| 437 | + null, |
| 438 | + null, |
| 439 | + null, |
| 440 | + $controllerResolverDefaults['disabled'] ?? false, |
| 441 | + ])); |
| 442 | + } |
| 443 | + |
435 | 444 | /** |
436 | 445 | * Normalizes the driver options array |
437 | 446 | * |
|
0 commit comments