Skip to content

Commit

Permalink
update for Expression Modifier Injector
Browse files Browse the repository at this point in the history
  • Loading branch information
eltharin committed Jul 13, 2024
1 parent 0a71f6e commit 96e5b2d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@
<argument type="service" id="doctrine" />
</service>

<service id="doctrine.orm.entity_value_resolver_variable_injector" class="Symfony\Bridge\Doctrine\ArgumentResolver\UserInjector">
<service id="Symfony\Bridge\Doctrine\ArgumentResolver\UserInjector">
<argument type="service" id="security.token_storage" on-invalid="ignore" />
<tag name="doctrine.orm.entity_value_resolver_expression_modifier_injector" key="userInjector"/>
</service>

<service id="doctrine.orm.entity_value_resolver" class="Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver">
Expand Down
7 changes: 6 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getConfigTreeBuilder(): TreeBuilder
private function addDbalSection(ArrayNodeDefinition $node): void
{
// Key that should not be rewritten to the connection config
$excludedKeys = ['default_connection' => true, 'driver_schemes' => true, 'driver_scheme' => true, 'types' => true, 'type' => true];
$excludedKeys = ['default_connection' => true, 'driver_schemes' => true, 'driver_scheme' => true, 'types' => true, 'type' => true, 'default_expression_modifier_injector' => true];

$node
->children()
Expand Down Expand Up @@ -167,6 +167,11 @@ private function addDbalSection(ArrayNodeDefinition $node): void
->end()
->end()
->end()
->children()
->arrayNode('default_expression_modifier_injector')->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->end()
->end()
->fixXmlConfig('connection')
->append($this->getDbalConnectionsNode())
->end();
Expand Down
11 changes: 7 additions & 4 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use InvalidArgumentException;
use LogicException;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
use Symfony\Bridge\Doctrine\ArgumentResolver\UserInjector;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolverExpressionModifiersInjectorInterface;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
Expand All @@ -51,6 +51,7 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -182,6 +183,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false));

$container->setParameter('doctrine.dbal.connection_factory.types', $config['types']);
$container->setParameter('doctrine.dbal.default_expression_modifier_injector', $config['default_expression_modifier_injector']);

Check failure on line 186 in src/DependencyInjection/DoctrineExtension.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

InvalidArrayOffset

src/DependencyInjection/DoctrineExtension.php:186:88: InvalidArrayOffset: Cannot access value on variable $config using offset value of 'default_expression_modifier_injector', expecting 'connections', 'driver_schemes', 'default_connection' or 'types' (see https://psalm.dev/115)

$container->getDefinition('doctrine.dbal.connection_factory.dsn_parser')->setArgument(0, array_merge(ConnectionFactory::DEFAULT_SCHEME_MAP, $config['driver_schemes']));

Expand Down Expand Up @@ -497,7 +499,6 @@ protected function ormLoad(array $config, ContainerBuilder $container)
// available in Symfony 6.2 and higher
if (! class_exists(EntityValueResolver::class)) {
$container->removeDefinition('doctrine.orm.entity_value_resolver');
$container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
} else {
if (! class_exists(ExpressionLanguage::class)) {
$container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
Expand Down Expand Up @@ -538,8 +539,10 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class)));
}

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'));
if (class_exists(ExpressionLanguage::class) && interface_exists(EntityValueResolverExpressionModifiersInjectorInterface::class)) {
$container->registerForAutoconfiguration(EntityValueResolverExpressionModifiersInjectorInterface::class)->addTag('doctrine.orm.entity_value_resolver_expression_modifier_injector');

Check failure on line 543 in src/DependencyInjection/DoctrineExtension.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

UndefinedClass

src/DependencyInjection/DoctrineExtension.php:543:58: UndefinedClass: Class, interface or enum named Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolverExpressionModifiersInjectorInterface does not exist (see https://psalm.dev/019)
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(3, new AutowireLocator('doctrine.orm.entity_value_resolver_expression_modifier_injector', 'key'));
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(4, $container->getParameter('doctrine.dbal.default_expression_modifier_injector'));

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

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/DoctrineExtension.php#L543-L545

Added lines #L543 - L545 were not covered by tests
}
}

Expand Down

0 comments on commit 96e5b2d

Please sign in to comment.