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

## Source for file option_rule.php

Documentation is available at option_rule.php

1. <?php
2. /**
3. * File containing the ezcConsoleOptionRule 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 a parameter rule.
30. *
31. * This struct stores relation rules between parameters. A relation consists of
32. * a parameter that the relation refers to and optionally the value(s) the
33. * referred parameter may have assigned. Rules may be used for dependencies and
34. * exclusions between parameters.
35. *
36. * The ezcConsoleOptionRule class has the following properties:
37. * - <b>option</b> <i>ezcConsoleOption</i>, contains the parameter that this rule refers to.
38. * - <b>values</b> <i>array(string)</i>, contains a list of values that are accepted.
39. *
40. * @see ezcConsoleOption
41. *
42. * @package ConsoleTools
43. * @version //autogen//
44. */
45. class ezcConsoleOptionRule
46. {
47. /**
48. * Properties.
49. *
50. * @var array
51. */
52. protected $properties = array(
53. 'option' => null,
54. 'values' => array(),
55. 'ifSet' => true
56. );
58. /**
59. * Creates a new option rule.
60. *
61. * Creates a new option rule. Per default the $values parameter
62. * is an empty array, which determines that the option may accept any
63. * value. To indicate that a option may only have certain values,
64. * place them inside tha $values array. For example to indicate an option
65. * may have the values 'a', 'b' and 'c' use:
66. *
67. * <code>
68. * $rule = new ezcConsoleOptionRule( $option, array( 'a', 'b', 'c' ) );
69. * </code>
70. *
71. * If you want to allow only 1 specific value for an option, you do not
72. * need to wrap this into an array, when creating the rule. Simply use
73. *
74. * <code>
75. * $rule = new ezcConsoleOptionRule( $option, 'a' );
76. * </code>
77. *
78. * to create a rule, that allows the desired option only to accept the
79. * value 'a'.
80. *
81. * The $ifSet parameter determines, if the rule is validated when its option
82. * is set or left out. If $ifSet is true, the rule is validated when the
83. * option is set. Otherwise the rule is validated if the option was not set
84. * by the user.
85. *
86. * @param ezcConsoleOption $option The option to refer to.
87. * @param mixed $values The affected values.
88. * @param bool $ifSet
89. */
90. public function __construct ( ezcConsoleOption $option, array $values = array(), $ifSet = true )
91. {
92. $this->__set( 'option', $option );
93. $this->__set( 'values', $values );
94. $this->__set( 'ifSet', $ifSet );
95. }
97. /**
98. * Property read access.
99. *
100. * @throws ezcBasePropertyNotFoundException
101. * If the the desired property is not found.
102. *
103. * @param string $propertyName Name of the property.
104. * @return mixed Value of the property or null.
105. * @ignore
106. */
107. public function __get( $propertyName )
108. {
109. switch ( $propertyName )
110. {
111. case 'option':
112. return $this-> properties ['option'];
113. case 'values':
114. return $this-> properties ['values'];
115. case 'ifSet':
116. return $this-> properties ['ifSet'];
117. }
118. throw new ezcBasePropertyNotFoundException ( $propertyName );
119. }
121. /**
122. * Property write access.
123. *
124. * @param string $propertyName Name of the property.
125. * @param mixed $propertyValue The value for the property.
126. *
127. * @throws ezcBasePropertyPermissionException
128. * If the property you try to access is read-only.
129. * @throws ezcBasePropertyNotFoundException
130. * If the the desired property is not found.
131. * @ignore
132. */
133. public function __set( $propertyName, $propertyValue )
134. {
135. switch ( $propertyName )
136. {
137. case 'option':
138. if ( !( $propertyValue instanceof ezcConsoleOption ) )
139. {
140. throw new ezcBaseValueException ( $propertyName, $propertyValue, 'ezcConsoleOption' );
141. }
142. $this-> properties ['option'] = $propertyValue;
143. return;
144. case 'values':
145. if ( ! is_array ( $propertyValue ) )
146. {
147. throw new ezcBaseValueException ( $propertyName, $propertyValue, 'array' );
148. }
149. $this-> properties ['values'] = $propertyValue;
150. return;
151. case 'ifSet':
152. if ( ! is_bool ( $propertyValue ) )
153. {
154. throw new ezcBaseValueException ( $propertyName, $propertyValue, 'bool' );
155. }
156. $this-> properties ['ifSet'] = $propertyValue;
157. return;
158. }
159. throw new ezcBasePropertyNotFoundException ( $propertyName );
160. }
162. /**
163. * Property isset access.
164. *
165. * @param string $propertyName Name of the property to check.
166. * @return bool If the property exists or not.
167. * @ignore
168. */
169. public function __isset( $propertyName )
170. {
171. switch ( $propertyName )
172. {
173. case 'option':
174. case 'values':
175. case 'ifSet':
176. return true;
177. }
178. return false;
179. }
181. }
183. ?>

Documentation generated by phpDocumentor 1.4.3