Пример #1
0
 /**
  * Copy value or method return of source property to destination property
  * 
  *  @param t41_Data_Object $do
  *  @return boolean
  */
 public function execute(t41_Data_Object $do)
 {
     try {
         $prep = array();
         foreach ($this->_source as $elem) {
             if (in_array($elem, array('+', '-', '/', '*'))) {
                 $prep[] = $elem;
             } else {
                 if (strpos($elem, '.') !== false) {
                     $props = explode('.', $elem);
                     $value = $do;
                     foreach ($props as $prop) {
                         if ($value instanceof \t41\ObjectModel\DataObject) {
                             $value = $value->getProperty($prop)->getValue();
                         } else {
                             if ($value instanceof ObjectModel\BaseObject) {
                                 $value = $value->getProperty($prop);
                             } else {
                                 if ($value instanceof Property\PropertyAbstract) {
                                     $value = $value->getValue();
                                 }
                             }
                         }
                     }
                     $prep[] = $value instanceof Property\PropertyAbstract ? $value->getValue() : $value;
                 } else {
                     $prep[] = $do->getProperty($elem)->getValue();
                 }
             }
         }
         $value = (double) eval(sprintf('return %s;', implode($prep)));
         /* set destination value with source value */
         if (is_array($this->_destination)) {
             $do->getProperty($this->_destination[0])->getProperty($this->_destination[1])->setValue($value);
         } else {
             $do->getProperty($this->_destination)->setValue($value);
         }
     } catch (Exception $e) {
         echo $e->getTraceAsString();
         /* @todo log exception */
         return false;
     }
     return true;
 }
Пример #2
0
 public function __call($m, $a)
 {
     $method_begin = substr($m, 0, 3);
     $method_end = strtolower(substr($m, 3));
     switch ($method_begin) {
         // reset a property value to null
         case 'del':
             $this->_triggerRules('before/set/' . $method_end);
             $res = $this->_dataObject->getProperty($method_end);
             if ($res === false) {
                 throw new Exception('OBJECT_UNKNOWN_PROPERTY', $method_end);
             }
             var_dump($res);
             die;
             $res->resetValue();
             $this->_triggerRules('after/set/' . $method_end);
             break;
         case 'set':
             $this->_triggerRules('before/set/' . $method_end);
             $res = $this->_dataObject->{$method_end} = $a[0];
             if ($res === false) {
                 throw new Exception('OBJECT_UNKNOWN_PROPERTY', $method_end);
             }
             $this->_triggerRules('after/set/' . $method_end);
             break;
             /* get a property value with optional parameter passed in $a[0] */
         /* get a property value with optional parameter passed in $a[0] */
         case 'get':
             if (($property = $this->_dataObject->getProperty($method_end)) !== false) {
                 $this->_triggerRules('before/get/' . $method_end);
                 $prop = $property->getValue(isset($a[0]) ? $a[0] : null);
                 $this->_triggerRules('after/get/' . $method_end);
                 return $prop;
             } else {
                 throw new Exception('OBJECT_UNKNOWN_PROPERTY', $method_end);
             }
             break;
         default:
             throw new Exception(array("UNKNOWN_METHOD", $m));
             break;
     }
     return $this;
 }