Skip to content

Symfony 8.1 beta: DateTimeValueObjectTransformer is auto-tagged as property transformer and breaks container compile #7954

@tacman

Description

@tacman

API Platform version(s) affected

4.3.4

Description

When using api-platform/core 4.3.4 with Symfony 8.1 beta, the container fails to compile because the API Platform JSON Streamer DateTime value-object transformer service is also tagged as a property value transformer by Symfony's deprecation compiler pass.

The failure is:

In TransformerPass.php line 42:

  [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
  The service "api_platform.jsonld.json_streamer.value_transformer.date_time" tagged "json_streamer.property_value_transformer" must implement "Symfony\Component\JsonStreamer\Transformer\PropertyValueTransformerInterface".

Installed versions from the affected project:

api-platform/core      v4.3.4
symfony/json-streamer v8.1.0-BETA1

The service is registered in src/Symfony/Bundle/Resources/config/json_streamer/common.php as:

$services->set('api_platform.jsonld.json_streamer.value_transformer.date_time', DateTimeValueObjectTransformer::class)
    ->tag('json_streamer.value_transformer', ['key' => \DateTimeInterface::class])
    ->tag('json_streamer.value_object_transformer');

In Symfony 8.1, json_streamer.value_transformer is deprecated. Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DeprecateJsonStreamerValueTransformerTagPass adds json_streamer.property_value_transformer to services with the deprecated tag. Then Symfony\Component\JsonStreamer\DependencyInjection\TransformerPass validates json_streamer.property_value_transformer services and throws because Symfony\Component\JsonStreamer\Transformer\DateTimeValueObjectTransformer implements ValueObjectTransformerInterface, not PropertyValueTransformerInterface.

This looks related to #7839 and #7867, but those changes are already present in 4.3.4 and this still fails with Symfony 8.1.0-BETA1.

How to reproduce

Install API Platform with Symfony 8.1 beta packages, including symfony/json-streamer 8.1.0-BETA1, then boot the Symfony console/container.

For example:

php bin/console

The container compile fails before commands are listed.

Possible Solution

The DateTime service is a value-object transformer, so it probably should not be left with the deprecated json_streamer.value_transformer tag under Symfony 8.1 if FrameworkBundle converts that tag into json_streamer.property_value_transformer.

One possible direction is to conditionally avoid the deprecated tag for Symfony/json-streamer 8.1+, or otherwise prevent api_platform.jsonld.json_streamer.value_transformer.date_time from being processed as a property value transformer while preserving the \DateTimeInterface::class lookup needed by API Platform's JSON-LD stream writer.

Additional Context

Relevant Symfony code path:

  • Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DeprecateJsonStreamerValueTransformerTagPass
  • Symfony\Component\JsonStreamer\DependencyInjection\TransformerPass

Exception trace starts at:

vendor/symfony/json-streamer/DependencyInjection/TransformerPass.php:42
Symfony\Component\JsonStreamer\DependencyInjection\TransformerPass->process()
vendor/symfony/dependency-injection/Compiler/Compiler.php:73

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions