From e4479cc13ca211b0da235ebfca684421c8a61e1f Mon Sep 17 00:00:00 2001 From: Moln Date: Sat, 20 Feb 2021 15:53:36 +0800 Subject: [PATCH] Update --- src/Basic/CollectionNormalizer.php | 9 +++++---- src/Serializer/AbstractCollectionNormalizer.php | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Basic/CollectionNormalizer.php b/src/Basic/CollectionNormalizer.php index 062e100..67d9a85 100644 --- a/src/Basic/CollectionNormalizer.php +++ b/src/Basic/CollectionNormalizer.php @@ -34,16 +34,17 @@ protected function getPaginationData($object, array $context = []): array { [$currentPage, $itemsPerPage, $totalItems, $pageCount] = $this->getPaginationConfig($object, $context); - if ($totalItems) { + $data = []; + if ($totalItems !== null) { $data['total'] = $totalItems; } - if ($currentPage) { + if ($currentPage !== null) { $data['page'] = $currentPage; } - if ($pageCount) { + if ($pageCount !== null) { $data['page_count'] = $pageCount; } - if ($itemsPerPage) { + if ($itemsPerPage !== null) { $data['page_size'] = $itemsPerPage; } diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index d98e512..e7ba8c5 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -48,6 +48,7 @@ public function supportsNormalization($data, $format = null, array $context = [] return static::FORMAT === $format && is_iterable($data) && isset($context['api_resource']) && + $context['api_resource'] == 'collection' && !isset($context['api_sub_level']); }