12
12
13
13
namespace chillerlan \Database ;
14
14
15
- use ArrayAccess , Countable , Iterator ;
16
- use chillerlan \Database \Traits \{Enumerable , Magic };
15
+ use ArrayAccess , Countable , SeekableIterator ;
16
+ use chillerlan \Traits \{
17
+ Enumerable , Magic , Interfaces \ArrayAccessTrait , SPL \SeekableIteratorTrait , SPL \CountableTrait
18
+ };
17
19
18
20
/**
19
21
* @property int $length
20
22
*
21
23
* each($func [, $fieldname)
22
24
*/
23
- class Result implements Iterator , ArrayAccess, Countable{
24
- use Enumerable, Magic;
25
+ class Result implements SeekableIterator , ArrayAccess, Countable{
26
+ use ArrayAccessTrait, SeekableIteratorTrait, CountableTrait, Magic, Enumerable ;
25
27
26
28
/**
27
29
* @var \chillerlan\Database\ResultRow[]
@@ -52,11 +54,11 @@ class Result implements Iterator, ArrayAccess, Countable{
52
54
*
53
55
* @throws \chillerlan\Database\ConnectionException
54
56
*/
55
- public function __construct ($ data = null , $ sourceEncoding = null , $ destEncoding = ' UTF-8 ' ){
57
+ public function __construct ($ data = null , string $ sourceEncoding = null , string $ destEncoding = null ){
56
58
$ this ->sourceEncoding = $ sourceEncoding ;
57
- $ this ->destEncoding = $ destEncoding ;
59
+ $ this ->destEncoding = $ destEncoding ?? ' UTF-8 ' ;
58
60
59
- if (is_null ( $ data) ){
61
+ if ($ data === null ){
60
62
$ data = [];
61
63
}
62
64
else if ($ data instanceof \Traversable){
@@ -130,24 +132,6 @@ protected function magic_get_length():int{
130
132
* ArrayAccess *
131
133
***************/
132
134
133
- /**
134
- * @param int|string $offset
135
- *
136
- * @return bool
137
- */
138
- public function offsetExists ($ offset ):bool {
139
- return isset ($ this ->array [$ offset ]);
140
- }
141
-
142
- /**
143
- * @param int|string $offset
144
- *
145
- * @return \chillerlan\Database\ResultRow|mixed|null
146
- */
147
- public function offsetGet ($ offset ){
148
- return $ this ->array [$ offset ] ?? null ;
149
- }
150
-
151
135
/**
152
136
* @param int|string $offset
153
137
* @param array $value
@@ -165,65 +149,4 @@ public function offsetSet($offset, $value){
165
149
166
150
}
167
151
168
- /**
169
- * @param int|string $offset
170
- *
171
- * @return void
172
- */
173
- public function offsetUnset ($ offset ){
174
- unset($ this ->array [$ offset ]);
175
- }
176
-
177
-
178
- /*************
179
- * Countable *
180
- *************/
181
-
182
- /**
183
- * @return int
184
- */
185
- public function count ():int {
186
- return count ($ this ->array );
187
- }
188
-
189
-
190
- /************
191
- * Iterator *
192
- ************/
193
-
194
- /**
195
- * @return \chillerlan\Database\ResultRow|mixed
196
- */
197
- public function current (){
198
- return $ this ->offsetGet ($ this ->offset );
199
- }
200
-
201
- /**
202
- * @return int
203
- */
204
- public function key ():int {
205
- return $ this ->offset ;
206
- }
207
-
208
- /**
209
- * @return bool
210
- */
211
- public function valid ():bool {
212
- return $ this ->offsetExists ($ this ->offset );
213
- }
214
-
215
- /**
216
- * @return void
217
- */
218
- public function next (){
219
- $ this ->offset ++;
220
- }
221
-
222
- /**
223
- * @return void
224
- */
225
- public function rewind (){
226
- $ this ->offset = 0 ;
227
- }
228
-
229
152
}
0 commit comments