|
80 | 80 | use ApiPlatform\State\Pagination\Pagination; |
81 | 81 | use ApiPlatform\State\ParameterProviderInterface; |
82 | 82 | use ApiPlatform\State\ProcessorInterface; |
| 83 | +use ApiPlatform\State\Processor\ObjectMapperProcessor; |
| 84 | +use ApiPlatform\State\Provider\ObjectMapperProvider; |
83 | 85 | use ApiPlatform\State\Provider\ParameterProvider; |
| 86 | +use ApiPlatform\State\Provider\ReadProvider; |
84 | 87 | use ApiPlatform\State\Provider\SecurityParameterProvider; |
85 | 88 | use ApiPlatform\State\ProviderInterface; |
86 | 89 | use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface; |
|
89 | 92 | use Illuminate\Support\ServiceProvider; |
90 | 93 | use Negotiation\Negotiator; |
91 | 94 | use Psr\Log\LoggerInterface; |
| 95 | +use Symfony\Component\ObjectMapper\ConditionCallableInterface; |
| 96 | +use Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory; |
| 97 | +use Symfony\Component\ObjectMapper\ObjectMapper; |
| 98 | +use Symfony\Component\ObjectMapper\ObjectMapperInterface; |
| 99 | +use Symfony\Component\ObjectMapper\TransformCallableInterface; |
| 100 | +use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
92 | 101 | use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; |
93 | 102 | use Symfony\Component\Serializer\NameConverter\NameConverterInterface; |
94 | 103 |
|
@@ -190,6 +199,34 @@ public function register(): void |
190 | 199 |
|
191 | 200 | $this->autoconfigure($classes, ProviderInterface::class, [ItemProvider::class, CollectionProvider::class, ErrorProvider::class]); |
192 | 201 |
|
| 202 | + $this->app->singleton(ObjectMapperInterface::class, function (Application $app) { |
| 203 | + return new ObjectMapper( |
| 204 | + new ReflectionObjectMapperMetadataFactory(), |
| 205 | + $app->make(PropertyAccessorInterface::class), |
| 206 | + new ServiceLocator(iterator_to_array($app->tagged(TransformCallableInterface::class))), |
| 207 | + new ServiceLocator(iterator_to_array($app->tagged(ConditionCallableInterface::class))), |
| 208 | + ); |
| 209 | + }); |
| 210 | + |
| 211 | + $this->autoconfigure($classes, TransformCallableInterface::class, []); |
| 212 | + $this->autoconfigure($classes, ConditionCallableInterface::class, []); |
| 213 | + |
| 214 | + $this->app->extend(ReadProvider::class, function (ReadProvider $service, Application $app) { |
| 215 | + return new ObjectMapperProvider( |
| 216 | + $app->make(ObjectMapperInterface::class), |
| 217 | + $service |
| 218 | + ); |
| 219 | + }); |
| 220 | + |
| 221 | + $this->app->extend(CallableProcessor::class, function (CallableProcessor $service, Application $app) { |
| 222 | + return new ObjectMapperProcessor( |
| 223 | + $app->make(ObjectMapperInterface::class), |
| 224 | + $service |
| 225 | + ); |
| 226 | + }); |
| 227 | + |
| 228 | + $this->autoconfigure($classes, ProviderInterface::class, [ItemProvider::class, CollectionProvider::class, ErrorProvider::class]); |
| 229 | + |
193 | 230 | $this->app->singleton(ResourceMetadataCollectionFactoryInterface::class, function (Application $app) { |
194 | 231 | /** @var ConfigRepository $config */ |
195 | 232 | $config = $app['config']; |
@@ -355,6 +392,7 @@ public function provides(): array |
355 | 392 | 'api_platform.graphql.state_provider.parameter', |
356 | 393 | FieldsBuilderEnumInterface::class, |
357 | 394 | ExceptionHandlerInterface::class, |
| 395 | + ObjectMapperInterface::class |
358 | 396 | ]; |
359 | 397 | } |
360 | 398 | } |
0 commit comments