1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Mgid\Component\Pagination; |
4
|
|
|
|
5
|
|
|
use Mgid\Component\Pagination\Validator; |
6
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @Assert\Sequentially({ |
10
|
|
|
* @Validator\Structure(), |
11
|
|
|
* @Validator\Limit(), |
12
|
|
|
* @Validator\Offset(), |
13
|
|
|
* @Validator\FieldName(), |
14
|
|
|
* @Validator\Operator(), |
15
|
|
|
* @Validator\Order(), |
16
|
|
|
* }) |
17
|
|
|
*/ |
18
|
|
|
class Input implements InputInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
private int $limit; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
private int $offset; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array<string,string> |
32
|
|
|
*/ |
33
|
|
|
private array $orders; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array<string,array<string,string>> |
37
|
|
|
*/ |
38
|
|
|
private array $filters; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param int $limit |
42
|
|
|
* @param int $offset |
43
|
|
|
* @param array<string,string> $orders |
44
|
|
|
* @param array<string,array<string,string>> $filters |
45
|
|
|
*/ |
46
|
|
|
public function __construct(int $limit = 20, int $offset = 0, array $orders = [], array $filters = []) |
47
|
|
|
{ |
48
|
|
|
$this->setLimit($limit); |
49
|
|
|
$this->setOffset($offset); |
50
|
|
|
$this->setOrders($orders); |
51
|
|
|
$this->setFilters($filters); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function setLimit(int $limit): void |
58
|
|
|
{ |
59
|
|
|
$this->limit = $limit; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getLimit(): int |
66
|
|
|
{ |
67
|
|
|
return $this->limit; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function setOffset(int $offset): void |
74
|
|
|
{ |
75
|
|
|
$this->offset = $offset; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getOffset(): int |
82
|
|
|
{ |
83
|
|
|
return $this->offset; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function setOrders(array $orders): void |
90
|
|
|
{ |
91
|
|
|
$this->orders = $orders; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function getOrders(): array |
98
|
|
|
{ |
99
|
|
|
return $this->orders; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function setFilters(array $filters): void |
106
|
|
|
{ |
107
|
|
|
$this->filters = $filters; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function getFilters(): array |
114
|
|
|
{ |
115
|
|
|
return $this->filters; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|