1 | <?php |
||
36 | abstract class AbstractRow implements Iterator, Countable, ArrayAccess |
||
37 | { |
||
38 | /** |
||
39 | * An array of fields for this row |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $fields; |
||
43 | |||
44 | /** |
||
45 | * Iterator position |
||
46 | * @var int |
||
47 | */ |
||
48 | protected $position; |
||
49 | |||
50 | /** |
||
51 | * Class constructor |
||
52 | * |
||
53 | * @param array|Iterator An array (or anything that looks like one) of data (fields) |
||
54 | * @access public |
||
55 | */ |
||
56 | 59 | public function __construct($fields) |
|
61 | |||
62 | 59 | protected function setFields($fields) |
|
76 | |||
77 | 1 | public function __toString() |
|
81 | |||
82 | /** |
||
83 | * Join fields together using specified delimiter |
||
84 | * |
||
85 | * @param char The delimiter character |
||
86 | * @return string |
||
87 | * @access public |
||
88 | */ |
||
89 | 17 | public function join($delimiter = ',') |
|
93 | |||
94 | /** |
||
95 | * Convert object to an array |
||
96 | * |
||
97 | * @return array representation of the object |
||
98 | * @access public |
||
99 | */ |
||
100 | 27 | public function toArray() |
|
104 | |||
105 | /** Begin SPL Countable Interface Method **/ |
||
106 | |||
107 | /** |
||
108 | * Count fields within the row |
||
109 | * |
||
110 | * @return integer The amount of fields |
||
111 | * @access public |
||
112 | */ |
||
113 | 21 | public function count() |
|
117 | |||
118 | /** Begin SPL Iterator Interface Methods **/ |
||
119 | |||
120 | /** |
||
121 | * Get the current column's data object |
||
122 | * |
||
123 | * @return string |
||
124 | * @access public |
||
125 | */ |
||
126 | 58 | public function current() |
|
130 | |||
131 | /** |
||
132 | * Get the current key (column number or header, if available) |
||
133 | * |
||
134 | * @return string The "current" key |
||
135 | * @access public |
||
136 | * @todo Figure out if this can return a CSVelte\Table\HeaderData object so long as it |
||
137 | * has a __toString() method that generated the right key... |
||
138 | */ |
||
139 | 20 | public function key() |
|
143 | |||
144 | /** |
||
145 | * Advance the internal pointer to the next column's data object |
||
146 | * Also returns the next column's data object if there is one |
||
147 | * |
||
148 | * @return CSVelte\Table\Data The "next" column's data |
||
149 | * @access public |
||
150 | */ |
||
151 | 32 | public function next() |
|
156 | |||
157 | /** |
||
158 | * Return the internal pointer to the first column and return that object |
||
159 | * |
||
160 | * @return void |
||
161 | * @access public |
||
162 | */ |
||
163 | 58 | public function rewind() |
|
168 | |||
169 | /** |
||
170 | * Is the current position within the row's data fields valid? |
||
171 | * |
||
172 | * @return boolean |
||
173 | * @access public |
||
174 | */ |
||
175 | 58 | public function valid() |
|
179 | |||
180 | /** Begin SPL ArrayAccess Methods **/ |
||
181 | |||
182 | /** |
||
183 | * Is there an offset at specified position |
||
184 | * |
||
185 | * @param integer Offset |
||
186 | * @return boolean |
||
187 | * @access public |
||
188 | */ |
||
189 | 5 | public function offsetExists($offset) |
|
198 | |||
199 | /** |
||
200 | * Retrieve offset at specified position or by header name |
||
201 | * |
||
202 | * @param integer|string Offset/index |
||
203 | * @return CSVelte\Table\Data |
||
204 | * @access public |
||
205 | */ |
||
206 | 4 | public function offsetGet($offset) |
|
211 | |||
212 | /** |
||
213 | * Set offset at specified position |
||
214 | * |
||
215 | * @param integer|string Offset/index |
||
216 | * @param CSVelte\Table\Data |
||
217 | * @return void |
||
218 | * @access public |
||
219 | * @throws CSVelte\Exception\ImmutableException |
||
220 | */ |
||
221 | 2 | public function offsetSet($offset, $value) |
|
226 | |||
227 | /** |
||
228 | * Unset offset at specified position/index |
||
229 | * |
||
230 | * @param integer|string Offset/index |
||
231 | * @return void |
||
232 | * @access public |
||
233 | * @throws CSVelte\Exception\ImmutableException |
||
234 | * @todo I'm not sure if these objects will stay immutable or not yet... |
||
235 | */ |
||
236 | 1 | public function offsetUnset($offset) |
|
240 | |||
241 | /** |
||
242 | * Throw exception unless offset/index exists |
||
243 | * |
||
244 | * @param integer|string Offset/index |
||
245 | * @return void |
||
246 | * @access protected |
||
247 | * @throws \OutOfBoundsException |
||
248 | */ |
||
249 | 4 | protected function assertOffsetExists($offset) |
|
255 | |||
256 | /** |
||
257 | * Raise (throw) immutable exception |
||
258 | * |
||
259 | * @param string Message |
||
260 | * @return void |
||
261 | * @access protected |
||
262 | * @throws CSVelte\Exception\ImmutableException |
||
263 | */ |
||
264 | 3 | protected function raiseImmutableException($msg = null) |
|
269 | } |
||
270 |