|
126 | 126 | use ApiPlatform\Metadata\Resource\Factory\ConcernsResourceNameCollectionFactory; |
127 | 127 | use ApiPlatform\Metadata\Resource\Factory\LinkFactory; |
128 | 128 | use ApiPlatform\Metadata\Resource\Factory\LinkFactoryInterface; |
| 129 | +use ApiPlatform\Metadata\Resource\Factory\ObjectMapperMetadataCollectionFactory; |
129 | 130 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
130 | 131 | use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; |
131 | 132 | use ApiPlatform\Metadata\ResourceAccessCheckerInterface; |
|
146 | 147 | use ApiPlatform\State\CallableProcessor; |
147 | 148 | use ApiPlatform\State\CallableProvider; |
148 | 149 | use ApiPlatform\State\ErrorProvider; |
| 150 | +use ApiPlatform\State\ObjectMapper\ObjectMapper; |
149 | 151 | use ApiPlatform\State\Pagination\Pagination; |
150 | 152 | use ApiPlatform\State\Pagination\PaginationOptions; |
151 | 153 | use ApiPlatform\State\Processor\AddLinkHeaderProcessor; |
| 154 | +use ApiPlatform\State\Processor\ObjectMapperProcessor; |
152 | 155 | use ApiPlatform\State\Processor\RespondProcessor; |
153 | 156 | use ApiPlatform\State\Processor\SerializeProcessor; |
154 | 157 | use ApiPlatform\State\Processor\WriteProcessor; |
155 | 158 | use ApiPlatform\State\ProcessorInterface; |
156 | 159 | use ApiPlatform\State\Provider\ContentNegotiationProvider; |
157 | 160 | use ApiPlatform\State\Provider\DeserializeProvider; |
| 161 | +use ApiPlatform\State\Provider\ObjectMapperProvider; |
158 | 162 | use ApiPlatform\State\Provider\ParameterProvider; |
159 | 163 | use ApiPlatform\State\Provider\ReadProvider; |
160 | 164 | use ApiPlatform\State\ProviderInterface; |
|
166 | 170 | use Negotiation\Negotiator; |
167 | 171 | use PHPStan\PhpDocParser\Parser\PhpDocParser; |
168 | 172 | use Psr\Log\LoggerInterface; |
| 173 | +use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface; |
| 174 | +use Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory; |
| 175 | +use Symfony\Component\ObjectMapper\ObjectMapperInterface; |
169 | 176 | use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
170 | 177 | use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor; |
171 | 178 | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; |
@@ -347,6 +354,16 @@ public function register(): void |
347 | 354 | return new HydraPrefixNameConverter(new MetadataAwareNameConverter($app->make(ClassMetadataFactoryInterface::class), $nameConverter), $defaultContext); |
348 | 355 | }); |
349 | 356 |
|
| 357 | + // ObjectMapper metadata factory support |
| 358 | + if (interface_exists(ObjectMapperInterface::class)) { |
| 359 | + $this->app->extend(ResourceMetadataCollectionFactoryInterface::class, static function (ResourceMetadataCollectionFactoryInterface $inner, Application $app) { |
| 360 | + return new ObjectMapperMetadataCollectionFactory( |
| 361 | + $inner, |
| 362 | + $app->make(ObjectMapperMetadataFactoryInterface::class) |
| 363 | + ); |
| 364 | + }); |
| 365 | + } |
| 366 | + |
350 | 367 | $this->app->singleton(OperationMetadataFactory::class, static function (Application $app) { |
351 | 368 | return new OperationMetadataFactory($app->make(ResourceNameCollectionFactoryInterface::class), $app->make(ResourceMetadataCollectionFactoryInterface::class)); |
352 | 369 | }); |
@@ -404,6 +421,23 @@ public function register(): void |
404 | 421 |
|
405 | 422 | $this->app->bind(ProviderInterface::class, ContentNegotiationProvider::class); |
406 | 423 |
|
| 424 | + // ObjectMapper support |
| 425 | + if (interface_exists(ObjectMapperInterface::class)) { |
| 426 | + $this->app->singleton(ObjectMapperMetadataFactoryInterface::class, ReflectionObjectMapperMetadataFactory::class); |
| 427 | + |
| 428 | + $this->app->singleton(ObjectMapper::class, static function (Application $app) { |
| 429 | + if (!$app->bound('api_platform.object_mapper')) { |
| 430 | + return null; |
| 431 | + } |
| 432 | + |
| 433 | + return new ObjectMapper($app->make('api_platform.object_mapper')); |
| 434 | + }); |
| 435 | + |
| 436 | + $this->app->extend(ProviderInterface::class, static function (ProviderInterface $inner, Application $app) { |
| 437 | + return new ObjectMapperProvider($app->make(ObjectMapper::class), $inner); |
| 438 | + }); |
| 439 | + } |
| 440 | + |
407 | 441 | $this->app->singleton(RespondProcessor::class, static function (Application $app) { |
408 | 442 | $decorated = new RespondProcessor( |
409 | 443 | $app->make(IriConverterInterface::class), |
@@ -470,6 +504,13 @@ public function register(): void |
470 | 504 | return $app->make(WriteProcessor::class); |
471 | 505 | }); |
472 | 506 |
|
| 507 | + // ObjectMapperProcessor wraps the base processor if available |
| 508 | + if (interface_exists(ObjectMapperInterface::class)) { |
| 509 | + $this->app->extend(ProcessorInterface::class, static function (ProcessorInterface $inner, Application $app) { |
| 510 | + return new ObjectMapperProcessor($app->make(ObjectMapper::class), $inner); |
| 511 | + }); |
| 512 | + } |
| 513 | + |
473 | 514 | $this->app->singleton(ObjectNormalizer::class, static function (Application $app) { |
474 | 515 | $config = $app['config']; |
475 | 516 | $defaultContext = $config->get('api-platform.serializer', []); |
|
0 commit comments