Skip to content

Commit

Permalink
feat(laravel): add CSV support (#6617)
Browse files Browse the repository at this point in the history
* feat(laravel): add CSV support

* text/csv
  • Loading branch information
dunglas authored Sep 17, 2024
1 parent de6e3f5 commit 06a647a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
Expand Down Expand Up @@ -956,7 +957,15 @@ public function register(): void
// $list->insert($jsonserializableNormalizer, -900);
// $list->insert($uuidDenormalizer, -895); //Todo ramsey uuid support ?
return new Serializer(iterator_to_array($list), [new JsonEncoder('json'), $app->make(JsonEncoder::class), new JsonEncoder('jsonopenapi'), new JsonEncoder('jsonapi')]);
return new Serializer(
iterator_to_array($list),
[
new JsonEncoder('json'),
$app->make(JsonEncoder::class),
new JsonEncoder('jsonopenapi'),
new JsonEncoder('jsonapi'),
new CsvEncoder(),
]);
});

$this->app->singleton(JsonLdItemNormalizer::class, function (Application $app) {
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/config/api-platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'formats' => [
'jsonld' => ['application/ld+json'],
//'jsonapi' => ['application/vnd.api+json'],
//'csv' => ['text/csv'],
],

'patch_formats' => [
Expand Down

0 comments on commit 06a647a

Please sign in to comment.