Exemplo n.º 1
0
 /**
  * Adding event or behavior to the current object.
  * 
  * If method name begins with 'on', it considered to be event. 
  * Or behavior otherwise.
  *
  * @param string the name of the event/behavior
  * @param mixed It might be callable (in case of lambda-function); array of class/object and  method name;
  * or instance of Behavior class
  * @return null
  * @throws EventException in case of error
  * @throws BehaviorException in case of error
  */
 function __set($name, $value)
 {
     if (empty($name) || !is_string($name)) {
         throw new EventException("Wrong parameter");
     }
     $name = strtolower($name);
     if (method_exists($this, $name) || property_exists_safe(get_class($this), $name)) {
         throw new EventException("Method or property {$name} in class " . get_class($this) . " already exists");
     }
     if (stripos($name, 'on') === 0) {
         // event
         if (!is_callable($value) && !is_string($value) && (!is_array($value) || count($value) != 2)) {
             throw new EventException("Wrong callback function in event {$name}");
         } else {
             $this->__events[substr($name, 2)][] = $value;
         }
     } else {
         // behavior
         if (!is_callable($value) && !$value instanceof Behavior && (!is_array($value) || count($value) != 2)) {
             $this->__injected_properties[$name] = $value;
         } elseif (array_key_exists($name, $this->__behaviors)) {
             throw new BehaviorException("Behavior {$name} already exists");
         } else {
             $this->__behaviors[$name] = $value;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Method description
  *
  * More detailed method description
  * @param    string $attribute    
  * @param    mixed $value    
  * @return   void
  */
 function addPlain($attribute, $value)
 {
     if (empty($attribute) || empty($value) || !property_exists_safe(get_class($this), $attribute)) {
         return;
     }
     if (!isset($this->{$attribute})) {
         $this->{$attribute} = new WJSEvent();
     }
     $this->{$attribute}->addToPlain($value);
 }