-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLimitTrait.php
More file actions
65 lines (54 loc) · 1.17 KB
/
LimitTrait.php
File metadata and controls
65 lines (54 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace ModernPDO\Traits;
use ModernPDO\Escaper;
/**
* Trait for working with 'limit'.
*/
trait LimitTrait
{
/**
* @var int limit count
*/
protected int $limitCount = 0;
/**
* @var int limit offset
*/
protected int $limitOffset = 0;
/**
* Returns set query.
*/
protected function limitQuery(Escaper $escaper): string
{
if ($this->limitCount <= 0) {
return '';
}
$query = 'LIMIT ' . $this->limitCount;
if ($this->limitOffset > 0) {
$query .= ' OFFSET ' . $this->limitOffset;
}
return $query;
}
/**
* Returns set placeholders.
*
* @return list<mixed>
*/
protected function limitPlaceholders(): array
{
return [];
}
/**
* Set values for limit.
*
* @param int $count count of rows. It must be greater than 0
* @param int $offset start rows offset. It must be greater than 0
*
* @return $this
*/
public function limit(int $count, int $offset = 0): object
{
$this->limitCount = $count;
$this->limitOffset = $offset;
return $this;
}
}