Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
use Symfony\Component\TypeInfo\Type;

final class ContextValueTransformer implements ValueTransformerInterface
final class ContextValueTransformer implements PropertyValueTransformerInterface
{
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
use Symfony\Component\TypeInfo\Type;

final class IriValueTransformer implements ValueTransformerInterface
final class IriValueTransformer implements PropertyValueTransformerInterface
{
public function __construct(
private readonly IriConverterInterface $iriConverter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\JsonLd\JsonStreamer\ValueTransformer;

use Symfony\Component\JsonStreamer\Transformer\PropertyValueTransformerInterface as SymfonyPropertyValueTransformerInterface;
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface as LegacySymfonyValueTransformerInterface;

// symfony/json-streamer 8.1 deprecates ValueTransformerInterface in favor of PropertyValueTransformerInterface.
if (interface_exists(SymfonyPropertyValueTransformerInterface::class)) {
/**
* @internal
*/
interface PropertyValueTransformerInterface extends SymfonyPropertyValueTransformerInterface
{
}
} else {
/**
* @internal
*/
interface PropertyValueTransformerInterface extends LegacySymfonyValueTransformerInterface
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
use Symfony\Component\TypeInfo\Type;

final class TypeValueTransformer implements ValueTransformerInterface
final class TypeValueTransformer implements PropertyValueTransformerInterface
{
public function __construct(
private readonly ResourceClassResolverInterface $resourceClassResolver,
Expand Down
14 changes: 9 additions & 5 deletions src/Symfony/Bundle/Resources/config/json_streamer/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@
use Symfony\Component\JsonStreamer\JsonStreamWriter;
use Symfony\Component\JsonStreamer\StreamerDumper;
use Symfony\Component\JsonStreamer\Transformer\DateTimeValueObjectTransformer;
use Symfony\Component\JsonStreamer\Transformer\PropertyValueTransformerInterface;

return static function (ContainerConfigurator $container) {
$services = $container->services();

// symfony/json-streamer 8.1 renamed the "json_streamer.value_transformer" tag
$valueTransformerTag = interface_exists(PropertyValueTransformerInterface::class) ? 'json_streamer.property_value_transformer' : 'json_streamer.value_transformer';

$services->set('api_platform.jsonld.json_streamer.stream_writer', JsonStreamWriter::class)
->args([
tagged_locator('json_streamer.value_transformer', 'key'),
tagged_locator($valueTransformerTag, 'key'),
service('api_platform.jsonld.json_streamer.write.property_metadata_loader'),
'%.json_streamer.stream_writers_dir.jsonld%',
service('config_cache_factory')->ignoreOnInvalid(),
]);

$jsonStreamReaderArgs = [
tagged_locator('json_streamer.value_transformer', 'key'),
tagged_locator($valueTransformerTag, 'key'),
service('json_streamer.read.property_metadata_loader'),
'%.json_streamer.stream_readers_dir.jsonld%',
];
Expand Down Expand Up @@ -65,18 +69,18 @@

$services->set('api_platform.jsonld.json_streamer.write.value_transformer.iri', IriValueTransformer::class)
->args([service('api_platform.iri_converter')])
->tag('json_streamer.value_transformer');
->tag($valueTransformerTag);

$services->set('api_platform.jsonld.json_streamer.write.value_transformer.type', TypeValueTransformer::class)
->args([
service('api_platform.resource_class_resolver'),
service('api_platform.metadata.resource.metadata_collection_factory'),
])
->tag('json_streamer.value_transformer');
->tag($valueTransformerTag);

$services->set('api_platform.jsonld.json_streamer.write.value_transformer.context', ContextValueTransformer::class)
->args([service('api_platform.router')])
->tag('json_streamer.value_transformer');
->tag($valueTransformerTag);

// FrameworkBundle 8.1+ registers DateTimeValueObjectTransformer itself; skip to avoid duplicate registration and TransformerPass validation breakage (issue #7954).
if (class_exists(DateTimeValueObjectTransformer::class) && !class_exists(DeprecateJsonStreamerValueTransformerTagPass::class)) {
Expand Down
Loading