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

## Source for file output_format.php

Documentation is available at output_format.php

1. <?php
2. /**
3. * File containing the ezcConsoleOutputFormat 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 formating entities used by ezcConsoleOutput.
30. *
31. * Struct class to store formating entities used by ezcConsoleOutput.
32. *
33. * Possible values of {@link ezcConsoleOutputFormat::$color} are:
34. * - gray
35. * - red
36. * - green
37. * - yellow
38. * - blue
39. * - magenta
40. * - cyan
41. * - white
42. * - default (representing the consoles default color)
43. *
44. * For {@link ezcConsoleOutputFormat::$bgcolor} the following values are valid:
45. * - black
46. * - red
47. * - green
48. * - yellow
49. * - blue
50. * - magenta
51. * - cyan
52. * - white
53. * - default (representing the consoles default background color)
54. *
55. * The {@link ezcConsoleOutputFormat::$style} attribute takes an array of
56. * (possibly) multiple attributes. Choose from the lists below:
57. *
58. * - default (resets all attributes to default)
59. *
60. * - bold
61. * - faint
62. * - normal
63. *
64. * - italic
65. * - notitalic
66. *
67. * - underlined
68. * - doubleunderlined
69. * - notunderlined
70. *
71. * - blink
72. * - blinkfast
73. * - noblink
74. *
75. * - negative
76. * - positive
77. *
78. * @property string $color
79. * Contains the color for this format.
80. * @property array(string) $style
81. * Contains the lists of styles that are associated with
82. * this format.
83. * @property string $bgcolor
84. * Contains the background color for this format.
85. * @property string $target
86. * Contains the output target to use. Pick one of
87. * ezcConsoleOutput::TARGET_OUTPUT, ezcConsoleOutput::TARGET_STDOUT
88. * or ezcConsoleOutput::TARGET_STDERR.
89. *
90. * @package ConsoleTools
91. * @version //autogen//
92. */
93. class ezcConsoleOutputFormat
94. {
95. /**
96. * Container to hold the properties
97. *
98. * @var array(string=>mixed)
99. */
100. protected $properties = array(
101. 'color' => 'default',
102. 'style' => array( 'default' ),
103. 'bgcolor' => 'default',
104. 'target' => ezcConsoleOutput::TARGET_OUTPUT,
105. );
107. /**
108. * Create a new ezcConsoleOutputFormat object.
109. * Creates a new object of this class.
110. *
111. * @param string $color Name of a color value.
112. * @param array(string) $style Names of style values.
113. * @param string $bgcolor Name of a bgcolor value.
114. * @param string $target Target output stream.
115. */
116. public function __construct ( $color = 'default', array $style = null, $bgcolor = 'default', $target = ezcConsoleOutput::TARGET_OUTPUT )
117. {
118. $this->__set( 'color', $color );
119. $this->__set( 'style', isset( $style ) ? $style : array( 'default' ) );
120. $this->__set( 'bgcolor', $bgcolor );
121. $this->__set( 'target', $target );
122. }
124. /**
125. * Overloaded __get() method to gain read-only access to some attributes.
126. *
127. * @param string $propertyName Name of the property to read.
128. * @return mixed Desired value if exists, otherwise null.
129. * @ignore
130. */
131. public function __get( $propertyName )
132. {
133. switch ( $propertyName )
134. {
135. case 'style':
136. return (array) $this-> properties [$propertyName];
137. case 'color':
138. case 'bgcolor':
139. case 'target':
140. return $this-> properties [$propertyName];
141. default:
142. throw new ezcBasePropertyNotFoundException ( $propertyName );
143. }
144. }
146. /**
147. * Overloaded __set() method to gain read-only access to properties.
148. * It also performs checks on setting others.
149. *
150. * @throws ezcBasePropertyNotFoundException
151. * If the setting you try to access does not exists
152. * @throws ezcBaseValueException
153. * If trying to set an invalid value for a setting.
154. *
155. * @param string $propertyName Name of the attrinbute to access.
156. * @param string $val The value to set.
157. * @ignore
158. */
159. public function __set( $propertyName, $val )
160. {
161. if ( !isset( $this-> properties [$propertyName] ) )
162. {
163. throw new ezcBasePropertyNotFoundException ( $propertyName );
164. }
165. // Extry handling of multi styles
166. if ( $propertyName === 'style' )
167. {
168. if ( ! is_array ( $val ) ) $val = array( $val );
169. foreach ( $val as $style )
170. {
171. if ( ! ezcConsoleOutput :: isValidFormatCode ( $propertyName, $style ) )
172. {
173. throw new ezcBaseValueException ( $propertyName, $style, 'valid ezcConsoleOutput format code' );
174. }
175. }
176. $this-> properties ['style'] = $val;
177. return;
178. }
179. // Continue normal handling
180. if ( ( $propertyName === "color" || $propertyName === "bgcolor" )
181. && ! ezcConsoleOutput :: isValidFormatCode ( $propertyName, $val ) )
182. {
183. throw new ezcBaseValueException ( $propertyName, $val, 'valid ezcConsoleOutput format code' );
184. }
185. $this-> properties [$propertyName] = $val;
186. }
188. /**
189. * Property isset access.
190. *
191. * @param string $propertyName Name of the property.
192. * @return bool True is the property is set, otherwise false.
193. * @ignore
194. */
195. public function __isset( $propertyName )
196. {
197. return isset( $this-> properties [$propertyName] );
198. }
200. }
202. ?>

Documentation generated by phpDocumentor 1.4.3