Exemplo n.º 1
0
 /**
  * @param string $key
  * @param mixed $val
  * @return mixed|void
  * @throws Exception\ValidationException
  */
 public function set($key, $val)
 {
     if ($key == 'active') {
         // prevent abuse
         return;
     }
     if ($key != 'updated') {
         if ($this->exists($key)) {
             $currentVal = $this->get($key);
             // if current value is not a relational object
             // and value has changed -> update table col
             if (!is_object($currentVal) && $currentVal != $val) {
                 $this->touch('updated');
             }
         }
     }
     // trim all values
     if (is_string($val)) {
         $val = trim($val);
     }
     $valid = $this->validateField($key, $val);
     if (!$valid) {
         $this->throwValidationError($key);
     } else {
         return parent::set($key, $val);
     }
 }
Exemplo n.º 2
0
 /**
  * @param string $key
  * @param mixed $val
  * @return mixed|void
  * @throws Exception\ValidationException
  */
 public function set($key, $val)
 {
     if (!$this->dry() && $key != 'updated') {
         if ($this->exists($key)) {
             $currentVal = $this->get($key);
             // if current value is not a relational object
             // and value has changed -> update table col
             if (is_object($currentVal)) {
                 if (is_numeric($val) && is_subclass_of($currentVal, 'Model\\BasicModel') && $currentVal->_id !== (int) $val) {
                     $this->touch('updated');
                 }
             } elseif ($currentVal != $val) {
                 $this->touch('updated');
             }
         }
     }
     // trim all values
     if (is_string($val)) {
         $val = trim($val);
     }
     $valid = $this->validateField($key, $val);
     if (!$valid) {
         $this->throwValidationError($key);
     } else {
         return parent::set($key, $val);
     }
 }