本文整理汇总了PHP中KObject::__call方法的典型用法代码示例。如果您正苦于以下问题:PHP KObject::__call方法的具体用法?PHP KObject::__call怎么用?PHP KObject::__call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KObject
的用法示例。
在下文中一共展示了KObject::__call方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* 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);
}
示例2: __call
/**
* 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);
}
示例3: __call
/**
* 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);
}
示例4: __call
/**
* 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);
}
示例5: __call
/**
* 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);
}
示例6: __call
/**
* 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);
}
示例7: __call
/**
* 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);
}
示例8: __call
/**
* 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);
}
示例9: __call
/**
* 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);
}
示例10: __call
/**
* 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);
}
示例11: __call
/**
* 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);
}
示例12: __call
/**
* 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);
}
示例13: __call
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);
}