<?PHP/** * Checks If a property value is null. * Check whether the property value is empty. * This method would check in the following order and act accordingly: * This approach will be checked in the following order and acted accordingly: *-a property define D by a Setter:return whether the property value is NULL * properties defined by setter: Returns whether the value of the attribute is empty *-a property of a Behavi Or:return whether the property value is null * The behavior of the attribute: Returns whether the value of the attribute is empty * does not call this method directly as it is a PH P Magic Method that * would be implicitly called when executing ' isset ($component->property) '. * * Rewrite the Isset method in Object, add the processing to behaviors, loop behaviors, if there are corresponding attributes, it is considered to have * * @param string $name the property Name or the event name * @return Boolean whether the named property is null*/ Public function__isset ($name) { $getter= ' Get '.$name; if(method_exists($this,$getter)) { //returns True if $getter method exists and is not NULL return $this-$getter() !==NULL; } Else { //Behavior Property $this-ensurebehaviors (); //Loop all the behavior foreach($this->_behaviors as $behavior) { if($behavior->cangetproperty ($name)) { //returns True if there is $name attribute in the behavior and is not NULL return $behavior-$name!==NULL; } } } return false; } /** * Sets a component property to IS null. * Set component properties to null. * This method would check in the following order and act accordingly: * This approach will be checked in the following order and acted accordingly: *-a property define D by a Setter:set the attribute value to IS null * property defined by setter: Set the property value to NULL *-a properties of a behavior:set the property value to being null * attribute's behavior: Set property values to empty * Do not call this method directly as it's a PHP magic method that * would be implicitly called when executing ' unset ($component->property) '. * * Rewrite the unset method in Object, add the processing to behaviors, loop behaviors, if there are corresponding properties, set to NULL * * @param string $name the property Name * @throws Invalidcallexception If the property was read only. */ Public function__unset ($name) { $setter= ' Set '.$name; if(method_exists($this,$setter)) { //returns True if $setter method exists and is not NULL $this-$setter(NULL); return; } Else { //Behavior Property $this-ensurebehaviors (); //Loop all the behavior foreach($this->_behaviors as $behavior) { if($behavior->cansetproperty ($name)) { //set this property to null if there is $name attribute in the behavior $behavior-$name=NULL; return; } } } Throw NewInvalidcallexception (' unsetting an unknown or read-only property: '.Get_class($this) . ‘::‘ .$name); } /** * Calls the named method which is not a class method. * Named methods that are called Non-class methods. * This method would check if any attached behavior have * The named method and would execute it if available. * Don't call the This method directly as it's a PHP magic method that * would be implicitly called if an unknown method is being invoked. * * Rewrite the call method in Object, add the processing to behaviors, loop behaviors, if there is a corresponding method, execute the Behavior method * * @param string $name th E Method Name * @param array $params method parameters * @return Mixed the method return value * @throws Unkno Wnmethodexception when calling unknown method*/ Public function__call ($name,$params) { $this-ensurebehaviors (); foreach($this->_behaviors as $object) { if($object->hasmethod ($name)) { //there is a method named $name in behavior, execute IT//call_user_func_array-call callback function, and take an array parameter as the parameter of the callback function return Call_user_func_array([$object,$name],$params); } } Throw NewUnknownmethodexception (' Calling unknown method: '.Get_class($this) . "::$name()"); } /** * This method was called after the object was created by cloning a existing one. * It removes all behaviors because they is attached to the old object. * * When cloning is performed, its _events and _behaviors are set to NULL * object replication can be done by using the Clone keyword (which, if possible, calls the object's __clone () method). The __clone () method in the object cannot be called directly. * ~ ~ ~ $copy _of_object = Clone $object; * ~ ~ ~ * When the object is copied, PHP 5 performs a shallow copy of all properties of the object (shallow copy). All reference properties will still be a reference to the original variable. */ Public function__clone () {//when an object is copied, its _events is set to an empty array, and the _behaviors is set to null $this->_events = []; $this->_behaviors =NULL; }
Yii2 Reading Essays 12