本文整理汇总了PHP中call_user_func_array函数的典型用法代码示例。如果您正苦于以下问题:PHP call_user_func_array函数的具体用法?PHP call_user_func_array怎么用?PHP call_user_func_array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_user_func_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate($rules, $obj)
{
$fail = array();
//print_r($rules); print_r($obj);
foreach ($rules as $k => $v) {
$m = explode('|', $v);
//print_r($m);
//echo $v.' '.$k.' '.$obj->$k."\n";
foreach ($m as $mk => $mv) {
//$str=(string)$obj->$k;
//chek to see if we're anything more complex
if (preg_match('/\\[(.*?)\\]/', $mv, $matches)) {
//print_r($matches);
$par = array_merge(array($k, $obj), explode(',', $matches[1]));
$func = str_replace($matches[0], '', $mv);
$ret = call_user_func_array(array(&$this, 'validate_' . $func), $par);
} else {
$ret = $this->{'validate_' . $mv}($k, $obj);
}
if (!$ret) {
if ($msg = $this->getCustErr($k)) {
$fail[] = $msg;
} else {
$fail[] = sprintf($this->default_err, $k);
}
}
}
}
return count($fail) > 0 ? $fail : false;
}
示例2: __call
/**
*
*/
public function __call($method, $params)
{
if (!method_exists($this->repository, $method)) {
throw new RepositoryException("Method {$method} not found on repository");
}
if ($this->skipCache === true || config('laravel-database.cache') === false) {
return call_user_func_array(array($this->repository, $method), $params);
} else {
if (empty($this->key)) {
$this->cacheKey($this->generateKey($method, $params));
}
$key = $this->key;
unset($this->key);
if ($this->refreshCache) {
$this->cache->forget($key);
$this->refreshCache = false;
}
if (empty($this->lifetime)) {
$this->cacheLifetime($this->repository->getModel()->cacheLifetime());
}
$lifetime = $this->lifetime;
unset($this->lifetime);
return $this->cache->remember($key, $lifetime, function () use($method, $params) {
return call_user_func_array(array($this->repository, $method), $params);
});
}
}
示例3: __construct
public function __construct($statement)
{
$this->error = $statement->error;
$this->field_count = $statement->field_count;
$this->insert_id = $statement->insert_id;
$this->num_rows = $statement->num_rows;
if ($this->field_count == 1) {
$statement->bind_result($res);
while ($statement->fetch) {
$this->result = $res;
break;
}
$this->array = array();
} else {
$data = $statement->result_metadata();
$rows = array();
$fields = array($statement);
while ($f = $data->fetch_field()) {
$fields[] =& $rows[$f->name];
}
call_user_func_array('mysqli_stmt_bind_result', $fields);
$statement->fetch();
$this->array = array();
foreach ($rows as $key => $value) {
$this->array[$key] = $value;
}
$this->result = '';
}
}
示例4: addCommandsFromClass
public function addCommandsFromClass($className, $passThrough = null)
{
$roboTasks = new $className();
$commandNames = array_filter(get_class_methods($className), function ($m) {
return !in_array($m, ['__construct']);
});
foreach ($commandNames as $commandName) {
$command = $this->createCommand(new TaskInfo($className, $commandName));
$command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) {
// get passthru args
$args = $input->getArguments();
array_shift($args);
if ($passThrough) {
$args[key(array_slice($args, -1, 1, TRUE))] = $passThrough;
}
$args[] = $input->getOptions();
$res = call_user_func_array([$roboTasks, $commandName], $args);
if (is_int($res)) {
exit($res);
}
if (is_bool($res)) {
exit($res ? 0 : 1);
}
if ($res instanceof Result) {
exit($res->getExitCode());
}
});
$this->add($command);
}
}
示例5: getPrefixes
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
示例6: SendMessage
public function SendMessage($To, $Key, $Pre = null)
{
$Args = func_get_args();
array_shift($Args);
$Message = call_user_func_array(array(new Lang($this->LangSection), 'Get'), $Args);
if ($Message !== false) {
return $this->SendRawMessage($To, (is_array($Pre) && !empty($Pre[0]) ? $Pre[0] : null) . $Message);
} else {
if ($Key === 'message:module::not_loaded') {
return $this->SendRawMessage($To, 'That module doesn\'t exists. Try !help to see a list of available modules');
} elseif ($Key === 'message:not_admin') {
return $this->SendRawMessage($To, 'You need admin rights in order to do that');
} elseif ($Key === 'message:module::not_enabled') {
return $this->SendRawMessage($To, 'That module is loaded, but is disabled. Ask the admin about it');
} elseif ($Key === 'message:internal_error') {
return $this->SendRawMessage($To, 'Internal error');
} elseif ($Key === 'message:internal_error:wrong_response_code') {
return $this->SendRawMessage($To, 'Internal error. The code (' . var_export($Pre, true) . ') returned by the module is wrong');
} elseif ($Key === 'message:module::load_error') {
return $this->SendRawMessage($To, 'That module is loaded, but there are some troubles (at reload, json-php not readable/lint). If you are the admin, see the logs!');
} else {
array_shift($Args);
return $this->SendLangError($To, $Key, $Args);
}
}
}
示例7: getSingleton
public function getSingleton()
{
if (!isset($this->instance)) {
$this->instance = call_user_func_array([$this, 'getInstance'], func_get_args());
}
return $this->instance;
}
示例8: __construct
/**
* @todo Pass around Messages when Status class doesn't suck
* @param array $msg Message key with parameters
*/
public function __construct(array $msg)
{
$this->msg = $msg;
// Using ->plain() instead of ->text() due to bug T58226
$wikitext = call_user_func_array('wfMessage', $msg)->plain();
parent::__construct($wikitext);
}
示例9: __callStatic
public static function __callStatic($method, $args)
{
if (!isset(self::$i)) {
self::$i = new Query();
}
return call_user_func_array([self::$i, $method], $args);
}
示例10: process
/**
* Applies operation to data source and returns modified data source.
*
* @param $src
* @param OperationInterface|CustomOperation $operation
* @return mixed modified data source
*/
public function process($src, OperationInterface $operation)
{
$callable = $operation->getCallback();
$arguments = array_merge([$src], $operation->getArguments());
$res = call_user_func_array($callable, $arguments);
return $res ?: $src;
}
示例11: __call
/** @proxy */
public function __call($method, $arguments)
{
if (method_exists($this->mongo, $method)) {
return call_user_func_array(array($this->mongo, $method), $arguments);
}
throw new \BadMethodCallException(sprintf('Method %s does not exist on %s', $method, get_class($this)));
}
示例12: action_execute
/**
* Handles the request to execute a task.
*
* Responsible for parsing the tasks to execute & also any config items that
* should be passed to the tasks
*/
public function action_execute()
{
if (empty($this->_task)) {
return $this->action_help();
}
$task = $this->_retrieve_task();
$defaults = $task->get_config_options();
if (!empty($defaults)) {
if (Arr::is_assoc($defaults)) {
$options = array_keys($defaults);
$options = call_user_func_array(array('CLI', 'options'), $options);
$config = Arr::merge($defaults, $options);
} else {
// Old behavior
$config = call_user_func_array(array('CLI', 'options'), $defaults);
}
} else {
$config = array();
}
// Validate $config
$validation = Validation::factory($config);
$validation = $task->build_validation($validation);
if (!$validation->check()) {
echo View::factory('minion/error/validation')->set('errors', $validation->errors($task->get_errors_file()));
} else {
// Finally, run the task
echo $task->execute($config);
}
}
示例13: __call
public function __call($func, array $args = [])
{
if ($this->lazyLoad() == null) {
return '';
}
return call_user_func_array([$this->lazyLoad(), $func], $args);
}
示例14: handleRaw
/**
* @internal
*
* @param Oxygen_Http_Request $request
* @param Oxygen_Util_RequestData $requestData
* @param string $className
* @param string $method
* @param array $actionParameters
*
* @return Oxygen_Http_Response
* @throws Oxygen_Exception
*/
public function handleRaw($request, $requestData, $className, $method, array $actionParameters)
{
$reflectionMethod = new ReflectionMethod($className, $method);
$parameters = $reflectionMethod->getParameters();
$arguments = array();
foreach ($parameters as $parameter) {
if (isset($actionParameters[$parameter->getName()])) {
$arguments[] = $actionParameters[$parameter->getName()];
} else {
if (!$parameter->isOptional()) {
throw new Oxygen_Exception(Oxygen_Exception::ACTION_ARGUMENT_NOT_PROVIDED);
}
$arguments[] = $parameter->getDefaultValue();
}
}
if (is_subclass_of($className, 'Oxygen_Container_ServiceLocatorAware')) {
$instance = call_user_func(array($className, 'createFromContainer'), $this->container);
} else {
$instance = new $className();
}
$result = call_user_func_array(array($instance, $method), $arguments);
if (is_array($result)) {
$result = $this->convertResultToResponse($request, $requestData, $result);
} elseif (!$result instanceof Oxygen_Http_Response) {
throw new LogicException(sprintf('An action should return array or an instance of Oxygen_Http_Response; %s gotten.', gettype($result)));
}
return $result;
}
示例15: getClass
/**
* @param string $class_name
*/
protected function getClass($class_name, $subclass_of = 'Cyan\\Framework\\Controller', array $arguments = [], \Closure $newInstance = null)
{
$required_traits = ['Cyan\\Framework\\TraitSingleton'];
$reflection_class = new ReflectionClass($class_name);
foreach ($required_traits as $required_trait) {
if (!in_array($required_trait, $reflection_class->getTraitNames())) {
throw new TraitException(sprintf('%s class must use %s', $class_name, $required_trait));
}
}
if (!is_subclass_of($class_name, $subclass_of)) {
throw new TraitException(sprintf('%s class must be a instance of %s', $class_name, $subclass_of));
}
if (is_callable($newInstance)) {
$instance = call_user_func_array($newInstance, $arguments);
} else {
$instance = !empty($arguments) ? call_user_func_array([$class_name, 'getInstance'], $arguments) : $class_name::getInstance();
}
if ($this->hasContainer('application')) {
if (!$instance->hasContainer('application')) {
$instance->setContainer('application', $this->getContainer('application'));
}
if (!$instance->hasContainer('factory_plugin')) {
$instance->setContainer('factory_plugin', $this->getContainer('application')->getContainer('factory_plugin'));
}
}
if (is_callable([$instance, 'initialize']) || method_exists($instance, 'initialize')) {
$instance->initialize();
}
return $instance;
}