1 | <?php |
||
16 | class CursorPaginator |
||
17 | { |
||
18 | /** |
||
19 | * A list of the items being paginated. |
||
20 | * |
||
21 | * @var \Illuminate\Support\Collection |
||
22 | */ |
||
23 | protected $items; |
||
24 | |||
25 | /** |
||
26 | * The current cursor reference. |
||
27 | * |
||
28 | * @var int|string|null |
||
29 | */ |
||
30 | protected $cursor; |
||
31 | |||
32 | /** |
||
33 | * The previous cursor reference. |
||
34 | * |
||
35 | * @var int|string|null |
||
36 | */ |
||
37 | protected $previousCursor; |
||
38 | |||
39 | /** |
||
40 | * The next cursor reference. |
||
41 | * |
||
42 | * @var int|string|null |
||
43 | */ |
||
44 | protected $nextCursor; |
||
45 | |||
46 | /** |
||
47 | * The current cursor resolver callback. |
||
48 | * |
||
49 | * @var \Closure|null |
||
50 | */ |
||
51 | protected static $currentCursorResolver; |
||
52 | |||
53 | /** |
||
54 | * Create a new paginator instance. |
||
55 | * |
||
56 | * @param \Illuminate\Support\Collection|array|null $data |
||
57 | * @param int|string|null $cursor |
||
58 | * @param int|string|null $previousCursor |
||
59 | * @param int|string|null $nextCursor |
||
60 | */ |
||
61 | 3 | public function __construct($data, $cursor, $previousCursor, $nextCursor) |
|
69 | |||
70 | /** |
||
71 | * Retrieve the current cursor reference. |
||
72 | * |
||
73 | * @return int|string|null |
||
74 | */ |
||
75 | 1 | public function cursor() |
|
79 | |||
80 | /** |
||
81 | * Retireve the next cursor reference. |
||
82 | * |
||
83 | * @return int|string|null |
||
84 | */ |
||
85 | 1 | public function previous() |
|
89 | |||
90 | /** |
||
91 | * Retireve the next cursor reference. |
||
92 | * |
||
93 | * @return int|string|null |
||
94 | */ |
||
95 | 1 | public function next() |
|
99 | |||
100 | /** |
||
101 | * Get the slice of items being paginated. |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | 2 | public function items(): array |
|
109 | |||
110 | /** |
||
111 | * Get the paginator's underlying collection. |
||
112 | * |
||
113 | * @return \Illuminate\Support\Collection |
||
114 | */ |
||
115 | 1 | public function get(): Collection |
|
119 | |||
120 | /** |
||
121 | * Set the paginator's underlying collection. |
||
122 | * |
||
123 | * @param \Illuminate\Support\Collection|array|null $data |
||
124 | * @return self |
||
125 | */ |
||
126 | 3 | public function set($data): CursorPaginator |
|
132 | |||
133 | /** |
||
134 | * Resolve the current cursor using the cursor resolver. |
||
135 | * |
||
136 | * @param string $name |
||
137 | * @return mixed |
||
138 | * @throws \LogicException |
||
139 | */ |
||
140 | 2 | public static function resolveCursor(string $name = 'cursor') |
|
148 | |||
149 | /** |
||
150 | * Set the current cursor resolver callback. |
||
151 | * |
||
152 | * @param \Closure $resolver |
||
153 | * @return void |
||
154 | */ |
||
155 | 1 | public static function cursorResolver(Closure $resolver) |
|
159 | } |
||
160 |