Exemplo n.º 1
0
 public function __call($method, array $args)
 {
     if (!preg_match('~^(set|get)([A-Z_])(.*)$~', $method, $matches)) {
         return parent::__call($method, $args);
     }
     //$property = strtolower($matches[2]) . $matches[3];
     $property = $matches[2] . $matches[3];
     if ($matches[1] == 'set') {
         $this->__set($property, $args[0]);
         return $this;
     }
     return $this->__get($property);
 }
Exemplo n.º 2
0
 /**
  * Prekryti magicke metody, aby odchytavala gettery a settery
  *
  * @param string $method
  * @param array $args
  */
 public function __call($method, array $args)
 {
     $matches = array();
     if (preg_match('/^get(\\w+?)$/', $method, $matches)) {
         $attribute = $matches[1];
         return $this->{$attribute};
     }
     if (preg_match('/^set(\\w+?)$/', $method, $matches)) {
         $attribute = $matches[1];
         $this->{$attribute} = count($args) == 1 ? $args[0] : null;
         return;
     }
     return parent::__call($method, $args);
 }
Exemplo n.º 3
0
 /**
  * Turn magic function calls into non-magic function calls
  * to class methods.
  *
  * @param  string $method
  * @param  array $args OPTIONAL Zend_Db_Table_Select query modifier
  * @return Zend_Db_Table_Row_Abstract|Zend_Db_Table_Rowset_Abstract
  */
 public function __call($method, array $args)
 {
     $matches = array();
     if (count($args) && $args[0] instanceof Zend_Db_Table_Select) {
         $select = $args[0];
     } else {
         $select = null;
     }
     /**
      * Recognize methods for Has-One cases:
      * get<Rule>()
      */
     if (preg_match('/^get(\\w+)$/', $method, $matches)) {
         $rule = $matches[1];
         return $this->findParentRowByRule($rule, $select);
     }
     return parent::__call($method, $args);
 }
Exemplo n.º 4
0
 public function __call($method, array $args)
 {
     if (preg_match('/^set(\\w*)/', $method, $matches)) {
         $first = mb_convert_case(mb_substr($matches[1], 0, 1), MB_CASE_LOWER);
         $column = preg_replace('/^./', $first, $matches[1]);
         if (count($args)) {
             $this->__set($column, $args[0]);
             return $this;
         }
     } else {
         if (preg_match('/^get(\\w*)/', $method, $matches)) {
             $first = mb_convert_case(mb_substr($matches[1], 0, 1), MB_CASE_LOWER);
             $column = preg_replace('/^./', $first, $matches[1]);
             return $this->__get($column);
         }
     }
     parent::__call($method, $args);
 }
Exemplo n.º 5
0
 public function __call($method, array $args)
 {
     switch (substr($method, 0, 3)) {
         case 'get':
             $key = $this->_transformColumn(substr($method, 3));
             return $this->getData($key);
         case 'set':
             parent::__set(substr($method, 3), isset($args[0]) ? $args[0] : null);
             return $this;
         case 'uns':
             $key = $this->_transformColumn(substr($method, 3));
             unset($this->_data[$key]);
             unset($this->_modifiedFields[$key]);
             return $this;
         case 'has':
             $key = $this->_transformColumn(substr($method, 3));
             return isset($this->_data[$key]);
     }
     return parent::__call($method, $args);
 }
Exemplo n.º 6
0
 public function __call($method, array $args)
 {
     # check if $method exists in case this method is called directly
     if (method_exists($this, $method)) {
         return call_user_func(array($this, $method), $args);
     }
     if (preg_match('/^set(\\w*)/', $method, $matches)) {
         $first = mb_convert_case(mb_substr($matches[1], 0, 1), MB_CASE_LOWER);
         $column = preg_replace('/^./', $first, $matches[1]);
         if (count($args)) {
             $this->__set($column, $args[0]);
             return $this;
         }
     } else {
         if (preg_match('/^get(\\w*)/', $method, $matches)) {
             $first = mb_convert_case(mb_substr($matches[1], 0, 1), MB_CASE_LOWER);
             $column = preg_replace('/^./', $first, $matches[1]);
             return $this->__get($column);
         }
     }
     parent::__call($method, $args);
 }
