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

## Source for file argument.php

Documentation is available at argument.php

1. <?php
2. /**
3. * File containing the ezcConsoleArgument 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. * The ezcConsoleArgument class represents an argument on the console.
30. * This class is the container to store information about an argument submitted
31. * to a shell application. It is used to define the appearance of an argument
32. * before parsing the parameter string and contains the received value
33. * afterwards. Argument objects are stored in an instance of the set class
34. * {@link ezcConsoleArguments} which is stored in
35. * {ezcConsoleInput::$argumentDefinition}.
36. *
37. * @property string $name The name for the argument. Must be unique.
38. * @property int $type The value type.
39. * @property string $shorthelp A short help text.
40. * @property string $longhelp A long help text-
41. * @property bool $mandatory Whether the argument is mandatory.
42. * @property mixed $default A default value, if not mandatory.
43. * @property bool $multiple Whether the argument accepts multiple values.
44. * @property-read mixed $value The value parsed from the parameter string, using
45. * {@link ezcConsoleInput::process()}.
46. * @package ConsoleTools
47. * @version //autogen//
48. */
49. class ezcConsoleArgument
50. {
51. /**
52. * Properties
53. *
54. * @var array
55. */
56. protected $properties = array(
57. "name" => null,
58. "type" => ezcConsoleInput::TYPE_STRING,
59. "shorthelp" => "No help available.",
60. "longhelp" => "There is no help for this argument available.",
61. "mandatory" => true,
62. "multiple" => false,
63. "default" => null,
64. "value" => null,
65. );
67. /**
68. * Creates a new console argument object.
69. * Creates a new console argument object, which represents a single
70. * argument on the shell. Arguments are stored insiede
71. * {@link ezcConsoleArguments} which is used with {@link ezcConsoleInput}.
72. *
73. * For the type property see {@link ezcConsoleInput::TYPE_STRING} and
74. * {@link ezcConsoleInput::TYPE_INT}. If 1 argument is defined as optional
75. * ($mandatory = false), all following arguments are autolamtically
76. * considered optional, too.
77. *
78. * @param string $name The name for the argument. Must be unique.
79. * @param int $type The value type.
80. * @param string $shorthelp A short help text.
81. * @param string $longhelp A long help text-
82. * @param bool $mandatory Whether the argument is mandatory.
83. * @param bool $multiple Whether the argument accepts multiple values.
84. * @param mixed $default A default value, if not mandatory.
85. * @return void
86. */
87. public function __construct (
88. $name = null,
89. $type = ezcConsoleInput::TYPE_STRING,
90. $shorthelp = "No help available.",
91. $longhelp = "There is no help for this argument available.",
92. $mandatory = true,
93. $multiple = false,
94. $default = null
95. )
96. {
97. if ( ! is_string ( $name ) || strlen ( $name ) < 1 )
98. {
99. throw new ezcBaseValueException ( "name", $name, "string, length > 0" );
100. }
101. $this-> properties ["name"] = $name;
103. $this->type = $type;
104. $this->shorthelp = $shorthelp;
105. $this->longhelp = $longhelp;
106. $this->mandatory = $mandatory;
107. $this->multiple = $multiple;
108. $this->default = $default;
109. }
111. /**
112. * Property set access.
113. *
114. * @param string $propertyName Name of the property.
115. * @param string $propertyValue Valze for the property.
116. * @return void
117. * @ignore
118. */
119. public function __set( $propertyName, $propertyValue )
120. {
121. switch ( $propertyName )
122. {
123. case "name":
124. throw new ezcBasePropertyPermissionException ( $propertyName, ezcBasePropertyPermissionException ::READ );
125. break;
126. case "type":
127. if ( $propertyValue !== ezcConsoleInput ::TYPE_INT && $propertyValue !== ezcConsoleInput ::TYPE_STRING )
128. {
129. throw new ezcBaseValueException ( $propertyName, $propertyValue, "string, length > 0" );
130. }
131. break;
132. case "shorthelp":
133. case "longhelp":
134. if ( is_string ( $propertyValue ) === false )
135. {
136. throw new ezcBaseValueException ( $propertyName, $propertyValue, "string" );
137. }
138. break;
139. case "mandatory":
140. case "multiple":
141. if ( is_bool ( $propertyValue ) === false )
142. {
143. throw new ezcBaseValueException ( $propertyName, $propertyValue, "bool" );
144. }
145. break;
146. case "default":
147. if ( is_scalar ( $propertyValue ) === false && is_array ( $propertyValue ) === false && $propertyValue !== null )
148. {
149. throw new ezcBaseValueException ( $propertyName, $propertyValue, "array, scalar or null" );
150. }
151. break;
152. case "value":
153. if ( is_scalar ( $propertyValue ) === false && is_array ( $propertyValue ) === false && $propertyValue !== null )
154. {
155. throw new ezcBaseValueException ( $propertyName, $propertyValue, "string or null" );
156. }
157. break;
158. default:
159. throw new ezcBasePropertyNotFoundException ( $propertyName );
160. }
161. $this-> properties [$propertyName] = $propertyValue;
162. }
164. /**
165. * Property read access.
166. *
167. * @throws ezcBasePropertyNotFoundException
168. * If the the desired property is not found.
169. *
170. * @param string $propertyName Name of the property.
171. * @return mixed Value of the property or null.
172. * @ignore
173. */
174. public function __get( $propertyName )
175. {
176. if ( isset( $this->$propertyName ) )
177. {
178. return $this-> properties [$propertyName];
179. }
180. throw new ezcBasePropertyNotFoundException ( $propertyName );
181. }
183. /**
184. * Property isset access.
185. *
186. * @param string $propertyName Name of the property.
187. * @return bool True is the property is set, otherwise false.
188. * @ignore
189. */
190. public function __isset( $propertyName )
191. {
192. return array_key_exists ( $propertyName, $this-> properties );
193. }
194. }
196. ?>

Documentation generated by phpDocumentor 1.4.3