Skip to content

Commit

Permalink
fix(laravel): declare normalizer list as a service
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Nov 12, 2024
1 parent 417fef5 commit 4bf961a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,7 @@ public function register(): void
);
});

$this->app->bind(SerializerInterface::class, Serializer::class);
$this->app->bind(NormalizerInterface::class, Serializer::class);
$this->app->singleton(Serializer::class, function (Application $app) {
/** @var ConfigRepository */
$config = $app['config'];
$this->app->singleton('api_platform_normalizer_list', function (Application $app) {
$list = new \SplPriorityQueue();
$list->insert($app->make(HydraEntrypointNormalizer::class), -800);
$list->insert($app->make(HydraPartialCollectionViewNormalizer::class), -800);
Expand Down Expand Up @@ -1011,14 +1007,20 @@ public function register(): void
$list->insert($app->make(GraphQlRuntimeExceptionNormalizer::class), -780);
}

return $list;
});

$this->app->bind(SerializerInterface::class, Serializer::class);
$this->app->bind(NormalizerInterface::class, Serializer::class);
$this->app->singleton(Serializer::class, function (Application $app) {
// TODO: unused + implement hal/jsonapi ?
// $list->insert($dataUriNormalizer, -920);
// $list->insert($unwrappingDenormalizer, 1000);
// $list->insert($jsonserializableNormalizer, -900);
// $list->insert($uuidDenormalizer, -895); //Todo ramsey uuid support ?
return new Serializer(
iterator_to_array($list),
iterator_to_array($app->make('api_platform_normalizer_list')),
[
new JsonEncoder('json'),
$app->make(JsonEncoder::class),
Expand Down

0 comments on commit 4bf961a

Please sign in to comment.