1 | <?php |
||
8 | class Resultset implements ResultInterface |
||
9 | { |
||
10 | const TYPE_ARRAYOBJECT = 'arrayobject'; |
||
11 | const TYPE_ARRAY = 'array'; |
||
12 | |||
13 | /** |
||
14 | * Allowed return types. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $allowedReturnTypes = [ |
||
19 | self::TYPE_ARRAYOBJECT, |
||
20 | self::TYPE_ARRAY, |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * Return type to use when returning an object from the set. |
||
25 | * |
||
26 | * @var string ResultSet::TYPE_ARRAYOBJECT|ResultSet::TYPE_ARRAY |
||
27 | */ |
||
28 | protected $returnType = self::TYPE_ARRAY; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $position = 0; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $count = 0; |
||
39 | |||
40 | /** |
||
41 | * @var array|ArrayObject |
||
42 | */ |
||
43 | protected $storage; |
||
44 | |||
45 | /** |
||
46 | * Constructor. |
||
47 | * |
||
48 | * @throws Exception\InvalidArgumentException |
||
49 | * |
||
50 | * @param string $returnType |
||
51 | */ |
||
52 | 23 | public function __construct($returnType = self::TYPE_ARRAY) |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | * |
||
70 | * @return array|ArrayObject |
||
71 | */ |
||
72 | 3 | public function current() |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | * |
||
80 | * @return int position |
||
81 | */ |
||
82 | 1 | public function key() |
|
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | 3 | public function next() |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 3 | public function rewind() |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 3 | public function valid() |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 6 | public function count() |
|
118 | |||
119 | /** |
||
120 | * Append a row to the end of resultset. |
||
121 | * |
||
122 | * @param array $row an associative array |
||
123 | */ |
||
124 | 16 | public function append(array $row) |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 1 | public function offsetExists($position) |
|
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | 10 | public function offsetGet($position) |
|
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | 1 | public function offsetSet($position, $row) |
|
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | 1 | public function offsetUnset($position) |
|
165 | |||
166 | /** |
||
167 | * Return underlying stored resultset as array. |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | 2 | public function getArray() |
|
175 | |||
176 | /** |
||
177 | * Return underlying stored resultset as ArrayObject. |
||
178 | * |
||
179 | * Depending on the $returnType Resultset::TYPE_ARRAY|Resultset::TYPE_ARRAYOBJECT you can modify |
||
180 | * the internal storage |
||
181 | * |
||
182 | * @return ArrayObject |
||
183 | */ |
||
184 | 2 | public function getArrayObject() |
|
195 | |||
196 | /** |
||
197 | * Return the currently set return type. |
||
198 | * |
||
199 | * @see Resultset::TYPE_ARRAY|Resultset::TYPE_ARRAYOBJECT |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | 1 | public function getReturnType() |
|
207 | } |
||
208 |