1 | <?php |
||
26 | class Statement |
||
27 | { |
||
28 | /** |
||
29 | * Callables to filter the iterator. |
||
30 | * |
||
31 | * @var callable[] |
||
32 | */ |
||
33 | protected $where = []; |
||
34 | |||
35 | /** |
||
36 | * Callables to sort the iterator. |
||
37 | * |
||
38 | * @var callable[] |
||
39 | */ |
||
40 | protected $order_by = []; |
||
41 | |||
42 | /** |
||
43 | * iterator Offset. |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | protected $offset = 0; |
||
48 | |||
49 | /** |
||
50 | * iterator maximum length. |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $limit = -1; |
||
55 | |||
56 | /** |
||
57 | * Named Constructor to ease Statement instantiation. |
||
58 | * |
||
59 | * @throws Exception |
||
60 | */ |
||
61 | 9 | public static function create(callable $where = null, int $offset = 0, int $limit = -1): self |
|
70 | |||
71 | /** |
||
72 | * Set the Iterator filter method. |
||
73 | */ |
||
74 | 3 | public function where(callable $callable): self |
|
81 | |||
82 | /** |
||
83 | * Set an Iterator sorting callable function. |
||
84 | */ |
||
85 | 6 | public function orderBy(callable $callable): self |
|
92 | |||
93 | /** |
||
94 | * Set LimitIterator Offset. |
||
95 | * |
||
96 | * @throws Exception if the offset is lesser than 0 |
||
97 | */ |
||
98 | 21 | public function offset(int $offset): self |
|
113 | |||
114 | /** |
||
115 | * Set LimitIterator Count. |
||
116 | * |
||
117 | * @throws Exception if the limit is lesser than -1 |
||
118 | */ |
||
119 | 42 | public function limit(int $limit): self |
|
134 | |||
135 | /** |
||
136 | * Execute the prepared Statement on the {@link Reader} object. |
||
137 | * |
||
138 | * @param Reader|ResultSet $records |
||
139 | * @param string[] $header an optional header to use instead of the CSV document header |
||
140 | */ |
||
141 | 33 | public function process($records, array $header = []): ResultSet |
|
163 | |||
164 | /** |
||
165 | * Filters elements of an Iterator using a callback function. |
||
166 | */ |
||
167 | 6 | protected function filter(Iterator $iterator, callable $callable): CallbackFilterIterator |
|
171 | |||
172 | /** |
||
173 | * Sort the Iterator. |
||
174 | */ |
||
175 | 21 | protected function buildOrderBy(Iterator $iterator): Iterator |
|
199 | } |
||
200 |