From 9bc13c869b5a7fbe94c468f8de7542ce58ff61f2 Mon Sep 17 00:00:00 2001 From: eltharin Date: Mon, 8 Jul 2024 12:33:26 +0200 Subject: [PATCH] service EntityValueResolver Changes Service Definition change for allow user inject its own variables in EntityValueResolver single quotes --- config/orm.xml | 4 ++++ src/DependencyInjection/DoctrineExtension.php | 7 +++++++ tests/DependencyInjection/DoctrineExtensionTest.php | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/orm.xml b/config/orm.xml index 2d8089926..375fce3ee 100644 --- a/config/orm.xml +++ b/config/orm.xml @@ -188,6 +188,10 @@ + + + + diff --git a/src/DependencyInjection/DoctrineExtension.php b/src/DependencyInjection/DoctrineExtension.php index 161626a7a..30337a443 100644 --- a/src/DependencyInjection/DoctrineExtension.php +++ b/src/DependencyInjection/DoctrineExtension.php @@ -33,6 +33,7 @@ use InvalidArgumentException; use LogicException; use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; +use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolverVariableLoader; use Symfony\Bridge\Doctrine\Attribute\MapEntity; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; @@ -533,6 +534,12 @@ protected function ormLoad(array $config, ContainerBuilder $container) $controllerResolverDefaults['evict_cache'] ?? null, $controllerResolverDefaults['disabled'] ?? false, ])); + } else { + $container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))); + } + + if (class_exists(ExpressionLanguage::class) && class_exists(EntityValueResolverVariableLoader::class)) { + $container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(3, new Reference('doctrine.orm.entity_value_resolver_variables_loader')); } } diff --git a/tests/DependencyInjection/DoctrineExtensionTest.php b/tests/DependencyInjection/DoctrineExtensionTest.php index b2a6e3c4e..1c17e60df 100644 --- a/tests/DependencyInjection/DoctrineExtensionTest.php +++ b/tests/DependencyInjection/DoctrineExtensionTest.php @@ -1451,7 +1451,7 @@ public function testControllerResolver(bool $simpleEntityManagerConfig): void $controllerResolver = $container->getDefinition('doctrine.orm.entity_value_resolver'); - $this->assertEquals([new Reference('doctrine'), new Reference('doctrine.orm.entity_value_resolver.expression_language', $container::IGNORE_ON_INVALID_REFERENCE)], $controllerResolver->getArguments()); + $this->assertEquals([new Reference('doctrine'), new Reference('doctrine.orm.entity_value_resolver.expression_language', $container::IGNORE_ON_INVALID_REFERENCE), new Definition(MapEntity::class)], $controllerResolver->getArguments()); $container = $this->getContainer();