1 | <?php |
||
26 | abstract class AbstractFormat implements FormatInterface |
||
27 | { |
||
28 | /** |
||
29 | * Constructor. |
||
30 | * The default implementation does two things: |
||
31 | * |
||
32 | * - Initializes the object with the given configuration `$config`. |
||
33 | * - Call [[init()]]. |
||
34 | * |
||
35 | * If this method is overridden in a child class, it is recommended that |
||
36 | * |
||
37 | * - the last parameter of the constructor is a configuration array, like `$config` here. |
||
38 | * - call the parent implementation at the end of the constructor. |
||
39 | * |
||
40 | * @param array $config name-value pairs that will be used to initialize the object properties |
||
41 | */ |
||
42 | public function __construct($config = []) |
||
51 | |||
52 | /** |
||
53 | * Returns the value of an object property. |
||
54 | * |
||
55 | * Do not call this method directly as it is a PHP magic method that |
||
56 | * will be implicitly called when executing `$value = $object->property;`. |
||
57 | * |
||
58 | * @param string $name the property name |
||
59 | * |
||
60 | * @throws UnknownPropertyException if the property is not defined |
||
61 | * @throws InvalidCallException if the property is write-only |
||
62 | * @return mixed the property value |
||
63 | * @see __set() |
||
64 | */ |
||
65 | public function __get($name) |
||
78 | |||
79 | /** |
||
80 | * Sets value of an object property. |
||
81 | * |
||
82 | * Do not call this method directly as it is a PHP magic method that |
||
83 | * will be implicitly called when executing `$object->property = $value;`. |
||
84 | * |
||
85 | * @param string $name the property name or the event name |
||
86 | * @param mixed $value the property value |
||
87 | * |
||
88 | * @throws UnknownPropertyException if the property is not defined |
||
89 | * @throws InvalidCallException if the property is read-only |
||
90 | * @see __get() |
||
91 | */ |
||
92 | public function __set($name, $value) |
||
103 | |||
104 | /** |
||
105 | * Checks if a property is set, i.e. defined and not null. |
||
106 | * |
||
107 | * Do not call this method directly as it is a PHP magic method that |
||
108 | * will be implicitly called when executing `isset($object->property)`. |
||
109 | * |
||
110 | * Note that if the property is not defined, false will be returned. |
||
111 | * |
||
112 | * @param string $name the property name or the event name |
||
113 | * |
||
114 | * @return bool whether the named property is set (not null). |
||
115 | * @see http://php.net/manual/en/function.isset.php |
||
116 | */ |
||
117 | public function __isset($name) |
||
126 | |||
127 | /** |
||
128 | * Sets an object property to null. |
||
129 | * |
||
130 | * Do not call this method directly as it is a PHP magic method that |
||
131 | * will be implicitly called when executing `unset($object->property)`. |
||
132 | * |
||
133 | * Note that if the property is not defined, this method will do nothing. |
||
134 | * If the property is read-only, it will throw an exception. |
||
135 | * |
||
136 | * @param string $name the property name |
||
137 | * |
||
138 | * @throws InvalidCallException if the property is read only. |
||
139 | * @see http://php.net/manual/en/function.unset.php |
||
140 | */ |
||
141 | public function __unset($name) |
||
150 | |||
151 | /** |
||
152 | * Calls the named method which is not a class method. |
||
153 | * |
||
154 | * Do not call this method directly as it is a PHP magic method that |
||
155 | * will be implicitly called when an unknown method is being invoked. |
||
156 | * |
||
157 | * @param string $name the method name |
||
158 | * @param array $params method parameters |
||
159 | * |
||
160 | * @throws UnknownMethodException when calling unknown method |
||
161 | * @return mixed the method return value |
||
162 | */ |
||
163 | public function __call($name, $params) |
||
167 | |||
168 | /** |
||
169 | * @return string the string representation of the object |
||
170 | */ |
||
171 | public function __toString() |
||
175 | |||
176 | /** |
||
177 | * Initialization method |
||
178 | */ |
||
179 | public function init(): void |
||
182 | |||
183 | /** |
||
184 | * Returns a value indicating whether a property is defined. |
||
185 | * A property is defined if: |
||
186 | * |
||
187 | * - the class has a getter or setter method associated with the specified name |
||
188 | * (in this case, property name is case-insensitive); |
||
189 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
190 | * |
||
191 | * @param string $name the property name |
||
192 | * @param bool $checkVars whether to treat member variables as properties |
||
193 | * |
||
194 | * @return bool whether the property is defined |
||
195 | * @see canGetProperty() |
||
196 | * @see canSetProperty() |
||
197 | */ |
||
198 | public function hasProperty($name, $checkVars = true): bool |
||
202 | |||
203 | /** |
||
204 | * Returns a value indicating whether a property can be read. |
||
205 | * A property is readable if: |
||
206 | * |
||
207 | * - the class has a getter method associated with the specified name |
||
208 | * (in this case, property name is case-insensitive); |
||
209 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
210 | * |
||
211 | * @param string $name the property name |
||
212 | * @param bool $checkVars whether to treat member variables as properties |
||
213 | * |
||
214 | * @return bool whether the property can be read |
||
215 | * @see canSetProperty() |
||
216 | */ |
||
217 | public function canGetProperty($name, $checkVars = true): bool |
||
221 | |||
222 | /** |
||
223 | * Returns a value indicating whether a property can be set. |
||
224 | * A property is writable if: |
||
225 | * |
||
226 | * - the class has a setter method associated with the specified name |
||
227 | * (in this case, property name is case-insensitive); |
||
228 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
229 | * |
||
230 | * @param string $name the property name |
||
231 | * @param bool $checkVars whether to treat member variables as properties |
||
232 | * |
||
233 | * @return bool whether the property can be written |
||
234 | * @see canGetProperty() |
||
235 | */ |
||
236 | public function canSetProperty($name, $checkVars = true): bool |
||
240 | |||
241 | /** |
||
242 | * Returns a value indicating whether a method is defined. |
||
243 | * |
||
244 | * The default implementation is a call to php function `method_exists()`. |
||
245 | * You may override this method when you implemented the php magic method `__call()`. |
||
246 | * |
||
247 | * @param string $name the method name |
||
248 | * |
||
249 | * @return bool whether the method is defined |
||
250 | */ |
||
251 | public function hasMethod($name): bool |
||
255 | } |
||
256 |