1 | <?php |
||
39 | abstract class AbstractRow implements Iterator, Countable, ArrayAccess |
||
40 | { |
||
41 | /** |
||
42 | * An collection of fields for this row. |
||
43 | * |
||
44 | * @var AbstractCollection |
||
45 | */ |
||
46 | protected $fields; |
||
47 | |||
48 | /** |
||
49 | * Iterator position. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $position; |
||
54 | |||
55 | /** |
||
56 | * Class constructor. |
||
57 | * |
||
58 | * @param array|Iterator An array (or anything that looks like one) of data (fields) |
||
59 | * @param mixed $fields |
||
60 | */ |
||
61 | public function __construct($fields) |
||
66 | |||
67 | /** |
||
68 | * Return a string representation of this object. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function __toString() |
||
76 | |||
77 | /** |
||
78 | * Join fields together using specified delimiter. |
||
79 | * |
||
80 | * @param string The delimiter character |
||
81 | * @param mixed $delimiter |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function join($delimiter = ',') |
||
89 | |||
90 | /** |
||
91 | * Convert object to an array. |
||
92 | * |
||
93 | * @return array representation of the object |
||
94 | */ |
||
95 | public function toArray() |
||
99 | |||
100 | // Begin SPL Countable Interface Method |
||
101 | |||
102 | /** |
||
103 | * Count fields within the row. |
||
104 | * |
||
105 | * @return int The amount of fields |
||
106 | */ |
||
107 | public function count() |
||
111 | |||
112 | // Begin SPL Iterator Interface Methods |
||
113 | |||
114 | /** |
||
115 | * Get the current column's data object. |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function current() |
||
123 | |||
124 | /** |
||
125 | * Get the current key (column number or header, if available). |
||
126 | * |
||
127 | * @return string The "current" key |
||
128 | * |
||
129 | * @todo Figure out if this can return a CSVelte\Table\HeaderData object so long as it |
||
130 | * has a __toString() method that generated the right key... |
||
131 | */ |
||
132 | public function key() |
||
136 | |||
137 | /** |
||
138 | * Advance the internal pointer to the next column's data object |
||
139 | * Also returns the next column's data object if there is one. |
||
140 | * |
||
141 | * @return mixed The "next" column's data |
||
142 | */ |
||
143 | public function next() |
||
150 | |||
151 | /** |
||
152 | * Return the internal pointer to the first column and return that object. |
||
153 | * |
||
154 | * @return null|mixed|AbstractRow |
||
155 | */ |
||
156 | public function rewind() |
||
163 | |||
164 | /** |
||
165 | * Is the current position within the row's data fields valid? |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function valid() |
||
173 | |||
174 | // Begin SPL ArrayAccess Methods |
||
175 | |||
176 | /** |
||
177 | * Is there an offset at specified position. |
||
178 | * |
||
179 | * @param mixed $offset The offset to check existence of |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function offsetExists($offset) |
||
187 | |||
188 | /** |
||
189 | * Retrieve offset at specified position or by header name. |
||
190 | * |
||
191 | * @param mixed $offset The offset to get |
||
192 | * |
||
193 | * @return mixed The data at the specified position |
||
194 | */ |
||
195 | public function offsetGet($offset) |
||
199 | |||
200 | /** |
||
201 | * Set offset at specified position. |
||
202 | * |
||
203 | * @param mixed $offset The array offset to set |
||
204 | * @param mixed $value The value to set $offset to |
||
205 | * |
||
206 | * @throws ImmutableException |
||
207 | */ |
||
208 | public function offsetSet($offset, $value) |
||
213 | |||
214 | /** |
||
215 | * Unset offset at specified position/index. |
||
216 | * |
||
217 | * @param mixed $offset The offset to unset |
||
218 | * |
||
219 | * @throws ImmutableException |
||
220 | * |
||
221 | * @todo I'm not sure if these objects will stay immutable or not yet... |
||
222 | */ |
||
223 | public function offsetUnset($offset) |
||
227 | |||
228 | /** |
||
229 | * Set the row fields. |
||
230 | * |
||
231 | * Using either an array or iterator, set the fields for this row. |
||
232 | * |
||
233 | * @param array|Iterator $fields An array or iterator with the row's fields |
||
234 | * |
||
235 | * @return $this |
||
236 | */ |
||
237 | protected function setFields($fields) |
||
252 | |||
253 | /** |
||
254 | * Raise (throw) immutable exception. |
||
255 | * |
||
256 | * @param string $msg The message to pass to the exception |
||
257 | * |
||
258 | * @throws ImmutableException |
||
259 | */ |
||
260 | protected function raiseImmutableException($msg = null) |
||
265 | } |
||
266 |