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 integer|array $limitInfos If it's a integer, the number of row to |
47
|
|
|
* return. If an array, the format is [offset, rowCount] |
48
|
|
|
*/ |
49
|
|
|
public function __invoke(...$limitInfos) |
50
|
|
|
{ |
51
|
|
|
if (isset($limitInfos[1])) { |
52
|
|
|
$this->offset = (int) $limitInfos[0]; |
53
|
|
|
$this->rowCount = (int) $limitInfos[1]; |
54
|
|
|
} else { |
55
|
|
|
$this->rowCount = (int) $limitInfos[0]; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function generate(): string |
63
|
|
|
{ |
64
|
|
|
if ($this->rowCount === null) { |
65
|
|
|
return ''; |
66
|
|
|
} else if ($this->offset === null) { |
67
|
|
|
return (string) $this->rowCount; |
68
|
|
|
} else { |
69
|
|
|
return $this->offset.', '.$this->rowCount; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|