1 | <?php |
||
77 | class BaseObject implements Configurable |
||
78 | { |
||
79 | /** |
||
80 | * Returns the fully qualified name of this class. |
||
81 | * @return string the fully qualified name of this class. |
||
82 | * @deprecated since 2.0.14. On PHP >=5.5, use `::class` instead. |
||
83 | */ |
||
84 | public static function className() |
||
88 | |||
89 | /** |
||
90 | * Constructor. |
||
91 | * |
||
92 | * The default implementation does two things: |
||
93 | * |
||
94 | * - Initializes the object with the given configuration `$config`. |
||
95 | * - Call [[init()]]. |
||
96 | * |
||
97 | * If this method is overridden in a child class, it is recommended that |
||
98 | * |
||
99 | * - the last parameter of the constructor is a configuration array, like `$config` here. |
||
100 | * - call the parent implementation at the end of the constructor. |
||
101 | * |
||
102 | * @param array $config name-value pairs that will be used to initialize the object properties |
||
103 | */ |
||
104 | 4047 | public function __construct($config = []) |
|
111 | |||
112 | /** |
||
113 | * Initializes the object. |
||
114 | * This method is invoked at the end of the constructor after the object is initialized with the |
||
115 | * given configuration. |
||
116 | */ |
||
117 | 3921 | public function init() |
|
120 | |||
121 | /** |
||
122 | * Returns the value of an object property. |
||
123 | * |
||
124 | * Do not call this method directly as it is a PHP magic method that |
||
125 | * will be implicitly called when executing `$value = $object->property;`. |
||
126 | * @param string $name the property name |
||
127 | * @return mixed the property value |
||
128 | * @throws UnknownPropertyException if the property is not defined |
||
129 | * @throws InvalidCallException if the property is write-only |
||
130 | * @see __set() |
||
131 | */ |
||
132 | 69 | public function __get($name) |
|
143 | |||
144 | /** |
||
145 | * Sets value of an object property. |
||
146 | * |
||
147 | * Do not call this method directly as it is a PHP magic method that |
||
148 | * will be implicitly called when executing `$object->property = $value;`. |
||
149 | * @param string $name the property name or the event name |
||
150 | * @param mixed $value the property value |
||
151 | * @throws UnknownPropertyException if the property is not defined |
||
152 | * @throws InvalidCallException if the property is read-only |
||
153 | * @see __get() |
||
154 | */ |
||
155 | 32 | public function __set($name, $value) |
|
156 | { |
||
157 | 32 | $setter = 'set' . $name; |
|
158 | 32 | if (method_exists($this, $setter)) { |
|
159 | 31 | $this->$setter($value); |
|
160 | 1 | } elseif (method_exists($this, 'get' . $name)) { |
|
161 | 1 | throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); |
|
162 | } |
||
163 | |||
164 | 31 | throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name); |
|
165 | } |
||
166 | |||
167 | /** |
||
168 | * Checks if a property is set, i.e. defined and not null. |
||
169 | * |
||
170 | * Do not call this method directly as it is a PHP magic method that |
||
171 | * will be implicitly called when executing `isset($object->property)`. |
||
172 | * |
||
173 | * Note that if the property is not defined, false will be returned. |
||
174 | * @param string $name the property name or the event name |
||
175 | * @return bool whether the named property is set (not null). |
||
176 | * @see http://php.net/manual/en/function.isset.php |
||
177 | */ |
||
178 | 2 | public function __isset($name) |
|
179 | { |
||
180 | 2 | $getter = 'get' . $name; |
|
181 | 2 | if (method_exists($this, $getter)) { |
|
182 | 2 | return $this->$getter() !== null; |
|
183 | } |
||
184 | |||
185 | return false; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Sets an object property to null. |
||
190 | * |
||
191 | * Do not call this method directly as it is a PHP magic method that |
||
192 | * will be implicitly called when executing `unset($object->property)`. |
||
193 | * |
||
194 | * Note that if the property is not defined, this method will do nothing. |
||
195 | * If the property is read-only, it will throw an exception. |
||
196 | * @param string $name the property name |
||
197 | * @throws InvalidCallException if the property is read only. |
||
198 | * @see http://php.net/manual/en/function.unset.php |
||
199 | */ |
||
200 | 2 | public function __unset($name) |
|
209 | |||
210 | /** |
||
211 | * Calls the named method which is not a class method. |
||
212 | * |
||
213 | * Do not call this method directly as it is a PHP magic method that |
||
214 | * will be implicitly called when an unknown method is being invoked. |
||
215 | * @param string $name the method name |
||
216 | * @param array $params method parameters |
||
217 | * @throws UnknownMethodException when calling unknown method |
||
218 | * @return mixed the method return value |
||
219 | */ |
||
220 | 1 | public function __call($name, $params) |
|
224 | |||
225 | /** |
||
226 | * Returns a value indicating whether a property is defined. |
||
227 | * |
||
228 | * A property is defined if: |
||
229 | * |
||
230 | * - the class has a getter or setter method associated with the specified name |
||
231 | * (in this case, property name is case-insensitive); |
||
232 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
233 | * |
||
234 | * @param string $name the property name |
||
235 | * @param bool $checkVars whether to treat member variables as properties |
||
236 | * @return bool whether the property is defined |
||
237 | * @see canGetProperty() |
||
238 | * @see canSetProperty() |
||
239 | */ |
||
240 | 1 | public function hasProperty($name, $checkVars = true) |
|
244 | |||
245 | /** |
||
246 | * Returns a value indicating whether a property can be read. |
||
247 | * |
||
248 | * A property is readable if: |
||
249 | * |
||
250 | * - the class has a getter method associated with the specified name |
||
251 | * (in this case, property name is case-insensitive); |
||
252 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
253 | * |
||
254 | * @param string $name the property name |
||
255 | * @param bool $checkVars whether to treat member variables as properties |
||
256 | * @return bool whether the property can be read |
||
257 | * @see canSetProperty() |
||
258 | */ |
||
259 | 7 | public function canGetProperty($name, $checkVars = true) |
|
263 | |||
264 | /** |
||
265 | * Returns a value indicating whether a property can be set. |
||
266 | * |
||
267 | * A property is writable if: |
||
268 | * |
||
269 | * - the class has a setter method associated with the specified name |
||
270 | * (in this case, property name is case-insensitive); |
||
271 | * - the class has a member variable with the specified name (when `$checkVars` is true); |
||
272 | * |
||
273 | * @param string $name the property name |
||
274 | * @param bool $checkVars whether to treat member variables as properties |
||
275 | * @return bool whether the property can be written |
||
276 | * @see canGetProperty() |
||
277 | */ |
||
278 | 7 | public function canSetProperty($name, $checkVars = true) |
|
282 | |||
283 | /** |
||
284 | * Returns a value indicating whether a method is defined. |
||
285 | * |
||
286 | * The default implementation is a call to php function `method_exists()`. |
||
287 | * You may override this method when you implemented the php magic method `__call()`. |
||
288 | * @param string $name the method name |
||
289 | * @return bool whether the method is defined |
||
290 | */ |
||
291 | 14 | public function hasMethod($name) |
|
295 | } |
||
296 |