Skip to content

Commit be8119f

Browse files
committed
add laravel provider
1 parent 280ee15 commit be8119f

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/Laravel/ApiPlatformDeferredProvider.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@
8080
use ApiPlatform\State\Pagination\Pagination;
8181
use ApiPlatform\State\ParameterProviderInterface;
8282
use ApiPlatform\State\ProcessorInterface;
83+
use ApiPlatform\State\Processor\ObjectMapperProcessor;
84+
use ApiPlatform\State\Provider\ObjectMapperProvider;
8385
use ApiPlatform\State\Provider\ParameterProvider;
86+
use ApiPlatform\State\Provider\ReadProvider;
8487
use ApiPlatform\State\Provider\SecurityParameterProvider;
8588
use ApiPlatform\State\ProviderInterface;
8689
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface;
@@ -89,6 +92,12 @@
8992
use Illuminate\Support\ServiceProvider;
9093
use Negotiation\Negotiator;
9194
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;
92101
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
93102
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
94103

@@ -190,6 +199,34 @@ public function register(): void
190199

191200
$this->autoconfigure($classes, ProviderInterface::class, [ItemProvider::class, CollectionProvider::class, ErrorProvider::class]);
192201

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+
193230
$this->app->singleton(ResourceMetadataCollectionFactoryInterface::class, function (Application $app) {
194231
/** @var ConfigRepository $config */
195232
$config = $app['config'];
@@ -355,6 +392,7 @@ public function provides(): array
355392
'api_platform.graphql.state_provider.parameter',
356393
FieldsBuilderEnumInterface::class,
357394
ExceptionHandlerInterface::class,
395+
ObjectMapperInterface::class
358396
];
359397
}
360398
}

src/Serializer/SerializerContextBuilder.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public function createFromRequest(Request $request, bool $normalization, ?array
8484
}
8585
}
8686

87-
// if (null === $context['output'] && $this->getStateOptionsClass($operation)) {
88-
// $context['force_resource_class'] = $operation->getClass();
89-
// }
90-
9187
if ($this->debug && isset($context['groups']) && $operation instanceof ErrorOperation) {
9288
if (!\is_array($context['groups'])) {
9389
$context['groups'] = (array) $context['groups'];

0 commit comments

Comments
 (0)