-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PagerInterface.php
98 lines (83 loc) · 2.41 KB
/
PagerInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace SonsOfPHP\Contract\Pager;
use Countable;
use InvalidArgumentException;
use IteratorAggregate;
use JsonSerializable;
/**
* The pager should take an adapter and optional arguments when being created.
*
* Example:
* new Pager($adapter, ['current_page' => 2, 'max_per_page' => 10]);
*
* @author Joshua Estes <joshua@sonsofphp.com>
*/
interface PagerInterface extends Countable, IteratorAggregate, JsonSerializable
{
/**
* This will return the current results based on the current page and max
* results per page
*/
public function getCurrentPageResults(): iterable;
/**
* Returns the total number of results that the adapter can return
*/
public function getTotalResults(): int;
/**
* Returns the total number of pages that exist based on the total results
* and the max results per page
*/
public function getTotalPages(): int;
/**
* Returns true if there are 2 or more total pages
*/
public function haveToPaginate(): bool;
/**
* If there is a previous page available, this will return true
*/
public function hasPreviousPage(): bool;
/**
* If there is no previous page, this will return null
*/
public function getPreviousPage(): ?int;
/**
* If there is a next page available, this will return true
*/
public function hasNextPage(): bool;
/**
* If there is no next page, this will return null
*/
public function getNextPage(): ?int;
/**
* Returns the current page
*
* This should default to 1 if no current page is set.
*/
public function getCurrentPage(): int;
/**
* The page must be 1 or greater
*
* If the page is out of bounds, this may throw an exception
*
* @throws InvalidArgumentException
* If $page is invalid
*/
public function setCurrentPage(int $page): void;
/**
* This should return a default value if not set
*
* If max per page is set to null, this will return null
*/
public function getMaxPerPage(): ?int;
/**
* The max per page should be a value of 1 or greater.
*
* If the value is set to null, and results are grabbed, all the results
* will be returned.
*
* @throws InvalidArgumentException
* If $maxPerPage is invalid
*/
public function setMaxPerPage(?int $maxPerPage): void;
}