本文整理汇总了PHP中ReflectionFunction::invokeArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::invokeArgs方法的具体用法?PHP ReflectionFunction::invokeArgs怎么用?PHP ReflectionFunction::invokeArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::invokeArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* (non-PHPdoc)
* @see \PHPFluent\EventManager\Listener::execute()
*/
public function execute(Event $event, array $context = array())
{
$arguments = array($event, $context);
$parameters = $this->reflection->getParameters();
$firstParameter = array_shift($parameters);
if ($firstParameter instanceof \ReflectionParameter && $firstParameter->isArray()) {
$arguments = array_reverse($arguments);
}
return $this->reflection->invokeArgs($arguments);
}
示例2: getResponse
public function getResponse($method, $uri)
{
foreach ($this->routes as $route) {
if ($match = $route($method, $uri)) {
if (is_callable($match[0])) {
if (empty($match[1])) {
return $match[0]();
}
// http://www.creapptives.com/post/26272336268/calling-php-functions-with-named-parameters
$ref = new \ReflectionFunction($match[0]);
$this->params = [];
foreach ($ref->getParameters() as $p) {
if (!$p->isOptional() and !isset($match[1][$p->name])) {
throw new \Exception("Missing parameter {$p->name}");
}
if (!isset($match[1][$p->name])) {
$this->params[$p->name] = $p->getDefaultValue();
} else {
$this->params[$p->name] = $match[1][$p->name];
}
}
return $ref->invokeArgs($this->params);
}
return $match[0];
}
}
throw new \Exception($method . ':' . $uri . ' not found');
}
示例3: array
function exec_function_array($o, array $B = array())
{
switch (count($B)) {
case 0:
return $o();
case 1:
return $o($B[0]);
case 2:
return $o($B[0], $B[1]);
case 3:
return $o($B[0], $B[1], $B[2]);
case 4:
return $o($B[0], $B[1], $B[2], $B[3]);
case 5:
return $o($B[0], $B[1], $B[2], $B[3], $B[4]);
default:
if (is_object($o)) {
$v = new ReflectionMethod($o, '__invoke');
return $v->invokeArgs($o, $B);
} else {
if (is_callable($o)) {
$v = new ReflectionFunction($o);
return $v->invokeArgs($B);
}
}
}
}
示例4: runMiddlewares
/**
* Runs all the middlewares of given type.
*/
public static function runMiddlewares($type = self::BEFORE_REQUEST)
{
$apricot = static::getInstance();
$middlewares = $apricot->middlewares;
/** @var \Exception */
$error = null;
foreach ($middlewares as $key => $middleware) {
$hasNextMiddleware = array_key_exists($key + 1, $middlewares);
if ($type !== $middleware['type']) {
continue;
}
$r = new \ReflectionFunction($middleware['callback']);
$parameters = $r->getParameters();
$next = $hasNextMiddleware ? $middlewares[$key + 1] : function () {
};
try {
$r->invokeArgs(array($error, $next));
} catch (\Exception $e) {
// If there is no more middleware to run, throw the exception.
if (!$hasNextMiddleware) {
throw $e;
}
$error = $e;
}
}
}
示例5: exec
public function exec($key)
{
//匿名函数
if ($this->route[$key]['callback'] instanceof Closure) {
//反射分析闭包
$reflectionFunction = new \ReflectionFunction($this->route[$key]['callback']);
$gets = $this->route[$key]['get'];
$args = [];
foreach ($reflectionFunction->getParameters() as $k => $p) {
if (isset($gets[$p->name])) {
//如果GET变量中存在则将GET变量值赋予,也就是说GET优先级高
$args[$p->name] = $gets[$p->name];
} else {
//如果类型为类时分析类
if ($dependency = $p->getClass()) {
$args[$p->name] = App::build($dependency->name);
} else {
//普通参数时获取默认值
$args[$p->name] = App::resolveNonClass($p);
}
}
}
echo $reflectionFunction->invokeArgs($args);
} else {
//设置控制器与方法
Request::set('get.' . c('http.url_var'), $this->route[$key]['callback']);
Controller::run($this->route[$key]['get']);
}
}
示例6: invoke
/**
*
* @param array $arguments
*
* @return mixed
*/
public function invoke($arguments = array())
{
if ($this->isMethod) {
return $this->reflection->invokeArgs($this->thisObject, $arguments);
}
return $this->reflection->invokeArgs($arguments);
}
示例7: pack
/**
* Packs 8-bit integers into a binary string
*
* @since 1.0
*
* @param int $ascii,... 8-bit unsigned integer
* @return binary
*/
public static function pack($ascii)
{
$packer = new \ReflectionFunction('pack');
$args = func_get_args();
array_unshift($args, 'C*');
return $packer->invokeArgs($args);
}
示例8: call
/**
* @param \Closure $closure
* @return mixed
*/
public function call($closure)
{
$reflect = new \ReflectionFunction($closure);
$parameters = $reflect->getParameters();
$dependencies = $this->getDependencies($parameters);
return $reflect->invokeArgs($dependencies);
}
示例9: XLLoop_reflection_handler
function XLLoop_reflection_handler()
{
try {
$input = file_get_contents('php://input');
$value = json_decode($input);
if ($value != NULL) {
$argc = count($value->args);
$args = array();
for ($i = 0; $i < $argc; $i++) {
$args[$i] = XLLoop_decode($value->args[$i]);
}
$function = new ReflectionFunction($value->name);
if ($function->isUserDefined()) {
$reqArgc = $function->getNumberOfParameters();
for ($i = $argc; $i < $reqArgc; $i++) {
$args[$i] = 0;
}
$result = $function->invokeArgs($args);
$enc = XLLoop_encode($result);
print json_encode($enc);
} else {
print json_encode(XLLoop_encode("#Function " . $value->name . "() does not exist"));
}
} else {
print "<html><body><code>XLLoop function handler alive</code></body></html>";
}
} catch (Exception $e) {
print json_encode(XLLoop_encode("#" . $e->getMessage()));
}
}
示例10: testCheckAPI
/**
* Asserts that a function is implemented and returns the expected result
*
* @param String $function The function name
* @param Array $params The parameters
* @param Mixed $result The expected result
*
* @dataProvider provideTestCheckAPI
* @return void
*/
public function testCheckAPI($function, array $params, $result)
{
$api = new OldPHPAPI_Test();
$api->checkAPI();
$this->assertTrue(function_exists($function), "Function {$function} is not defined.");
$reflection = new ReflectionFunction($function);
$this->assertEquals($result, $reflection->invokeArgs($params));
}
示例11: callFunction
public function callFunction($function)
{
/** @var \ReflectionFunction $reflectionFunction */
$reflectionFunction = new \ReflectionFunction($function);
$signatureParams = $reflectionFunction->getParameters();
$calledFunctionArgs = $this->resolveParams($signatureParams);
$reflectionFunction->invokeArgs($calledFunctionArgs);
}
示例12: execute
/**
* @param $method
* @param array $args
* @param bool $singleton
* @return mixed
* @throws \Exception
*/
public function execute($method, array $args = array(), $singleton = true)
{
if (is_array($method) && count($method) >= 2) {
list($class, $name) = $method;
$reflection = new \ReflectionMethod($class, $name);
} elseif (is_callable($method)) {
$reflection = new \ReflectionFunction($method);
} else {
throw new \RuntimeException();
}
$parameters = $reflection->getParameters();
$args = $this->getReflectionValues($parameters, $args, $singleton);
if ($reflection instanceof \ReflectionFunction) {
return $reflection->invokeArgs($args);
} else {
return $reflection->invokeArgs($class, $args);
}
}
示例13: prepareArgs
private function prepareArgs($sql, $arguments = null)
{
if ($arguments != null && count($arguments) > 0) {
$sprintfargs = array_merge(array($sql), $arguments);
$sprintf = new \ReflectionFunction('sprintf');
$sql = $sprintf->invokeArgs($sprintfargs);
}
return $sql;
}
示例14: invoke_function
/**
*
* @param string $callback
* @param array $params
* @return mixed
*/
public static function invoke_function($callback, array $params = NULL)
{
$class = new ReflectionFunction($callback);
if (empty($params)) {
return $class->invoke();
} else {
return $class->invokeArgs($params);
}
}
示例15: processController
/**
* Execute the active controller
*/
public function processController()
{
// closure
if (is_callable($this->controller)) {
$func = new \ReflectionFunction($this->controller);
return $func->invokeArgs($this->controller_args);
} else {
return Controller::execute($this->controller, $this->controller_args);
}
}