public function __call($name, $args) { //if the scope is null if (is_null($this->_scope)) { //just call the parent return parent::__call($name, $args); } //get the results from the method call $results = $this->_getResults($name, $args); //set temp variables $name = $this->_name; $scope = $this->_scope; //reset globals $this->_name = NULL; $this->_scope = NULL; //if there's a property name if ($name) { //output that $scope->debug($name); //and return the results return $results; } //at this point we should output the results $class = get_class($scope); $this->output(sprintf(self::DEBUG, $class . '->' . $name))->output($results); //and return the results return $results; }
public function __call($name, $args) { if (strpos($name, 'filterBy') === 0) { //filterByUserName('Chris', '-') $separator = '_'; if (isset($args[1]) && is_scalar($args[1])) { $separator = (string) $args[1]; } $key = Eden_Type_String::i($name)->substr(8)->preg_replace("/([A-Z])/", $separator . "\$1")->substr(strlen($separator))->strtolower()->get(); if (!isset($args[0])) { $args[0] = NULL; } $key = $key . '=%s'; $this->addFilter($key, $args[0]); return $this; } if (strpos($name, 'sortBy') === 0) { //filterByUserName('Chris', '-') $separator = '_'; if (isset($args[1]) && is_scalar($args[1])) { $separator = (string) $args[1]; } $key = Eden_Type_String::i($name)->substr(6)->preg_replace("/([A-Z])/", $separator . "\$1")->substr(strlen($separator))->strtolower()->get(); if (!isset($args[0])) { $args[0] = self::ASC; } $this->addSort($key, $args[0]); return $this; } try { return parent::__call($name, $args); } catch (Eden_Error $e) { Eden_Facebook_Error::i($e->getMessage())->trigger(); } }
public function __call($name, $args) { $type = $this->_getMethodType($name); //if no type if (!$type) { //we don't process anything else try { //call the parent return parent::__call($name, $args); } catch (Eden_Error $e) { Eden_Type_Error::i($e->getMessage())->trigger(); } } //case different types switch ($type) { case self::PRE: //if pre, we add it first into the args array_unshift($args, $this->_data); break; case self::POST: //if post, we add it last into the args array_push($args, $this->_data); break; case self::REFERENCE: //if reference, we add it first //into the args and call it call_user_func_array($name, array_merge(array(&$this->_data), $args)); return $this; } //call the method $result = call_user_func_array($name, $args); //if the result is a string if (is_string($result)) { //if this class is a string type if ($this instanceof Eden_Type_String) { //set value $this->_data = $result; return $this; } //return string class return Eden_Type_String::i($result); } //if the result is an array if (is_array($result)) { //if this class is a array type if ($this instanceof Eden_Type_Array) { //set value $this->_data = $result; return $this; } //return array class return Eden_Type_Array::i($result); } return $result; }
public function __call($name, $args) { //if the method name starts with a capital letter //most likely they want a class //since we are in the loader class //we might as well try to load it if (preg_match("/^[A-Z]/", $name)) { $this->load($name); } return parent::__call($name, $args); }
public function __call($name, $args) { //if the scope is null if (is_null($this->_scope)) { //just call the parent return parent::__call($name, $args); } //get the results from the method call $results = $this->_getResults($name, $args); //lets make sure this is loopable $loopable = is_scalar($results) ? array($results) : $results; //at this point we should loop through the results foreach ($loopable as $key => $value) { call_user_func($this->_callback, $key, $value); } //and return the results return $results; }
public function __call($name, $args) { //if the method starts with get if (strpos($name, 'get') === 0) { //getUserName('-') - get all rows column values $value = isset($args[0]) ? $args[0] : NULL; //make a new model $list = Eden_Model::i(); //for each row foreach ($this->_list as $i => $row) { //just add the column they want //let the model worry about the rest $list[] = $row->{$name}(isset($args[0]) ? $args[0] : NULL); } return $list; //if the method starts with set } else { if (strpos($name, 'set') === 0) { //setUserName('Chris', '-') - set all user names to Chris $value = isset($args[0]) ? $args[0] : NULL; $separator = isset($args[1]) ? $args[1] : NULL; //for each row foreach ($this->_list as $i => $row) { //just call the method //let the model worry about the rest $row->{$name}($value, $separator); } return $this; } } //nothing more, just see what the parent has to say try { return parent::__call($name, $args); } catch (Eden_Error $e) { Eden_Collection_Error::i($e->getMessage())->trigger(); } }
public function __call($name, $args) { //if the method starts with get if (strpos($name, 'get') === 0) { //getUserName('-') - get all rows column values $value = isset($args[0]) ? $args[0] : NULL; //make a new model $list = Eden_Model::i(); //for each row foreach ($this->_list as $i => $row) { //just add the column they want //let the model worry about the rest $list[] = $row->{$name}(isset($args[0]) ? $args[0] : NULL); } return $list; //if the method starts with set } else { if (strpos($name, 'set') === 0) { //setUserName('Chris', '-') - set all user names to Chris $value = isset($args[0]) ? $args[0] : NULL; $separator = isset($args[1]) ? $args[1] : NULL; //for each row foreach ($this->_list as $i => $row) { //just call the method //let the model worry about the rest $row->{$name}($value, $separator); } return $this; } } $found = false; //for an array of models the method might exist //we should loop and check for a valid method foreach ($this->_list as $i => $row) { //if no method exists if (!method_exists($row, $name)) { continue; } $found = true; //just call the method //let the model worry about the rest $row->callThis($name, $args); } //if found, it means something happened if ($found) { //so it was successful return $this; } //nothing more, just see what the parent has to say try { return parent::__call($name, $args); } catch (Eden_Error $e) { Eden_Collection_Error::i($e->getMessage())->trigger(); } }
public function __call($name, $args) { if (strpos($name, 'set') === 0) { $method = substr($name, 3); if (isset(self::$_setBoolKeys[$method])) { Eden_Curl_Error::i()->vargument($name, $args, 1, 'bool'); $key = self::$_setBoolKeys[$method]; $this->_options[$key] = $args[0]; return $this; } if (isset(self::$_setIntegerKeys[$method])) { Eden_Curl_Error::i()->vargument($name, $args, 1, 'int'); $key = self::$_setIntegerKeys[$method]; $this->_options[$key] = $args[0]; return $this; } if (isset(self::$_setStringKeys[$method])) { Eden_Curl_Error::i()->vargument($name, $args, 1, 'string'); $key = self::$_setStringKeys[$method]; $this->_options[$key] = $args[0]; return $this; } if (isset(self::$_setArrayKeys[$method])) { Eden_Curl_Error::i()->vargument($name, $args, 1, 'array'); $key = self::$_setArrayKeys[$method]; $this->_options[$key] = $args[0]; return $this; } if (isset(self::$_setFileKeys[$method])) { $key = self::$_setFileKeys[$method]; $this->_options[$key] = $args[0]; return $this; } if (isset(self::$_setCallbackKeys[$method])) { Eden_Curl_Error::i()->vargument($name, $args, 1, 'array', 'string'); $key = self::$_setCallbackKeys[$method]; $this->_options[$key] = $args[0]; return $this; } } parent::__call($name, $args); }
/** * Returns the string version of the query * * @param bool * @return string * @notes returns the query based on the registry */ public function getQuery() { return '(' . substr(parent::getQuery(), 0, -1) . ')'; }
if(!class_exists('Eden_Facebook_Search')){class Eden_Facebook_Search extends Eden_Class{const ASC='ASC';const DESC='DESC';protected $_database=NULL;protected $_table=NULL;protected $_columns=array();protected $_filter=array();protected $_sort=array();protected $_start=0;protected $_range=0;protected $_group=array();public static function i(){return self::_getMultiple(__CLASS__);}public function __call($name,$args){if(strpos($name,'filterBy')===0){$separator='_';if(isset($args[1]) && is_scalar($args[1])){$separator=(string) $args[1];}$key=Eden_Type_String::i($name)->substr(8)->preg_replace("/([A-Z])/",$separator."$1")->substr(strlen($separator))->strtolower()->get();if(!isset($args[0])){$args[0]=NULL;}$key=$key.'=%s';$this->addFilter($key,$args[0]);return $this;}if(strpos($name,'sortBy')===0){$separator='_';if(isset($args[1]) && is_scalar($args[1])){$separator=(string) $args[1];}$key=Eden_Type_String::i($name)->substr(6)->preg_replace("/([A-Z])/",$separator."$1")->substr(strlen($separator))->strtolower()->get();if(!isset($args[0])){$args[0]=self::ASC;}$this->addSort($key,$args[0]);return $this;}try{return parent::__call($name,$args);}catch(Eden_Error $e){Eden_Facebook_Error::i($e->getMessage())->trigger();}}public function __construct(Eden_Facebook_Fql $database){$this->_database=$database;}public function addFilter(){Eden_Facebook_Error::i()->argument(1,'string');$this->_filter[]=func_get_args();return $this;}public function addSort($column,$order=self::ASC){Eden_Facebook_Error::i()->argument(1,'string')->argument(2,'string');if($order !=self::DESC){$order=self::ASC;}$this->_sort[$column]=$order;return $this;}public function getCollection($key='last'){$rows=$this->getRows($key);if(count($this->_group)==1){return Eden_Collection::i($rows);}foreach($rows as $key=>$collection){$rows[$key]=Eden_Collection::i($collection['fql_result_set']);}return $rows;}public function getRows($key='last'){$this->group($key);if(empty($this->_group)){return array();}$group=array();foreach($this->_group as $key=>$query){$this->_table=$query['table'];$this->_columns=$query['columns'];$this->_filter=$query['filter'];$this->_sort=$query['sort'];$this->_start=$query['start'];$this->_range=$query['range'];$query=$this->_getQuery();if(!empty($this->_columns)){$query->select(implode(',',$this->_columns));}foreach($this->_sort as $name=>$value){$query->sortBy($name,$value);}if($this->_range){$query->limit($this->_start,$this->_range);}$group[$key]=$query;}$query=$group;if(count($query)==1){$query=$group[$key];}$results=$this->_database->query($query);return $results;}public function getTotal(){$query=$this->_getQuery()->select('COUNT(*) as total');$rows=$this->_database->query($query);if(!isset($rows[0]['total'])){return 0;}return $rows[0]['total'];}public function group($key){Eden_Facebook_Error::i()->argument(1,'scalar');if(is_null($this->_table)){return $this;}$this->_group[$key]=array( 'table'=>$this->_table,'columns'=>$this->_columns,'filter'=>$this->_filter,'sort'=>$this->_sort,'start'=>$this->_start,'range'=>$this->_range);$this->_table=NULL;$this->_columns=array();$this->_filter=array();$this->_sort=array();$this->_start=0;$this->_range=0;return $this;}public function setColumns($columns){if(!is_array($columns)){$columns=func_get_args();}$this->_columns=$columns;return $this;}public function setPage($page){Eden_Facebook_Error::i()->argument(1,'int');if($page < 1){$page=1;}$this->_start=($page - 1) * $this->_range;return $this;}public function setRange($range){Eden_Facebook_Error::i()->argument(1,'int');if($range < 0){$range=25;}$this->_range=$range;return $this;}public function setStart($start){Eden_Facebook_Error::i()->argument(1,'int');if($start < 0){$start=0;}$this->_start=$start;return $this;}public function setTable($table){Eden_Facebook_Error::i()->argument(1,'string');$this->_table=$table;return $this;}protected function _getQuery(){$query=$this->_database->select()->from($this->_table);foreach($this->_filter as $i=>$filter){$where=array_shift($filter);if(!empty($filter)){foreach($filter as $i=>$value){if(!is_string($value)){continue;}$filter[$i]="'".$value."'";}$where=vsprintf($where,$filter);}$query->where($where);}return $query;}}}