1 | <?php |
||
29 | class Pagination |
||
30 | { |
||
31 | /** |
||
32 | * @var int The max number of records to return |
||
33 | */ |
||
34 | protected $max; |
||
35 | /** |
||
36 | * @var int The offset in the records |
||
37 | */ |
||
38 | protected $offset; |
||
39 | /** |
||
40 | * @var array<string,bool> Associative array of field names to boolean values |
||
41 | */ |
||
42 | protected $order = []; |
||
43 | |||
44 | /** |
||
45 | * Creates a new Pagination object. |
||
46 | * |
||
47 | * ```php |
||
48 | * // equivalent to ORDER BY foo ASC, bar DESC LIMIT 20 OFFSET 10 |
||
49 | * $pagination = new \Caridea\Http\Pagination(20, 10, ['foo' => true, 'bar' => false]); |
||
50 | * ``` |
||
51 | * |
||
52 | * @param int $max The max number of records to return. If zero or any negative number is provided, this defaults to `PHP_INT_MAX` |
||
53 | * @param int $offset The offset in the records. If a negative number is provided, this defaults to `0` |
||
54 | * @param array<string,bool> $order Associative array of field names to boolean values (`true` = ascending, `false` = descending). Any non-boolean value (`1` included) will evaluate as `false`. |
||
55 | */ |
||
56 | 2 | public function __construct(int $max, int $offset, $order = []) |
|
66 | |||
67 | 2 | private function normalize(int $value, int $default): int |
|
71 | |||
72 | /** |
||
73 | * Gets the max number of records to return. |
||
74 | * |
||
75 | * @return int The max number of records to return |
||
76 | */ |
||
77 | 2 | public function getMax(): int |
|
81 | |||
82 | /** |
||
83 | * Gets the offset in the records. |
||
84 | * |
||
85 | * @return int The offset in the records |
||
86 | */ |
||
87 | 2 | public function getOffset(): int |
|
91 | |||
92 | /** |
||
93 | * Gets the field ordering. |
||
94 | * |
||
95 | * Array keys are field names, values are `true` for ascending, `false` for descending. |
||
96 | * |
||
97 | * @return array<string,bool> The field order |
||
98 | */ |
||
99 | 2 | public function getOrder(): array |
|
103 | } |
||
104 |