1 | <?php |
||
77 | class Object implements Configurable |
||
78 | { |
||
79 | /** |
||
80 | * Constructor. |
||
81 | * The default implementation does two things: |
||
82 | * |
||
83 | * - Initializes the object with the given configuration `$config`. |
||
84 | * - Call [[init()]]. |
||
85 | * |
||
86 | * If this method is overridden in a child class, it is recommended that |
||
87 | * |
||
88 | * - the last parameter of the constructor is a configuration array, like `$config` here. |
||
89 | * - call the parent implementation at the end of the constructor. |
||
90 | * |
||
91 | * @param array $config name-value pairs that will be used to initialize the object properties |
||
92 | */ |
||
93 | public function __construct($config = []) |
||
100 | |||
101 | /** |
||
102 | * Initializes the object. |
||
103 | * This method is invoked at the end of the constructor after the object is initialized with the |
||
104 | 2214 | * given configuration. |
|
105 | */ |
||
106 | 2214 | public function init() |
|
109 | 2214 | ||
110 | 2214 | /** |
|
111 | * Returns the value of an object property. |
||
112 | * |
||
113 | * Do not call this method directly as it is a PHP magic method that |
||
114 | * will be implicitly called when executing `$value = $object->property;`. |
||
115 | * @param string $name the property name |
||
116 | * @return mixed the property value |
||
117 | 2075 | * @throws UnknownPropertyException if the property is not defined |
|
118 | * @throws InvalidCallException if the property is write-only |
||
119 | 2075 | * @see __set() |
|
120 | */ |
||
121 | public function __get($name) |
||
132 | 29 | ||
133 | /** |
||
134 | 29 | * Sets value of an object property. |
|
135 | 29 | * |
|
136 | 28 | * Do not call this method directly as it is a PHP magic method that |
|
137 | 2 | * will be implicitly called when executing `$object->property = $value;`. |
|
138 | 1 | * @param string $name the property name or the event name |
|
139 | * @param mixed $value the property value |
||
140 | 1 | * @throws UnknownPropertyException if the property is not defined |
|
141 | * @throws InvalidCallException if the property is read-only |
||
142 | * @see __get() |
||
143 | */ |
||
144 | public function __set($name, $value) |
||
155 | 32 | ||
156 | /** |
||
157 | 32 | * Checks if a property is set, i.e. defined and not null. |
|
158 | 32 | * |
|
159 | 31 | * Do not call this method directly as it is a PHP magic method that |
|
160 | 32 | * will be implicitly called when executing `isset($object->property)`. |
|
161 | 1 | * |
|
162 | * Note that if the property is not defined, false will be returned. |
||
163 | 1 | * @param string $name the property name or the event name |
|
164 | * @return boolean whether the named property is set (not null). |
||
165 | 31 | * @see http://php.net/manual/en/function.isset.php |
|
166 | */ |
||
167 | public function __isset($name) |
||
176 | |||
177 | /** |
||
178 | 2 | * Sets an object property to null. |
|
179 | * |
||
180 | 2 | * Do not call this method directly as it is a PHP magic method that |
|
181 | 2 | * will be implicitly called when executing `unset($object->property)`. |
|
182 | 2 | * |
|
183 | * Note that if the property is not defined, this method will do nothing. |
||
184 | 1 | * If the property is read-only, it will throw an exception. |
|
185 | * @param string $name the property name |
||
186 | * @throws InvalidCallException if the property is read only. |
||
187 | * @see http://php.net/manual/en/function.unset.php |
||
188 | */ |
||
189 | public function __unset($name) |
||
198 | |||
199 | /** |
||
200 | 2 | * Calls the named method which is not a class method. |
|
201 | * |
||
202 | 2 | * Do not call this method directly as it is a PHP magic method that |
|
203 | 2 | * will be implicitly called when an unknown method is being invoked. |
|
204 | 1 | * @param string $name the method name |
|
205 | 2 | * @param array $params method parameters |
|
206 | 1 | * @throws UnknownMethodException when calling unknown method |
|
207 | * @return mixed the method return value |
||
208 | 1 | */ |
|
209 | public function __call($name, $params) |
||
213 | |||
214 | /** |
||
215 | * Returns a value indicating whether a property is defined. |
||
216 | * A property is defined if: |
||
217 | * |
||
218 | * - the class has a getter or setter method associated with the specified name |
||
219 | * (in this case, property name is case-insensitive); |
||
220 | 28 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
|
221 | * |
||
222 | 1 | * @param string $name the property name |
|
223 | 28 | * @param boolean $checkVars whether to treat member variables as properties |
|
224 | * @return boolean whether the property is defined |
||
225 | * @see canGetProperty() |
||
226 | * @see canSetProperty() |
||
227 | */ |
||
228 | public function hasProperty($name, $checkVars = true) |
||
232 | |||
233 | /** |
||
234 | * Returns a value indicating whether a property can be read. |
||
235 | * A property is readable if: |
||
236 | * |
||
237 | * - the class has a getter method associated with the specified name |
||
238 | * (in this case, property name is case-insensitive); |
||
239 | 1 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
|
240 | * |
||
241 | 1 | * @param string $name the property name |
|
242 | * @param boolean $checkVars whether to treat member variables as properties |
||
243 | * @return boolean whether the property can be read |
||
244 | * @see canSetProperty() |
||
245 | */ |
||
246 | public function canGetProperty($name, $checkVars = true) |
||
250 | |||
251 | /** |
||
252 | * Returns a value indicating whether a property can be set. |
||
253 | * A property is writable if: |
||
254 | * |
||
255 | * - the class has a setter method associated with the specified name |
||
256 | * (in this case, property name is case-insensitive); |
||
257 | 6 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
|
258 | * |
||
259 | 6 | * @param string $name the property name |
|
260 | * @param boolean $checkVars whether to treat member variables as properties |
||
261 | * @return boolean whether the property can be written |
||
262 | * @see canGetProperty() |
||
263 | */ |
||
264 | public function canSetProperty($name, $checkVars = true) |
||
268 | |||
269 | /** |
||
270 | * Returns a value indicating whether a method is defined. |
||
271 | * |
||
272 | * The default implementation is a call to php function `method_exists()`. |
||
273 | * You may override this method when you implemented the php magic method `__call()`. |
||
274 | * @param string $name the method name |
||
275 | 5 | * @return boolean whether the method is defined |
|
276 | */ |
||
277 | 5 | public function hasMethod($name) |
|
281 | } |
||
282 |