1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BfwSql\Queries\Parts; |
4
|
|
|
|
5
|
|
|
class Limit extends AbstractPart |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* {@inheritdoc} |
9
|
|
|
*/ |
10
|
|
|
protected $partPrefix = 'LIMIT'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var integer|null $rowCount The maximum number of rows to return |
14
|
|
|
*/ |
15
|
|
|
protected $rowCount = null; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var integer|null $offset The offset of the first row to return |
19
|
|
|
*/ |
20
|
|
|
protected $offset = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Getter accessor to property rowCount |
24
|
|
|
* |
25
|
|
|
* @return integer|null |
26
|
|
|
*/ |
27
|
|
|
public function getRowCount() |
28
|
|
|
{ |
29
|
|
|
return $this->rowCount; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Getter accessor to property offset |
34
|
|
|
* |
35
|
|
|
* @return integer|null |
36
|
|
|
*/ |
37
|
|
|
public function getOffset() |
38
|
|
|
{ |
39
|
|
|
return $this->offset; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Magic method __invoke, used when the user call object like a function |
44
|
|
|
* @link http://php.net/manual/en/language.oop5.magic.php#object.invoke |
45
|
|
|
* |
46
|
|
|
* @param array $limitInfos If one args, the number of row to return. |
47
|
|
|
* If two args, the first is the offset, the second is the number |
48
|
|
|
* of row to return. |
49
|
|
|
*/ |
50
|
|
|
public function __invoke(...$limitInfos) |
51
|
|
|
{ |
52
|
|
|
$this->invokeCheckIsDisabled(); |
53
|
|
|
|
54
|
|
|
if (isset($limitInfos[1])) { |
55
|
|
|
$this->offset = (int) $limitInfos[0]; |
56
|
|
|
$this->rowCount = (int) $limitInfos[1]; |
57
|
|
|
} else { |
58
|
|
|
$this->rowCount = (int) $limitInfos[0]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function generate(): string |
66
|
|
|
{ |
67
|
|
|
if ($this->isDisabled === true) { |
68
|
|
|
return ''; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->querySystem |
72
|
|
|
->getQuerySgbd() |
73
|
|
|
->limit($this->rowCount, $this->offset) |
74
|
|
|
; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|