Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service definition changes for EntityValueResolver #1812

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_variable_injector" class="Symfony\Bridge\Doctrine\ArgumentResolver\UserInjector">
<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\UserInjector;
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 @@
$controllerResolverDefaults['evict_cache'] ?? null,
$controllerResolverDefaults['disabled'] ?? false,
]));
} else {
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Author

@eltharin eltharin Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not I can't set my new argument, I have this error :

``
In DefinitionErrorExceptionPass.php line 48:

Invalid constructor argument 4 for service "doctrine.orm.entity_value_resolver": argument 3 must be defined before. Check your service definition.
``

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just remove the if to have only one initialisation.

}

if (class_exists(ExpressionLanguage::class) && class_exists(UserInjector::class)) {
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(3, new Reference('doctrine.orm.entity_value_resolver_variable_injector'));

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
Loading