1 | <?php |
||
27 | abstract class AbstractFormat implements FormatInterface |
||
28 | { |
||
29 | /** |
||
30 | * Constructor. |
||
31 | * The default implementation does two things: |
||
32 | * |
||
33 | * - Initializes the object with the given configuration `$config`. |
||
34 | * - Call [[init()]]. |
||
35 | * |
||
36 | * If this method is overridden in a child class, it is recommended that |
||
37 | * |
||
38 | * - the last parameter of the constructor is a configuration array, like `$config` here. |
||
39 | * - call the parent implementation at the end of the constructor. |
||
40 | * |
||
41 | * @param array $config name-value pairs that will be used to initialize the object properties |
||
42 | */ |
||
43 | public function __construct($config = []) |
||
52 | |||
53 | /** |
||
54 | * Initialization method |
||
55 | */ |
||
56 | public function init() |
||
59 | |||
60 | /** |
||
61 | * Returns the value of an object property. |
||
62 | * |
||
63 | * Do not call this method directly as it is a PHP magic method that |
||
64 | * will be implicitly called when executing `$value = $object->property;`. |
||
65 | * |
||
66 | * @param string $name the property name |
||
67 | * |
||
68 | * @throws UnknownPropertyException if the property is not defined |
||
69 | * @throws InvalidCallException if the property is write-only |
||
70 | * @return mixed the property value |
||
71 | * @see __set() |
||
72 | */ |
||
73 | public function __get($name) |
||
83 | |||
84 | /** |
||
85 | * Sets value of an object property. |
||
86 | * |
||
87 | * Do not call this method directly as it is a PHP magic method that |
||
88 | * will be implicitly called when executing `$object->property = $value;`. |
||
89 | * |
||
90 | * @param string $name the property name or the event name |
||
91 | * @param mixed $value the property value |
||
92 | * |
||
93 | * @throws UnknownPropertyException if the property is not defined |
||
94 | * @throws InvalidCallException if the property is read-only |
||
95 | * @see __get() |
||
96 | */ |
||
97 | public function __set($name, $value) |
||
108 | |||
109 | /** |
||
110 | * Checks if a property is set, i.e. defined and not null. |
||
111 | * |
||
112 | * Do not call this method directly as it is a PHP magic method that |
||
113 | * will be implicitly called when executing `isset($object->property)`. |
||
114 | * |
||
115 | * Note that if the property is not defined, false will be returned. |
||
116 | * |
||
117 | * @param string $name the property name or the event name |
||
118 | * |
||
119 | * @return bool whether the named property is set (not null). |
||
120 | * @see http://php.net/manual/en/function.isset.php |
||
121 | */ |
||
122 | public function __isset($name) |
||
131 | |||
132 | /** |
||
133 | * Sets an object property to null. |
||
134 | * |
||
135 | * Do not call this method directly as it is a PHP magic method that |
||
136 | * will be implicitly called when executing `unset($object->property)`. |
||
137 | * |
||
138 | * Note that if the property is not defined, this method will do nothing. |
||
139 | * If the property is read-only, it will throw an exception. |
||
140 | * |
||
141 | * @param string $name the property name |
||
142 | * |
||
143 | * @throws InvalidCallException if the property is read only. |
||
144 | * @see http://php.net/manual/en/function.unset.php |
||
145 | */ |
||
146 | public function __unset($name) |
||
155 | |||
156 | /** |
||
157 | * Calls the named method which is not a class method. |
||
158 | * |
||
159 | * Do not call this method directly as it is a PHP magic method that |
||
160 | * will be implicitly called when an unknown method is being invoked. |
||
161 | * |
||
162 | * @param string $name the method name |
||
163 | * @param array $params method parameters |
||
164 | * |
||
165 | * @throws UnknownMethodException when calling unknown method |
||
166 | * @return mixed the method return value |
||
167 | */ |
||
168 | public function __call($name, $params) |
||
172 | |||
173 | /** |
||
174 | * @return string the string representation of the object |
||
175 | */ |
||
176 | public function __toString() |
||
180 | |||
181 | /** |
||
182 | * Returns a value indicating whether a property is defined. |
||
183 | * A property is defined if: |
||
184 | * |
||
185 | * - the class has a getter or setter method associated with the specified name |
||
186 | * (in this case, property name is case-insensitive); |
||
187 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
188 | * |
||
189 | * @param string $name the property name |
||
190 | * @param bool $checkVars whether to treat member variables as properties |
||
191 | * |
||
192 | * @return bool whether the property is defined |
||
193 | * @see canGetProperty() |
||
194 | * @see canSetProperty() |
||
195 | */ |
||
196 | public function hasProperty($name, $checkVars = true) |
||
200 | |||
201 | /** |
||
202 | * Returns a value indicating whether a property can be read. |
||
203 | * A property is readable if: |
||
204 | * |
||
205 | * - the class has a getter method associated with the specified name |
||
206 | * (in this case, property name is case-insensitive); |
||
207 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
208 | * |
||
209 | * @param string $name the property name |
||
210 | * @param bool $checkVars whether to treat member variables as properties |
||
211 | * |
||
212 | * @return bool whether the property can be read |
||
213 | * @see canSetProperty() |
||
214 | */ |
||
215 | public function canGetProperty($name, $checkVars = true) |
||
219 | |||
220 | /** |
||
221 | * Returns a value indicating whether a property can be set. |
||
222 | * A property is writable if: |
||
223 | * |
||
224 | * - the class has a setter method associated with the specified name |
||
225 | * (in this case, property name is case-insensitive); |
||
226 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
227 | * |
||
228 | * @param string $name the property name |
||
229 | * @param bool $checkVars whether to treat member variables as properties |
||
230 | * |
||
231 | * @return bool whether the property can be written |
||
232 | * @see canGetProperty() |
||
233 | */ |
||
234 | public function canSetProperty($name, $checkVars = true) |
||
238 | |||
239 | /** |
||
240 | * Returns a value indicating whether a method is defined. |
||
241 | * |
||
242 | * The default implementation is a call to php function `method_exists()`. |
||
243 | * You may override this method when you implemented the php magic method `__call()`. |
||
244 | * |
||
245 | * @param string $name the method name |
||
246 | * |
||
247 | * @return bool whether the method is defined |
||
248 | */ |
||
249 | public function hasMethod($name) |
||
253 | } |
||
254 |