Skip to content

Commit

Permalink
Merge pull request #914 from mbabker/provide-expression-evaluator-to-…
Browse files Browse the repository at this point in the history
…drivers

Add support for injecting the expression evaluator into metadata drivers
  • Loading branch information
goetas authored Jan 6, 2023
2 parents 671fbba + e8ab91d commit 4b7f6a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions DependencyInjection/JMSSerializerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\Expression\CompilableExpressionEvaluatorInterface;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\Handler\SymfonyUidHandler;
use JMS\Serializer\Metadata\Driver\AttributeDriver\AttributeReader;
Expand Down Expand Up @@ -143,6 +144,20 @@ private function loadInternal(array $config, ScopedContainer $container, array $
$container
->getDefinition('jms_serializer.accessor_strategy.default')
->replaceArgument(0, new Reference($config['expression_evaluator']['id']));

if (is_a($container->findDefinition($config['expression_evaluator']['id'])->getClass(), CompilableExpressionEvaluatorInterface::class, true)) {
$container
->getDefinition('jms_serializer.metadata.yaml_driver')
->replaceArgument(3, new Reference($config['expression_evaluator']['id']));

$container
->getDefinition('jms_serializer.metadata.xml_driver')
->replaceArgument(3, new Reference($config['expression_evaluator']['id']));

$container
->getDefinition('jms_serializer.metadata.annotation_driver')
->replaceArgument(3, new Reference($config['expression_evaluator']['id']));
}
} else {
$container->removeDefinition('jms_serializer.expression_evaluator');
}
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@
<argument type="service" id="jms_serializer.metadata.file_locator" />
<argument type="service" id="jms_serializer.naming_strategy" />
<argument type="service" id="jms_serializer.type_parser" on-invalid="null" />
<argument type="constant">NULL</argument> <!-- expression evaluator -->
</service>
<service id="jms_serializer.metadata.xml_driver" class="JMS\Serializer\Metadata\Driver\XmlDriver" public="false">
<argument type="service" id="jms_serializer.metadata.file_locator" />
<argument type="service" id="jms_serializer.naming_strategy" />
<argument type="service" id="jms_serializer.type_parser" on-invalid="null" />
<argument type="constant">NULL</argument> <!-- expression evaluator -->
</service>
<service id="jms_serializer.metadata.annotation_driver" class="JMS\Serializer\Metadata\Driver\AnnotationDriver" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="jms_serializer.naming_strategy" />
<argument type="service" id="jms_serializer.type_parser" on-invalid="null" />
<argument type="constant">NULL</argument> <!-- expression evaluator -->
</service>
<service id="jms_serializer.metadata_driver" class="Metadata\Driver\DriverChain" public="false">
<argument type="collection">
Expand Down

0 comments on commit 4b7f6a6

Please sign in to comment.