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

## Source for file output_formats.php

Documentation is available at output_formats.php

1. <?php
2. /**
3. * File containing the ezcConsoleOutputFormats 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. * Class to store the collection for formating classes.
30. *
31. * This class stores objects of {@link ezcConsoleOutputFormat}, which
32. * represents a format option set for {@link ezcConsoleOutput}.
33. *
34. * <code>
35. * // New ezcConsoleOutput
36. * // $output->format is instance of ezcConsoleOutputFormats.
37. * $output = new ezcConsoleOutput();
38. *
39. * // Default format - color = blue
40. * $output->formats->default->color = 'blue';
41. * // Default format - weight = bold
42. * $output->formats->default->style = array( 'bold' );
43. *
44. * // New format "important" - color = red
45. * $output->formats->important->color = 'red';
46. * // Format "important" - background color = black
47. * $output->formats->important->bgcolor = 'black';
48. * </code>
49. *
50. * @package ConsoleTools
51. * @version //autogen//
52. */
53. class ezcConsoleOutputFormats implements Iterator, Countable
54. {
55. /**
56. * Array of ezcConsoleOutputFormat.
57. *
58. * @var array(ezcConsoleOutputFormat)
59. */
60. protected $formats = array();
62. /**
63. * Create a new ezcConsoleOutputFormats object.
64. *
65. * Creates a new, empty object of this class. It also adds a default
66. * format.
67. */
68. public function __construct ()
69. {
70. $this-> formats ['default'] = new ezcConsoleOutputFormat ();
71. $this-> formats ['success'] = new ezcConsoleOutputFormat ();
72. $this-> formats ['success']->color = 'green';
73. $this-> formats ['success']->style = array( 'bold' );
74. $this-> formats ['failure'] = new ezcConsoleOutputFormat ();
75. $this-> formats ['failure']->color = 'red';
76. $this-> formats ['failure']->style = array( 'bold' );
77. }
79. /**
80. * Returns the current Iterator value.
81. *
82. * Implementation of {@link Iterator::current()}.
83. *
84. * @return ezcConsoleOutputFormat
85. */
86. public function current ()
87. {
88. return current ( $this-> formats );
89. }
91. /**
92. * Advances the Iterator to the next element.
93. *
94. * Implementation of {@link Iterator::next()}.
95. *
96. * @return ezcConsoleOutputFormat|bool
97. */
98. public function next ()
99. {
100. return next ( $this-> formats );
101. }
103. /**
104. * Returns the current Iterator key.
105. *
106. * Implementation of {@link Iterator::key()}.
107. *
108. * @return string
109. */
110. public function key ()
111. {
112. return key ( $this-> formats );
113. }
115. /**
116. * Resets the Iterator to the first element.
117. *
118. * Implementation of {@link Iterator::rewind()}.
119. *
120. * @return ezcConsoleOutputFormat
121. */
122. public function rewind ()
123. {
124. return reset ( $this-> formats );
125. }
127. /**
128. * Checks if the current Iterator position is still valid.
129. *
130. * Implementation of {@link Iterator::valid()}.
131. *
132. * @return bool
133. */
134. public function valid ()
135. {
136. return ( current ( $this-> formats ) !== false );
137. }
139. /**
140. * Returns the number of registered formats.
141. *
142. * Implementation of {@link Countable::count()}.
143. *
144. * @return void
145. */
146. public function count ()
147. {
148. return count ( $this-> formats );
149. }
151. /**
152. * Read access to the formats.
153. *
154. * Formats are accessed directly like properties of this object. If a
155. * format does not exist, it is created on the fly (using default values),
156. *
157. * @param string $formatName
158. * @return ezcConsoleOutputFormat The format.
159. */
160. public function __get ( $formatName )
161. {
162. if ( !isset( $this-> formats [$formatName] ) )
163. {
164. $this-> formats [$formatName] = new ezcConsoleOutputFormat ();
165. }
166. return $this-> formats [$formatName];
167. }
169. /**
170. * Write access to the formats.
171. *
172. * Formats are accessed directly like properties of this object. If a
173. * format does not exist, it is created on the fly (using default values),
174. *
175. * @param string $formatName
176. * @param ezcConsoleOutputFormat $val The format defintion.
177. * @return void
178. */
179. public function __set ( $formatName, ezcConsoleOutputFormat $val )
180. {
181. $this-> formats [$formatName] = $val;
182. }
184. /**
185. * Property isset access.
186. *
187. * @param string $formatName Name of the property.
188. * @return bool True is the property is set, otherwise false.
189. */
190. public function __isset ( $formatName )
191. {
192. return isset( $this-> formats [$formatName] );
193. }
195. }
197. ?>

Documentation generated by phpDocumentor 1.4.3