1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.9.7 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Paginator; |
16
|
|
|
|
17
|
|
|
use Quantum\Paginator\Exceptions\PaginatorException; |
18
|
|
|
use Quantum\Paginator\Contracts\PaginatorInterface; |
19
|
|
|
use Quantum\App\Exceptions\BaseException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Paginator |
23
|
|
|
* @package Quantum\Paginator |
24
|
|
|
* @method mixed data() |
25
|
|
|
* @method mixed firstItem() |
26
|
|
|
* @method mixed lastItem() |
27
|
|
|
* @method int currentPageNumber() |
28
|
|
|
* @method int|null previousPageNumber() |
29
|
|
|
* @method int|null nextPageNumber() |
30
|
|
|
* @method int lastPageNumber() |
31
|
|
|
* @method string|null currentPageLink(bool $withBaseUrl = false) |
32
|
|
|
* @method string|null firstPageLink(bool $withBaseUrl = false) |
33
|
|
|
* @method string|null previousPageLink(bool $withBaseUrl = false) |
34
|
|
|
* @method string|null nextPageLink(bool $withBaseUrl = false) |
35
|
|
|
* @method string|null lastPageLink(bool $withBaseUrl = false) |
36
|
|
|
* @method int perPage() |
37
|
|
|
* @method int total() |
38
|
|
|
* @method array links(bool $withBaseUrl = false) |
39
|
|
|
* @method string|null getPagination(bool $withBaseUrl = false, ?int $pageItemsCount = null) |
40
|
|
|
*/ |
41
|
|
|
class Paginator |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Array paginator type |
46
|
|
|
*/ |
47
|
|
|
const ARRAY = 'array'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Model paginator type |
51
|
|
|
*/ |
52
|
|
|
const MODEL = 'model'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var PaginatorInterface |
56
|
|
|
*/ |
57
|
|
|
private $adapter; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param PaginatorInterface $adapter |
61
|
|
|
*/ |
62
|
|
|
public function __construct(PaginatorInterface $adapter) |
63
|
|
|
{ |
64
|
|
|
$this->adapter = $adapter; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the adapter instance |
69
|
|
|
* @return PaginatorInterface |
70
|
|
|
*/ |
71
|
|
|
public function getAdapter(): PaginatorInterface |
72
|
|
|
{ |
73
|
|
|
return $this->adapter; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $method |
78
|
|
|
* @param array|null $arguments |
79
|
|
|
* @return mixed |
80
|
|
|
* @throws BaseException |
81
|
|
|
*/ |
82
|
|
|
public function __call(string $method, ?array $arguments) |
83
|
|
|
{ |
84
|
|
|
if (!method_exists($this->adapter, $method)) { |
85
|
|
|
throw PaginatorException::methodNotSupported($method, get_class($this->adapter)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->adapter->$method(...$arguments); |
89
|
|
|
} |
90
|
|
|
} |