File tree Expand file tree Collapse file tree 4 files changed +71
-1
lines changed
Expand file tree Collapse file tree 4 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,16 @@ protected function paginationInformation(): array
4141 {
4242 $ paginated = $ this ->resource ->resource ->toArray ();
4343
44- return [
44+ $ default = [
4545 'links ' => $ this ->paginationLinks ($ paginated ),
4646 'meta ' => $ this ->meta ($ paginated ),
4747 ];
48+
49+ if ($ this ->resource instanceof PaginationInformationInterface) {
50+ return $ this ->resource ->paginationInformation ($ paginated , $ default );
51+ }
52+
53+ return $ default ;
4854 }
4955
5056 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+ /**
5+ * This file is part of Hyperf.
6+ *
7+ * @link https://www.hyperf.io
8+ * @document https://hyperf.wiki
9+ * @contact group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+
13+ namespace Hyperf \Resource \Response ;
14+
15+ interface PaginationInformationInterface
16+ {
17+ public function paginationInformation (array $ paginated , array $ default );
18+ }
Original file line number Diff line number Diff line change 2323use HyperfTest \Resource \Stubs \Models \Subscription ;
2424use HyperfTest \Resource \Stubs \Resources \AuthorResourceWithOptionalRelationship ;
2525use HyperfTest \Resource \Stubs \Resources \ObjectResource ;
26+ use HyperfTest \Resource \Stubs \Resources \PaginationCollection ;
2627use HyperfTest \Resource \Stubs \Resources \PostCollectionResource ;
2728use HyperfTest \Resource \Stubs \Resources \PostResource ;
2829use HyperfTest \Resource \Stubs \Resources \PostResourceWithExtraData ;
@@ -733,6 +734,27 @@ public function testItWontKeysIfAnyOfThemAreStrings()
733734 ], ['data ' => [0 => 10 , 1 => 20 , 'total ' => 30 ]]);
734735 }
735736
737+ public function testResourceCollectionPagination ()
738+ {
739+ $ this ->http (function () {
740+ $ paginator = new LengthAwarePaginator (
741+ collect ([new Post (['id ' => 5 , 'title ' => 'Test Title ' ])]),
742+ 10 ,
743+ 15 ,
744+ 1
745+ );
746+
747+ return new PaginationCollection ($ paginator );
748+ })->assertJson ([
749+ 'data ' => [
750+ [
751+ 'id ' => 5 ,
752+ 'title ' => 'Test Title ' ,
753+ ],
754+ ],
755+ ]);
756+ }
757+
736758 private function assertJsonResourceResponse ($ data , $ expectedJson )
737759 {
738760 $ this ->http (function () use ($ data ) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+ /**
5+ * This file is part of Hyperf.
6+ *
7+ * @link https://www.hyperf.io
8+ * @document https://hyperf.wiki
9+ * @contact group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+
13+ namespace HyperfTest \Resource \Stubs \Resources ;
14+
15+ use Hyperf \Resource \Json \ResourceCollection ;
16+ use Hyperf \Resource \Response \PaginationInformationInterface ;
17+
18+ class PaginationCollection extends ResourceCollection implements PaginationInformationInterface
19+ {
20+ public function paginationInformation (array $ paginated , array $ default ): array
21+ {
22+ return [];
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments