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

## Source for file table.php

Documentation is available at table.php

1. <?php
2. /**
3. * File containing the ezcConsoleTableOptions 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. * Struct class to store the options of the ezcConsoleTable class.
30. * This class stores the options for the {@link ezcConsoleTable} class.
31. *
32. * @property mixed $colWidth
33. * Either 'auto' for automatic selection of column widths, or an
34. * array of column widths like array( 10, 30, 10 ).
35. * @property int $colWrap
36. * Wrap style of text contained in strings. See {@link }
37. * ezcConsoleTable::WRAP_AUTO}, {@link ezcConsoleTable::WRAP_NONE}
38. * and {@link ezcConsoleTable::WRAP_CUT}.
39. * @property int $defaultAlign
40. * Standard column alignment, applied to cells that have to explicit
41. * alignment assigned. See {@link ezcConsoleTable::ALIGN_LEFT},
42. * {@link ezcConsoleTable::ALIGN_RIGHT}, {@link }
43. * ezcConsoleTable::ALIGN_CENTER} and {@link }
44. * ezcConsoleTable::ALIGN_DEFAULT}.
45. * @property string $colPadding
46. * Padding characters for side padding between data and lines.
47. * @property int $widthType
48. * Type of the given table width (fixed or maximal value).
49. * @property string $lineVertical
50. * Character to use for drawing vertical lines. Null to switch off.
51. * @property string $lineHorizontal
52. * Character to use for drawing horizontal lines. Null to switch off.
53. * @property string $corner
54. * Character to use for drawing line corners. Null to switch off.
55. * @property string $defaultFormat
56. * Standard column content format, applied to cells that have
57. * "default" as the content format.
58. * @property string $defaultBorderFormat
59. * Standard border format, applied to rows that have 'default' as the
60. * border format.
61. *
62. * @package ConsoleTools
63. * @version //autogen//
64. */
65. class ezcConsoleTableOptions extends ezcBaseOptions
66. {
67. protected $properties = array(
68. 'colWidth' => 'auto',
69. 'colWrap' => ezcConsoleTable::WRAP_AUTO,
70. 'defaultAlign' => ezcConsoleTable::ALIGN_LEFT,
71. 'colPadding' => ' ',
72. 'widthType' => ezcConsoleTable::WIDTH_MAX,
73. 'lineVertical' => '-',
74. 'lineHorizontal' => '|',
75. 'corner' => '+',
76. 'defaultFormat' => 'default',
77. 'defaultBorderFormat' => 'default',
78. );
80. /**
81. * Construct a new options object.
82. *
83. * NOTE: For backwards compatibility reasons the old method of instantiating this class is kept,
84. * but the usage of the new version (providing an option array) is highly encouraged.
85. *
86. * @param array(string=>mixed) $options The initial options to set.
87. * @return void
88. *
89. * @throws ezcBasePropertyNotFoundException
90. * If the value for the property options is not an instance of
91. * @throws ezcBaseValueException
92. * If the value for a property is out of range.
93. */
94. public function __construct ()
95. {
96. $args = func_get_args ();
97. if ( func_num_args () === 1 && is_array ( $args[0] ) && ! is_int ( key ( $args[0] ) ) )
98. {
99. parent:: __construct ( $args[0] );
100. }
101. else
102. {
103. foreach ( $args as $id => $val )
104. {
105. switch ( $id )
106. {
107. case 0:
108. $this->__set( 'colWidth', $val );
109. break;
110. case 1:
111. $this->__set( 'colWrap', $val );
112. break;
113. case 2:
114. $this->__set( 'defaultAlign', $val );
115. break;
116. case 3:
117. $this->__set( 'colPadding', $val );
118. break;
119. case 4:
120. $this->__set( 'widthType', $val );
121. break;
122. case 5:
123. $this->__set( 'lineVertical', $val );
124. break;
125. case 6:
126. $this->__set( 'lineHorizontal', $val );
127. break;
128. case 7:
129. $this->__set( 'corner', $val );
130. break;
131. case 8:
132. $this->__set( 'defaultFormat', $val );
133. break;
134. case 9:
135. $this->__set( 'defaultBorderFormat', $val );
136. break;
137. }
138. }
139. }
140. }
142. /**
143. * Property write access.
144. *
145. * @throws ezcBasePropertyNotFoundException
146. * If a desired property could not be found.
147. * @throws ezcBaseValueException
148. * If a desired property value is out of range.
149. *
150. * @param string $propertyName Name of the property.
151. * @param mixed $val The value for the property.
152. * @ignore
153. */
154. public function __set( $propertyName, $val )
155. {
156. switch ( $propertyName )
157. {
158. case 'colWidth':
159. if ( is_array ( $val ) === false && ( is_string ( $val ) && $val !== 'auto' ) )
160. {
161. throw new ezcBaseValueException ( $propertyName, $val, 'array(int) or "auto"' );
162. }
163. break;
164. case 'colWrap':
165. if ( $val !== ezcConsoleTable ::WRAP_AUTO && $val !== ezcConsoleTable ::WRAP_NONE && $val !== ezcConsoleTable ::WRAP_CUT )
166. {
167. throw new ezcBaseValueException ( $propertyName, $val, 'ezcConsoleTable::WRAP_AUTO, ezcConsoleTable::WRAP_NONE, ezcConsoleTable::WRAP_CUT' );
168. }
169. break;
170. case 'defaultAlign':
171. if ( $val !== ezcConsoleTable ::ALIGN_DEFAULT && $val !== ezcConsoleTable ::ALIGN_LEFT && $val !== ezcConsoleTable ::ALIGN_CENTER && $val !== ezcConsoleTable ::ALIGN_RIGHT )
172. {
173. throw new ezcBaseValueException ( $propertyName, $val, 'ezcConsoleTable::ALIGN_DEFAULT, ezcConsoleTable::ALIGN_LEFT, ezcConsoleTable::ALIGN_CENTER, ezcConsoleTable::ALIGN_RIGHT' );
174. }
175. break;
176. case 'colPadding':
177. if ( ! is_string ( $val ) )
178. {
179. throw new ezcBaseValueException ( $propertyName, $val, 'string' );
180. }
181. break;
182. case 'widthType':
183. if ( $val !== ezcConsoleTable ::WIDTH_MAX && $val !== ezcConsoleTable ::WIDTH_FIXED )
184. {
185. throw new ezcBaseValueException ( $propertyName, $val, 'ezcConsoleTable::WIDTH_MAX, ezcConsoleTable::WIDTH_FIXED' );
186. }
187. break;
188. case 'lineVertical':
189. case 'lineHorizontal':
190. case 'corner':
191. if ( ( is_string ( $val ) === false || strlen ( $val ) !== 1 ) && $val !== null )
192. {
193. throw new ezcBaseValueException ( $propertyName, $val, 'string, length = 1, or null' );
194. }
195. break;
196. case 'defaultFormat':
197. if ( is_string ( $val ) === false || strlen ( $val ) < 1 )
198. {
199. throw new ezcBaseValueException ( $propertyName, $val, 'string, length = 1' );
200. }
201. break;
202. case 'defaultBorderFormat':
203. if ( is_string ( $val ) === false || strlen ( $val ) < 1 )
204. {
205. throw new ezcBaseValueException ( $propertyName, $val, 'string, length = 1' );
206. }
207. break;
208. default:
209. throw new ezcBasePropertyNotFoundException ( $propertyName );
210. }
211. $this-> properties [$propertyName] = $val;
212. }
213. }
215. ?>

Documentation generated by phpDocumentor 1.4.3