Skip to content

Commit

Permalink
service EntityValueResolver Changes
Browse files Browse the repository at this point in the history
Service Definition change for allow user inject its own variables in EntityValueResolver

single quotes
  • Loading branch information
eltharin committed Jul 8, 2024
1 parent 1ea2b5b commit 9bc13c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
<argument type="service" id="doctrine" />
</service>

<service id="doctrine.orm.entity_value_resolver_variables_loader" class="Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolverVariablesLoader">
<argument type="service" id="security.token_storage" on-invalid="ignore" />
</service>

<service id="doctrine.orm.entity_value_resolver" class="Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver">
<argument type="service" id="doctrine" />
<argument type="service" id="doctrine.orm.entity_value_resolver.expression_language" on-invalid="ignore" />
Expand Down
7 changes: 7 additions & 0 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));

Check warning on line 542 in src/DependencyInjection/DoctrineExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/DoctrineExtension.php#L542

Added line #L542 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 9bc13c8

Please sign in to comment.