forked from fuel/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base56.php
57 lines (49 loc) · 1.37 KB
/
base56.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Fuel is a fast, lightweight, community driven PHP 5.4+ framework.
*
* @package Fuel
* @version 1.9-dev
* @author Fuel Development Team
* @license MIT License
* @copyright 2010 - 2019 Fuel Development Team
* @link https://fuelphp.com
*/
/**
* Faster equivalent of call_user_func_array using variadics
*/
if ( ! function_exists('call_fuel_func_array'))
{
function call_fuel_func_array($callback, array $args)
{
// deal with "class::method" syntax
if (is_string($callback) and strpos($callback, '::') !== false)
{
$callback = explode('::', $callback);
}
// dynamic call on an object?
if (is_array($callback) and isset($callback[1]) and is_object($callback[0]))
{
// make sure our arguments array is indexed
if ($count = count($args))
{
$args = array_values($args);
}
list($instance, $method) = $callback;
return $instance->{$method}(...$args);
}
// static call?
elseif (is_array($callback) and isset($callback[1]) and is_string($callback[0]))
{
list($class, $method) = $callback;
$class = '\\'.ltrim($class, '\\');
return $class::{$method}(...$args);
}
// if it's a string, it's a native function or a static method call
elseif (is_string($callback) or $callback instanceOf \Closure)
{
is_string($callback) and $callback = ltrim($callback, '\\');
}
return $callback(...$args);
}
}