1 | <?php |
||
19 | class PagerService |
||
20 | { |
||
21 | /** |
||
22 | * @var int Current page. |
||
23 | */ |
||
24 | private $page; |
||
25 | |||
26 | /** |
||
27 | * @var int Number of items per page. |
||
28 | */ |
||
29 | private $limit; |
||
30 | |||
31 | /** |
||
32 | * @var int Maximum number of pages. |
||
33 | */ |
||
34 | private $maxPages; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | * |
||
39 | * @param PagerAdapterInterface $adapter The pager adapter. |
||
40 | * @param array $options Additional options. |
||
41 | */ |
||
42 | public function __construct(PagerAdapterInterface $adapter, array $options = []) |
||
52 | |||
53 | /** |
||
54 | * Sets the required options. |
||
55 | * |
||
56 | * @param OptionsResolver $resolver |
||
57 | */ |
||
58 | private function setRequiredOptions(OptionsResolver $resolver) |
||
64 | |||
65 | /** |
||
66 | * Sets the current page number. |
||
67 | * |
||
68 | * @param int $page The current page number. |
||
69 | */ |
||
70 | public function setPage($page) |
||
74 | |||
75 | /** |
||
76 | * Returns the current page number. |
||
77 | * |
||
78 | * @return int |
||
79 | */ |
||
80 | public function getPage() |
||
84 | |||
85 | /** |
||
86 | * Sets the results limit for one page. |
||
87 | * |
||
88 | * @param int $limit |
||
89 | */ |
||
90 | public function setLimit($limit) |
||
96 | |||
97 | /** |
||
98 | * Returns the current results limit for one page. |
||
99 | * |
||
100 | * @return int |
||
101 | */ |
||
102 | public function getLimit() |
||
106 | |||
107 | /** |
||
108 | * Sets the number of pages shown. |
||
109 | * |
||
110 | * @param int $maxPages |
||
111 | */ |
||
112 | public function setMaxPages($maxPages) |
||
116 | |||
117 | /** |
||
118 | * Returns the number of pages shown. |
||
119 | * |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getMaxPages() |
||
126 | |||
127 | /** |
||
128 | * Returns the next page number. |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | public function getNextPage() |
||
138 | |||
139 | /** |
||
140 | * Returns the previous page number. |
||
141 | * |
||
142 | * @return int |
||
143 | */ |
||
144 | public function getPreviousPage() |
||
148 | |||
149 | /** |
||
150 | * Returns true if the current page is first. |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function isFirstPage() |
||
158 | |||
159 | /** |
||
160 | * Returns the first page number. |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | public function getFirstPage() |
||
168 | |||
169 | /** |
||
170 | * Returns true if the current page is last. |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function isLastPage() |
||
178 | |||
179 | /** |
||
180 | * Returns the last page number. |
||
181 | * |
||
182 | * @return int |
||
183 | */ |
||
184 | public function getLastPage() |
||
188 | |||
189 | /** |
||
190 | * Returns true if the current result set requires pagination. |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function isPaginable() |
||
198 | |||
199 | /** |
||
200 | * Generates a page list. |
||
201 | * |
||
202 | * @return array The page list. |
||
203 | */ |
||
204 | public function getPages() |
||
226 | |||
227 | /** |
||
228 | * Returns true if the current result set is not empty. |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function hasResults() |
||
236 | |||
237 | /** |
||
238 | * Returns results list for the current page and limit. |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | public function getResults() |
||
246 | |||
247 | /** |
||
248 | * Returns offset. |
||
249 | * |
||
250 | * @return int |
||
251 | */ |
||
252 | public function getOffset() |
||
256 | |||
257 | /** |
||
258 | * Returns the current adapter instance. |
||
259 | * |
||
260 | * @return PagerAdapterInterface |
||
261 | */ |
||
262 | public function getAdapter() |
||
266 | } |
||
267 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: