public static function patched($namespace, $ref, $isFunc = true, &$substitute = null)
{
$name = $ref;
if ($namespace) {
if (!$isFunc || function_exists("{$namespace}\\{$ref}")) {
$name = "{$namespace}\\{$ref}";
}
}
$method = isset(static::$_registered[$name]) ? static::$_registered[$name] : null;
$fake = $method ? $method->substitute() : null;
if (!$isFunc) {
if (is_object($fake)) {
$substitute = $fake;
}
return $fake ?: $name;
}
if (!Suite::registered($name) && !$method) {
return $name;
}
return function () use($name, $method) {
$args = func_get_args();
if (Suite::registered($name)) {
Calls::log(null, compact('name', 'args'));
}
if ($method && $method->matchArgs($args)) {
return $method($args);
}
return call_user_func_array($name, $args);
};
}