## Apache Zeta Components Manual :: File Source for row.php

## Source for file row.php

Documentation is available at row.php

1. <?php
2. /**
3. * File containing the ezcConsoleTableRow class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @package ConsoleTools
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * Structure representing a table row in ezcConsoleTable.
30. * This class represents a row in a table object. You can access
31. * the properties of the row directly, but also access the cells of
32. * the row directly, as if the object was an array (index 0..).
33. *
34. * <code>
35. * // Create new table row
36. * $row = new ezcConsoleTableRow();
37. *
38. * // Set default format of the row's cells
39. * $row->format = 'headline';
40. *
41. * // On the fly create the cell no 0
42. * $row[0]->content = 'Name';
43. * // On the fly create the cell no 1
44. * $row[1]->content = 'Cellphone';
45. *
46. * // Change a setting on cell 0
47. * $row[0]->align = ezcConsoleTable::ALIGN_CENTER;
48. *
49. * // Iterate through the row's cells.
50. * foreach ( $row as $cell )
51. * {
52. * var_dump( $cell );
53. * }
54. *
55. * // Set the default align property for all cells in the row
56. * $row->align = ezcConsoleTable::ALIGN_CENTER;
57. *
58. * </code>
59. *
60. * This class stores the rows for the {@link ezcConsoleTable} class.
61. *
62. * @property string $borderFormat
63. * Set the format applied to the borders of this row. See
64. * {@link ezcConsoleOutput}
65. * @property string $format
66. * Format applied to cell contents of cells marked with
67. * format "default" in this row.
68. * @property mixed $align
69. * Alignment applied to cells marked with
70. * ezcConsoleTable::ALIGN_DEFAULT.
71. *
72. * @package ConsoleTools
73. * @version //autogen//
74. */
75. class ezcConsoleTableRow implements Countable, Iterator, ArrayAccess
76. {
77. /**
78. * Container to hold the properties
79. *
80. * @var array(string=>mixed)
81. */
82. protected $properties ;
84. /**
85. * The cells of the row.
86. *
87. * @var array(ezcConsoleTableCell)
88. */
89. protected $cells = array();
91. /**
92. * Create a new ezcConsoleProgressbarRow.
93. * Creates a new ezcConsoleProgressbarRow.
94. *
95. * This method takes any number of {@link ezcConsoleTableCell} objects as
96. * parameter, which will be added as table cells to the row in their
97. * specified order.
98. *
99. * @throws ezcBaseValueException
100. * If a parameter is not of type {@link ezcConsoleTableCell}.
101. */
102. public function __construct ()
103. {
104. $this-> properties ['borderFormat'] = 'default';
105. $this-> properties ['format'] = 'default';
106. $this-> properties ['align'] = ezcConsoleTable ::ALIGN_DEFAULT;
108. if ( func_num_args () > 0 )
109. {
110. foreach ( func_get_args () as $id => $arg )
111. {
112. if ( !( $arg instanceof ezcConsoleTableCell ) )
113. {
114. throw new ezcBaseValueException ( 'Parameter'.$id, $arg, 'ezcConsoleTableCell' );
115. }
116. $this-> cells [] = $arg;
117. }
118. }
119. }
121. /**
122. * Returns if the given offset exists.
123. * This method is part of the ArrayAccess interface to allow access to the
124. * data of this object as if it was an array.
125. *
126. * @param int $offset The offset to check.
127. * @return bool True when the offset exists, otherwise false.
128. *
129. * @throws ezcBaseValueException
130. * If a non numeric cell ID is requested.
131. */
132. public function offsetExists ( $offset )
133. {
134. if ( ! is_int ( $offset ) || $offset < 0 )
135. {
136. throw new ezcBaseValueException ( 'offset', $offset, 'int >= 0' );
137. }
138. return isset( $this-> cells [$offset] );
139. }
141. /**
142. * Returns the element with the given offset.
143. * This method is part of the ArrayAccess interface to allow access to the
144. * data of this object as if it was an array. In case of the
145. * ezcConsoleTableRow class this method always returns a valid cell object
146. * since it creates them on the fly, if a given item does not exist.
147. *
148. * @param int $offset The offset to check.
149. * @return ezcConsoleTableCell
150. *
151. * @throws ezcBaseValueException
152. * If a non numeric cell ID is requested.
153. */
154. public function offsetGet ( $offset )
155. {
156. if ( !isset( $offset ) )
157. {
158. $offset = count ( $this );
159. $this-> cells [$offset] = new ezcConsoleTableCell ();
160. }
161. if ( ! is_int ( $offset ) || $offset < 0 )
162. {
163. throw new ezcBaseValueException ( 'offset', $offset, 'int >= 0' );
164. }
165. if ( !isset( $this-> cells [$offset] ) )
166. {
167. $this-> cells [$offset] = new ezcConsoleTableCell ();
168. }
169. return $this-> cells [$offset];
170. }
172. /**
173. * Set the element with the given offset.
174. * This method is part of the ArrayAccess interface to allow access to the
175. * data of this object as if it was an array.
176. *
177. * @param int $offset The offset to assign an item to.
178. * @param ezcConsoleTableCell $value The cell to assign.
179. * @return void
180. *
181. * @throws ezcBaseValueException
182. * If a non numeric cell ID is requested.
183. * @throws ezcBaseValueException
184. * If the provided value is not of type {@ling ezcConsoleTableCell}.
185. */
186. public function offsetSet ( $offset, $value )
187. {
188. if ( !( $value instanceof ezcConsoleTableCell ) )
189. {
190. throw new ezcBaseValueException ( 'value', $value, 'ezcConsoleTableCell' );
191. }
192. if ( !isset( $offset ) )
193. {
194. $offset = count ( $this );
195. }
196. if ( ! is_int ( $offset ) || $offset < 0 )
197. {
198. throw new ezcBaseValueException ( 'offset', $offset, 'int >= 0' );
199. }
200. $this-> cells [$offset] = $value;
201. }
203. /**
204. * Unset the element with the given offset.
205. * This method is part of the ArrayAccess interface to allow access to the
206. * data of this object as if it was an array.
207. *
208. * @param int $offset The offset to unset the value for.
209. * @return void
210. *
211. * @throws ezcBaseValueException
212. * If a non numeric cell ID is requested.
213. */
214. public function offsetUnset ( $offset )
215. {
216. if ( ! is_int ( $offset ) || $offset < 0 )
217. {
218. throw new ezcBaseValueException ( 'offset', $offset, 'int >= 0' );
219. }
220. if ( isset( $this-> cells [$offset] ) )
221. {
222. unset( $this-> cells [$offset] );
223. }
224. }
226. /**
227. * Returns the number of cells in the row.
228. * This method is part of the Countable interface to allow the usage of
229. * PHP's count() function to check how many cells this row has.
230. *
231. * @return int Number of cells in this row.
232. */
233. public function count ()
234. {
235. $keys = array_keys ( $this-> cells );
236. return count ( $keys ) > 0 ? ( end ( $keys ) + 1 ) : 0;
237. }
239. /**
240. * Returns the currently selected cell.
241. * This method is part of the Iterator interface to allow acces to the
242. * cells of this row by iterating over it like an array (e.g. using
243. * foreach).
244. *
245. * @return ezcConsoleTableCell The currently selected cell.
246. */
247. public function current ()
248. {
249. return current ( $this-> cells );
250. }
252. /**
253. * Returns the key of the currently selected cell.
254. * This method is part of the Iterator interface to allow acces to the
255. * cells of this row by iterating over it like an array (e.g. using
256. * foreach).
257. *
258. * @return int The key of the currently selected cell.
259. */
260. public function key ()
261. {
262. return key ( $this-> cells );
263. }
265. /**
266. * Returns the next cell and selects it or false on the last cell.
267. * This method is part of the Iterator interface to allow acces to the
268. * cells of this row by iterating over it like an array (e.g. using
269. * foreach).
270. *
271. * @return mixed ezcConsoleTableCell if the next cell exists, or false.
272. */
273. public function next ()
274. {
275. return next ( $this-> cells );
276. }
278. /**
279. * Selects the very first cell and returns it.
280. * This method is part of the Iterator interface to allow acces to the
281. * cells of this row by iterating over it like an array (e.g. using
282. * foreach).
283. *
284. * @return ezcConsoleTableCell The very first cell of this row.
285. */
286. public function rewind ()
287. {
288. return reset ( $this-> cells );
289. }
291. /**
292. * Returns if the current cell is valid.
293. * This method is part of the Iterator interface to allow acces to the
294. * cells of this row by iterating over it like an array (e.g. using
295. * foreach).
296. *
297. * @return ezcConsoleTableCell The very first cell of this row.
298. */
299. public function valid ()
300. {
301. return current ( $this-> cells ) !== false;
302. }
304. /**
305. * Property read access.
306. *
307. * @param string $key Name of the property.
308. * @return mixed Value of the property or null.
309. *
310. * @throws ezcBasePropertyNotFoundException
311. * If the the desired property is not found.
312. * @ignore
313. */
314. public function __get( $key )
315. {
316. if ( isset( $this-> properties [$key] ) )
317. {
318. return $this-> properties [$key];
319. }
320. throw new ezcBasePropertyNotFoundException ( $key );
321. }
323. /**
324. * Property write access.
325. *
326. * @param string $key Name of the property.
327. * @param mixed $val The value for the property.
328. *
329. * @throws ezcBaseValueException
330. * If a the value submitted for the align is not in the range of
331. * {@link ezcConsoleTable::ALIGN_LEFT},
332. * {@link ezcConsoleTable::ALIGN_CENTER},
333. * {@link ezcConsoleTable::ALIGN_RIGHT},
334. * {@link ezcConsoleTable::ALIGN_DEFAULT}
335. *
336. * @ignore
337. */
338. public function __set( $key, $val )
339. {
341. switch ( $key )
342. {
343. case 'format':
344. case 'borderFormat':
345. if ( is_string ( $val ) === false || strlen ( $val ) < 1 )
346. {
347. throw new ezcBaseValueException ( $key, $val, "string, length > 0" );
348. }
349. break;
350. case 'align':
351. if ( $val !== ezcConsoleTable ::ALIGN_LEFT
352. && $val !== ezcConsoleTable ::ALIGN_CENTER
353. && $val !== ezcConsoleTable ::ALIGN_RIGHT
354. && $val !== ezcConsoleTable ::ALIGN_DEFAULT
355. )
356. {
357. throw new ezcBaseValueException ( $key, $val, 'ezcConsoleTable::ALIGN_DEFAULT, ezcConsoleTable::ALIGN_LEFT, ezcConsoleTable::ALIGN_CENTER, ezcConsoleTable::ALIGN_RIGHT' );
358. }
359. break;
360. default:
361. throw new ezcBasePropertyNotFoundException ( $key );
362. }
363. $this-> properties [$key] = $val;
364. }
366. /**
367. * Property isset access.
368. *
369. * @param string $key Name of the property.
370. * @return bool True is the property is set, otherwise false.
371. * @ignore
372. */
373. public function __isset( $key )
374. {
375. switch ( $key )
376. {
377. case 'format':
378. case 'borderFormat':
379. case 'align':
380. return true;
381. default:
382. return false;
383. }
384. }
386. }
388. ?>

Documentation generated by phpDocumentor 1.4.3