Skip to content

Commit

Permalink
Merge pull request #932 from mbabker/no-attribute-driver
Browse files Browse the repository at this point in the history
Don't wire the AttributeDriver
  • Loading branch information
goetas authored Jun 13, 2023
2 parents d968afb + 9d365dc commit 3279738
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
34 changes: 11 additions & 23 deletions DependencyInjection/JMSSerializerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,17 @@ public function load(array $rawConfigs, ContainerBuilder $container): void
$metadataDrivers = [
new Reference('jms_serializer.metadata.yaml_driver'),
new Reference('jms_serializer.metadata.xml_driver'),
// new Reference('jms_serializer.metadata.attribute_driver'), // TODO - Re-enable this driver at a later time
new Reference('jms_serializer.metadata.annotation_driver'),
];

// enable the attribute driver on php 8
if (PHP_VERSION_ID >= 80000) {
if (class_exists(AttributeDriver::class)) {
// Register the attribute driver before the annotation driver
$metadataDrivers = [
new Reference('jms_serializer.metadata.yaml_driver'),
new Reference('jms_serializer.metadata.xml_driver'),
new Reference('jms_serializer.metadata.attribute_driver'),
new Reference('jms_serializer.metadata.annotation_driver'),
];
} else {
$container->removeDefinition('jms_serializer.metadata.attribute_driver');

if (class_exists(AttributeReader::class)) {
$container->register('jms_serializer.metadata.annotation_and_attributes_reader', AttributeReader::class)
->setArgument(0, new Reference('annotation_reader'));

$container->findDefinition('jms_serializer.metadata.annotation_driver')
->replaceArgument(0, new Reference('jms_serializer.metadata.annotation_and_attributes_reader'));
}
}
} else {
$container->removeDefinition('jms_serializer.metadata.attribute_driver');
// enable attributes support on php 8
if (PHP_VERSION_ID >= 80000 && class_exists(AttributeReader::class)) {
$container->register('jms_serializer.metadata.annotation_and_attributes_reader', AttributeReader::class)
->setArgument(0, new Reference('annotation_reader'));

$container->findDefinition('jms_serializer.metadata.annotation_driver')
->replaceArgument(0, new Reference('jms_serializer.metadata.annotation_and_attributes_reader'));
}

$container
Expand Down Expand Up @@ -194,13 +179,16 @@ private function loadInternal(array $config, ScopedContainer $container, array $
->getDefinition('jms_serializer.metadata.annotation_driver')
->replaceArgument(3, new Reference($config['expression_evaluator']['id']));

// TODO - Re-enable this driver at a later time
/*
try {
$container
->getDefinition('jms_serializer.metadata.attribute_driver')
->replaceArgument(2, new Reference($config['expression_evaluator']['id']));
} catch (ServiceNotFoundException $exception) {
// Removed by conditional checks earlier
}
*/
}
} else {
$container->removeDefinition('jms_serializer.expression_evaluator');
Expand Down
7 changes: 4 additions & 3 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@
<argument type="service" id="jms_serializer.type_parser" on-invalid="null" />
<argument type="constant">NULL</argument> <!-- expression evaluator -->
</service>
<service id="jms_serializer.metadata.attribute_driver" class="JMS\Serializer\Metadata\Driver\AttributeDriver" public="false">
<!-- TODO - Re-enable this driver at a later time -->
<!-- <service id="jms_serializer.metadata.attribute_driver" class="JMS\Serializer\Metadata\Driver\AttributeDriver" public="false">
<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>
<argument type="constant">NULL</argument>
</service> -->
<service id="jms_serializer.metadata_driver" class="Metadata\Driver\DriverChain" public="false">
<argument type="collection">
<argument type="constant">NULL</argument> <!-- list of metadata drivers -->
Expand Down

0 comments on commit 3279738

Please sign in to comment.