|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/* |
|
5
|
|
|
* soluble-flexstore library |
|
6
|
|
|
* |
|
7
|
|
|
* @author Vanvelthem Sébastien |
|
8
|
|
|
* @link https://github.com/belgattitude/soluble-flexstore |
|
9
|
|
|
* @copyright Copyright (c) 2016-2017 Vanvelthem Sébastien |
|
10
|
|
|
* @license MIT License https://github.com/belgattitude/soluble-flexstore/blob/master/LICENSE.md |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Soluble\FlexStore; |
|
15
|
|
|
|
|
16
|
|
|
use Soluble\FlexStore\Options\HydrationOptions; |
|
17
|
|
|
|
|
18
|
|
|
class Options |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var HydrationOptions |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $hydrationOptions; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var int|null |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $limit; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var int|null |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $offset; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Set the (maximum) number of results to return. |
|
37
|
|
|
*/ |
|
38
|
12 |
|
public function setLimit(int $limit, ?int $offset = null): self |
|
39
|
|
|
{ |
|
40
|
12 |
|
$this->limit = $limit; |
|
41
|
12 |
|
if ($offset !== null) { |
|
42
|
7 |
|
$this->setOffset($offset); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
12 |
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
19 |
|
public function getLimit(): ?int |
|
49
|
|
|
{ |
|
50
|
19 |
|
return $this->limit; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Unset limit of results |
|
55
|
|
|
* Provides fluent interface. |
|
56
|
|
|
* |
|
57
|
|
|
* @param bool $unset_offset whether to unset offset as well |
|
58
|
|
|
* |
|
59
|
|
|
* @return Options |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function unsetLimit($unset_offset = true): self |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->limit = null; |
|
64
|
1 |
|
if ($unset_offset) { |
|
65
|
1 |
|
$this->offset = null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Tells whether the option contains a limit. |
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
43 |
|
public function hasLimit(): bool |
|
77
|
|
|
{ |
|
78
|
43 |
|
return $this->limit !== null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Tells whether the option contains an offset. |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
12 |
|
public function hasOffset(): bool |
|
87
|
|
|
{ |
|
88
|
12 |
|
return $this->offset !== null; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set the offset (the record to start reading when using limit). |
|
93
|
|
|
*/ |
|
94
|
7 |
|
public function setOffset(int $offset): self |
|
95
|
|
|
{ |
|
96
|
7 |
|
$this->offset = $offset; |
|
97
|
|
|
|
|
98
|
7 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return the offset when using limit |
|
103
|
|
|
* Offset gives the record number to start reading |
|
104
|
|
|
* from when a paging query is in use. |
|
105
|
|
|
* |
|
106
|
|
|
* @return int|null |
|
107
|
|
|
*/ |
|
108
|
15 |
|
public function getOffset() |
|
109
|
|
|
{ |
|
110
|
15 |
|
return $this->offset; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Unset previously set offset. |
|
115
|
|
|
* |
|
116
|
|
|
* @return Options |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function unsetOffset() |
|
119
|
|
|
{ |
|
120
|
1 |
|
$this->offset = null; |
|
121
|
|
|
|
|
122
|
1 |
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
40 |
|
public function getHydrationOptions(): HydrationOptions |
|
126
|
|
|
{ |
|
127
|
40 |
|
if ($this->hydrationOptions === null) { |
|
128
|
40 |
|
$this->hydrationOptions = new HydrationOptions(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
40 |
|
return $this->hydrationOptions; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|