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 42b85b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 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
8 changes: 6 additions & 2 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use LogicException;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
use Symfony\Bridge\Doctrine\ArgumentResolver\UserInjector;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolverExpressionModifiersInjectorInterface;

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Use statements should be sorted alphabetically. The first wrong one is 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 +52,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 +184,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 187 in src/DependencyInjection/DoctrineExtension.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

InvalidArrayOffset

src/DependencyInjection/DoctrineExtension.php:187: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 +500,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 @@ -539,7 +541,9 @@ protected function ormLoad(array $config, ContainerBuilder $container)
}

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'));
$container->registerForAutoconfiguration(EntityValueResolverExpressionModifiersInjectorInterface::class)->addTag('doctrine.orm.entity_value_resolver_expression_modifier_injector');

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

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

UndefinedClass

src/DependencyInjection/DoctrineExtension.php:544: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', indexAttribute: 'key'));
$container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(4, $container->getParameter('doctrine.dbal.default_expression_modifier_injector'));
}
}

Expand Down

0 comments on commit 42b85b2

Please sign in to comment.