Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/ApiPlatformBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\GraphQlTypePass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\MetadataAwareNameConverterPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\MutatorPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\ObjectMapperPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\SerializerMappingLoaderPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\TestClientPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\TestMercureHubPass;
Expand Down Expand Up @@ -59,5 +60,6 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new AuthenticatorManagerPass());
$container->addCompilerPass(new SerializerMappingLoaderPass());
$container->addCompilerPass(new MutatorPass());
$container->addCompilerPass(new ObjectMapperPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Symfony\Bundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ObjectMapper\ObjectMapper;

/**
* Creates the Object Mapper.
*
* @author Florent Blaison <florent.blaison@gmail.com>
*/
final class ObjectMapperPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!class_exists(ObjectMapper::class)) {
return;
}

if ($container->has('object_mapper.metadata_factory')) {
$container->setAlias('api_platform.object_mapper.metadata_factory', 'object_mapper.metadata_factory');
} else {
$container->setDefinition('api_platform.object_mapper.metadata_factory', new Definition('Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory'));
}

if ($container->has('object_mapper')) {
$container->setAlias('api_platform.object_mapper', 'object_mapper');
} else {
$container->setDefinition('api_platform.object_mapper', new Definition('Symfony\Component\ObjectMapper\ObjectMapper', [
new Reference('api_platform.object_mapper.metadata_factory'),
new Reference('property_accessor', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new ServiceLocatorArgument(new TaggedIteratorArgument('object_mapper.transform_callable', null, null, true)),
new ServiceLocatorArgument(new TaggedIteratorArgument('object_mapper.condition_callable', null, null, true)),
]));
}
}
}
10 changes: 0 additions & 10 deletions src/Symfony/Bundle/Resources/config/state/object_mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
return function (ContainerConfigurator $container) {
$services = $container->services();

$services->set('api_platform.object_mapper.metadata_factory', 'Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory');

$services->set('api_platform.object_mapper', 'Symfony\Component\ObjectMapper\ObjectMapper')
->args([
service('api_platform.object_mapper.metadata_factory'),
service('property_accessor')->nullOnInvalid(),
tagged_locator('object_mapper.transform_callable'),
tagged_locator('object_mapper.condition_callable'),
]);

$services->set('api_platform.object_mapper.relation', 'ApiPlatform\State\ObjectMapper\ObjectMapper')
->decorate('api_platform.object_mapper', null, -255)
->args([service('api_platform.object_mapper.relation.inner')]);
Expand Down
2 changes: 2 additions & 0 deletions tests/Symfony/Bundle/ApiPlatformBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\GraphQlTypePass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\MetadataAwareNameConverterPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\MutatorPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\ObjectMapperPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\SerializerMappingLoaderPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\TestClientPass;
use ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\TestMercureHubPass;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function testBuild(): void
$containerProphecy->addCompilerPass(Argument::type(AuthenticatorManagerPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(SerializerMappingLoaderPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(MutatorPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(ObjectMapperPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();

$bundle = new ApiPlatformBundle();
$bundle->build($containerProphecy->reveal());
Expand Down
Loading