/** * Execute a controller action by it's name. * * Function is also capable of checking is a behavior has been mixed successfully using is[Behavior] function. If * the behavior exists the function will return TRUE, otherwise FALSE. * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return mixed * @see execute() */ public function __call($method, $args) { //Handle action alias method if (in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Create a context object if (!$data instanceof KCommandInterface) { $context = $this->getContext(); //Store the parameters in the context $context->param = $data; //Force the result to false before executing $context->result = false; } else { $context = $data; } //Execute the action return $this->execute($method, $context); } if (!isset($this->_mixed_methods[$method])) { //Check if a behavior is mixed $parts = KStringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { return false; } } return parent::__call($method, $args); }
/** * Supports a simple form of Fluent Interfaces. Allows you to assign variables to the view by using the variable * name as the method name. If the method name is a setter method the setter will be called instead. * * For example : $view->data(array('foo' => 'bar'))->title('name')->render() * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return KViewAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { if (!isset($this->_mixed_methods[$method])) { //If one argument is passed we assume a setter method is being called if (count($args) == 1) { if (!method_exists($this, 'set' . ucfirst($method))) { $this->{$method} = $args[0]; return $this; } else { return $this->{'set' . ucfirst($method)}($args[0]); } } //Check if a behavior is mixed $parts = KStringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { return false; } } return parent::__call($method, $args); }
/** * Supports a simple form Fluent Interfaces. Allows you to set states by * using the state name as the method name. * * For example : $model->sort('name')->limit(10)->getList(); * * @param string Method name * @param array Array containing all the arguments for the original call * @return KModelAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { if (isset($this->_state->{$method})) { return $this->set($method, $args[0]); } return parent::__call($method, $args); }
/** * Add a command by it's name * * @param string Method name * @param array Array containing all the arguments for the original call * @see addCommand() */ public function __call($method, $args) { $parts = KInflector::explode($method); if ($parts[0] == 'add' && isset($parts[1])) { $config = isset($args[0]) ? $args[0] : array(); $this->addCommand(strtolower($parts[1]), $config); return $this; } return parent::__call($method, $args); }
/** * Overloaded call function * * @param string $method The function name * @param array $arguments The function arguments * @return mixed The result of the function */ public function __call($method, array $arguments) { $object = $this->getObject(); if (method_exists($object, $method)) { $result = null; // Call_user_func_array is ~3 times slower than direct method calls. switch (count($arguments)) { case 0: $result = $object->{$method}(); break; case 1: $result = $object->{$method}($arguments[0]); break; case 2: $result = $object->{$method}($arguments[0], $arguments[1]); break; case 3: $result = $object->{$method}($arguments[0], $arguments[1], $arguments[2]); break; case 4: $result = $object->{$method}($arguments[0], $arguments[1], $arguments[2], $arguments[3]); break; default: // Resort to using call_user_func_array for many segments $result = call_user_func_array(array($object, $method), $arguments); } return $result; } return parent::__call($method, $arguments); }
/** * Execute a controller action by it's name. * * Function is also capable of checking is a behavior has been mixed succesfully * using is[Behavior] function. If the behavior exists the function will return * TRUE, otherwise FALSE. * * @param string Method name * @param array Array containing all the arguments for the original call * @see execute() */ public function __call($method, $args) { //Handle action alias method if(in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Create a context object if(!($data instanceof KCommandContext)) { $context = $this->getCommandContext(); $context->data = $data; $context->result = false; } else $context = $data; //Execute the action return $this->execute($method, $context); } //Check if a behavior is mixed $parts = KInflector::explode($method); if($parts[0] == 'is' && isset($parts[1])) { //Lazy mix behaviors $behavior = strtolower($parts[1]); if(!isset($this->_mixed_methods[$method])) { if($this->hasBehavior($behavior)) { $this->mixin($this->getBehavior($behavior)); return true; } return false; } return true; } return parent::__call($method, $args); }
/** * If the $method is one of the MySQL. * * @see KObject::__call() */ public function __call($method, $arguments) { if (isset($arguments[0]) && $this->_parent_query->getRepository()->getDescription()->getProperty($method)) { $condition = isset($arguments[1]) ? $arguments[1] : 'AND'; $this->where($method, '=', $arguments[0], $condition); return $this; } return parent::__call($method, $arguments); }
/** * Execute a controller action by it's name. * * @param string Method name * @param array Array containing all the arguments for the original call * @see execute() */ public function __call($method, $args) { if (in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Create a context object if (!$data instanceof KCommandContext) { $context = $this->getCommandContext(); $context->data = $data; $context->result = false; } else { $context = $data; } //Execute the action return $this->execute($method, $context); } return parent::__call($method, $args); }
/** * Overloaded call function * * @param string The function name * @param array The function arguments * @throws BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { $object = $this->getObject(); //Check if the method exists if ($object instanceof KObject) { $methods = $object->getMethods(); $exists = in_array($method, $methods); } else { $exists = method_exists($object, $method); } //Call the method if it exists if ($exists) { $result = null; // Call_user_func_array is ~3 times slower than direct method calls. switch (count($arguments)) { case 0: $result = $object->{$method}(); break; case 1: $result = $object->{$method}($arguments[0]); break; case 2: $result = $object->{$method}($arguments[0], $arguments[1]); break; case 3: $result = $object->{$method}($arguments[0], $arguments[1], $arguments[2]); break; default: // Resort to using call_user_func_array for many segments $result = call_user_func_array(array($object, $method), $arguments); } //Allow for method chaining through the decorator $class = get_class($object); if ($result instanceof $class) { return $this; } return $result; } return parent::__call($method, $arguments); }
/** * Search the behaviors to see if this table behaves as. * * Function is also capable of checking is a behavior has been mixed successfully using is[Behavior] function. * If the behavior exists the function will return TRUE, otherwise FALSE. * * @param string $method The function name * @param array $arguments The function arguments * @throws \BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { if (!isset($this->_mixed_methods[$method])) { // If the method is of the form is[Bahavior] handle it. $parts = KStringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { return false; } } return parent::__call($method, $arguments); }
/** * Search the behaviors to see if this table behaves as. * * Function is also capable of checking is a behavior has been mixed succesfully * using is[Behavior] function. If the behavior exists the function will return * TRUE, otherwise FALSE. * * @param string The function name * @param array The function arguments * @throws BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { // If the method is of the form is[Bahavior] handle it. $parts = KInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { if ($this->hasBehavior(strtolower($parts[1]))) { return true; } return false; } return parent::__call($method, $arguments); }
/** * Supports a simple form Fluent Interfaces. Allows you to set states by using the state name as the method name. * * For example : $model->sort('name')->limit(10)->fetch(); * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return KModelAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { if ($this->getState()->has($method)) { $this->getState()->set($method, $args[0]); return $this; } return parent::__call($method, $args); }
/** * Implements magic method. Dynamically mixes a mixin * * @param string $method Method name * @param array $args Array of arugments * * @return mixed */ public function __call($method, $args) { //If the method hasn't been mixed yet, load all the behaviors if (!isset($this->_mixed_methods[$method])) { $key = 'behavior.' . $method; if (!self::_cache($this)->offsetExists($key)) { self::_cache($this)->offsetSet($key, false); $behaviors = $this->getRepository()->getBehaviors(); foreach ($behaviors as $behavior) { if (in_array($method, $behavior->getMixableMethods())) { //only mix the mixin that has $method self::_cache($this)->offsetSet($key, $behavior); break; } } } if ($behavior = self::_cache($this)->offsetGet($key)) { $this->mixin($behavior); } } $parts = KInflector::explode($method); if ($parts[0] == 'is') { if (isset($this->_mixed_methods[$method])) { return true; } else { return false; } } if (!isset($this->_mixed_methods[$method])) { if ($parts[0] == 'get' || $parts[0] == 'set') { $property = lcfirst(KInflector::implode(array_slice($parts, 1))); $property = $this->getEntityDescription()->getProperty($property); if ($property) { if ($parts[0] == 'get') { return $this->getData($property->getName()); } else { return $this->setData($property->getName(), array_shift($args)); } } } } return parent::__call($method, $args); }
/** * Call template functions * * @param string $method The function name * @param array $arguments The function arguments * @throws \BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { if (isset($this->_functions[$method])) { $result = call_user_func_array($this->_functions[$method], $arguments); } else { $result = parent::__call($method, $arguments); } return $result; }
/** * Supports a simple form of Fluent Interfaces. Allows you to assign variables to the view * by using the variable name as the method name. If the method name is a setter method the * setter will be called instead. * * For example : $view->layout('foo')->title('name')->display(). * It also supports using name method setLayout($layout) which will be translated to set('layout', $layout) * * @param string Method name * @param array Array containing all the arguments for the original call * @return LibBaseViewAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { //If one argument is passed we assume a setter method is being called if (!isset($this->_mixed_methods[$method]) && count($args) == 1) { $this->set(KInflector::underscore($method), $args[0]); return $this; } return parent::__call($method, $args); }
public function __call($method, $args) { if (method_exists($this->_database, $method)) { return call_user_func_array(array($this->_database, $method), $args); } return parent::__call($method, $args); }