Exemplo n.º 7
0
 public function __call($method, array $args)
 {
     $lcMethod = strtolower($method);
     //TODO: change all substr by strncmp
     if (!strncmp($lcMethod, 'getnextby', 9)) {
         $by = substr($method, 9, strlen($method));
         $method = 'getNextBy';
     } else {
         if (substr($lcMethod, 0, 13) == 'getpreviousby') {
             $by = substr($method, 13, strlen($method));
             $method = 'getPreviousBy';
         } else {
             if (substr($lcMethod, 0, 10) == 'getfirstby') {
                 $by = substr($method, 10, strlen($method));
                 $method = 'getFirstBy';
             } else {
                 if (substr($lcMethod, 0, 9) == 'getlastby') {
                     $by = substr($method, 9, strlen($method));
                     $method = 'getLastBy';
                 } else {
                     if (substr($lcMethod, 0, 15) == 'getdateobjectby') {
                         $by = substr($method, 15, strlen($method));
                         $method = 'getDateObjectBy';
                     } else {
                         if (substr($lcMethod, 0, 16) == 'getpictureorpxby') {
                             $by = substr($method, 16, strlen($method));
                             $method = 'getPictureOrPxBy';
                         } else {
                             if (substr($lcMethod, 0, 3) == 'get' && preg_match('`get((.+)Or(.+))+`', $method)) {
                                 $lcMethod = substr($lcMethod, 3);
                                 $columns = explode('or', $lcMethod);
                                 foreach ($columns as $column) {
                                     if (isset($this->{$column}) && null !== $this->{$column}) {
                                         return $this->{$column};
                                     }
                                 }
                                 return null;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($by)) {
         return call_user_func_array(array($this, $method), array_merge(array($by), $args));
     }
     if (is_array($args) && count($args) == 1 && $args[0] instanceof Centurion_Db_Table_Select) {
         $columnName = $this->_transformColumn($method);
         $referenceMap = $this->getTable()->info('referenceMap');
         $select = $args[0];
         if (isset($referenceMap[$columnName])) {
             $column = $referenceMap[$columnName]['columns'];
             $className = $referenceMap[$columnName]['refTableClass'];
             if (!isset(self::$_relationship[$className][$this->{$column}])) {
                 self::$_relationship[$className][$this->{$column}] = $this->findParentRow($referenceMap[$columnName]['refTableClass'], $columnName, $select);
             }
             return self::$_relationship[$className][$this->{$column}];
         }
         $dependentTables = $this->getTable()->info('dependentTables');
         if (isset($dependentTables[$columnName])) {
             if (!isset($this->_children[$columnName])) {
                 $this->_children[$columnName] = $this->findDependentRowset($dependentTables[$columnName], null, $select);
             }
             return $this->_children[$columnName];
         }
         $manyDependentTables = $this->getTable()->info('manyDependentTables');
         if (isset($manyDependentTables[$columnName])) {
             if (!isset($this->_children[$columnName])) {
                 $this->_children[$columnName] = $this->findManyToManyRowset($manyDependentTables[$columnName]['refTableClass'], $manyDependentTables[$columnName]['intersectionTable'], null, null, $select);
                 $this->_children[$columnName]->setIntersectionColumns($manyDependentTables[$columnName]['columns']);
             }
             return $this->_children[$columnName];
         }
     }
     try {
         $retVal = parent::__call($method, $args);
     } catch (Zend_Db_Table_Row_Exception $e) {
         list($found, $retVal) = Centurion_Traits_Common::checkTraitOverload($this, $method, $args);
         if (!$found) {
             throw $e;
         }
     }
     return $retVal;
 }
Exemplo n.º 8
0
 /**
  * Set/Get attribute wrapper
  *
  * @param   string $method
  * @param   array $args
  * @return  mixed
  */
 public function __call($method, array $args)
 {
     try {
         return parent::__call($method, $args);
     } catch (Zend_Db_Table_Row_Exception $e) {
         switch (substr($method, 0, 3)) {
             case 'get':
                 $key = $this->_underscore(substr($method, 3));
                 array_unshift($args, $key);
                 $data = call_user_func_array(array($this, 'getData'), $args);
                 return $data;
                 break;
             case 'set':
                 $key = $this->_underscore(substr($method, 3));
                 array_unshift($args, $key);
                 $data = call_user_func_array(array($this, 'setData'), $args);
                 return $data;
                 break;
             case 'uns':
                 $key = $this->_underscore(substr($method, 3));
                 array_unshift($args, $key);
                 return call_user_func_array(array($this, 'unsetData'), $args);
                 break;
             case 'has':
                 $key = $this->_underscore(substr($method, 3));
                 return isset($this->_data[$key]);
                 break;
             case 'add':
                 $key = $this->_underscore(substr($method, 3));
                 array_unshift($args, $key);
                 $data = call_user_func_array(array($this, 'addData'), $args);
                 return $data;
                 break;
             case '_ge':
                 $key = $this->_underscore(substr($method, 3));
                 array_unshift($args, $key);
                 $data = call_user_func_array(array($this, '_getData'), $args);
                 return $data;
                 break;
         }
         throw $e;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 9
0
 public function __call($func, $args)
 {
     if (preg_match("/get(\\w+)/", $func, $matches)) {
         $key = strtolower($matches[1]);
         $value = $this->{$key};
         if ($value) {
             return $value;
         }
         if (!array_key_exists($key, $this->_defaultValues)) {
             throw new Exception("No default value for {$key}");
         }
         return $this->_defaultValues[$key];
     } else {
         parent::__call($func, $args);
     }
 }
Exemplo n.º 10
0
 /** \zfb_read ActiveRow_Abstract..__call */
 public function __call($name, array $arguments)
 {
     try {
         parent::__call($name, $arguments);
     } catch (Zend_Db_Table_Row_Exception $e) {
         $result = false;
         foreach (array('set', 'get', 'is', 'unique') as $action) {
             if (substr_compare($name, $action, 0, strlen($action)) === 0) {
                 $result = true;
                 break;
             }
         }
         if (!$result) {
             throw new Zend_Db_Table_Row_Exception($e->getMessage());
         }
         $var = strtolower(substr($name, strlen($action), 1)) . substr($name, strlen($action) + 1);
         if (!array_key_exists($var, $this->_dataMap)) {
             throw new Zend_Db_Table_Row_Exception($e->getMessage());
         }
         switch ($action) {
             case 'set':
                 $value = $arguments[0];
                 if (in_array($var, $this->_timestampFields)) {
                     if (!$value instanceof Zend_Date) {
                         throw new Zend_Db_Table_Row_Exception("Value for {$name}() must be of class Zend_Date.");
                     }
                     $this->{$var} = $value->getTimestamp();
                 } else {
                     $this->{$var} = $value;
                 }
                 return $this;
                 break;
             case 'get':
                 if (in_array($var, $this->_timestampFields)) {
                     return new Zend_Date((int) $this->{$var});
                 } else {
                     if (isset($this->_fieldDecorators[$var])) {
                         return $this->_loadFieldDecorator($var)->decorate($this->{$var});
                     }
                     return $this->{$var};
                 }
                 break;
             case 'is':
                 if (!in_array($this->{$var}, array(null, 0, 1, '0', '1', true, false), true)) {
                     throw new Zend_Db_Table_Row_Exception($e->getMessage());
                 }
                 return $this->{$var} === null ? null : (bool) $this->{$var};
                 break;
             case 'unique':
                 $value = isset($arguments[0]) ? $arguments[0] : $this->{$var};
                 if ($value === null) {
                     return false;
                 }
                 if (($table = $this->getTable()) === null) {
                     throw new Zend_Db_Table_Row_Exception("Can't run {$name}() method on disconnected row.");
                 }
                 $column = $this->_dataMap[$var];
                 $select = $table->select();
                 $select->from($table->info('name'), array('num' => "COUNT({$column})"));
                 $select->where("{$column} = ?", $value);
                 return !$table->fetchRow($select)->num;
                 break;
         }
     }
 }