mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-27 10:53:48 +01:00
Improve format_callable()
This commit is contained in:
parent
0e8009420c
commit
9f2cbeca6f
1 changed files with 36 additions and 11 deletions
|
@ -746,20 +746,45 @@ function dumpFile($file_path, $mime_type=null, $max_age=3600, $force_download=fa
|
|||
|
||||
/**
|
||||
* Format a callable object for logging
|
||||
* @param callable $callable The callable object
|
||||
* @param string|array|\ReflectionMethod|\ReflectionFunction $callable The callable object
|
||||
* @param null|array<int,mixed> $args Optional argument(s)
|
||||
* @return string The callable object string representation
|
||||
*/
|
||||
function format_callable($callable) {
|
||||
function format_callable($callable, $args=null) {
|
||||
$formatted_args = format_callable_args($args);
|
||||
if (is_string($callable))
|
||||
return $callable."()";
|
||||
if (is_array($callable) && count($callable)==2)
|
||||
if (is_string($callable[0]))
|
||||
return $callable[0]."::".$callable[1]."()";
|
||||
elseif (is_object($callable[0]))
|
||||
return get_class($callable[0])."->".$callable[1]."()";
|
||||
else
|
||||
return "Unkown->".$callable[1]."()";
|
||||
return varDump($callable);
|
||||
return $callable."($formatted_args)";
|
||||
if (is_array($callable))
|
||||
if (is_string($callable[0]))
|
||||
return $callable[0]."::".$callable[1]."($formatted_args)";
|
||||
elseif (is_object($callable[0]))
|
||||
return get_class($callable[0])."->".$callable[1]."($formatted_args)";
|
||||
else
|
||||
return "Unknown->".$callable[1]."($formatted_args)";
|
||||
if ($callable instanceof \ReflectionFunction)
|
||||
return sprintf("%s(%s)", $callable->name, $formatted_args);
|
||||
if ($callable instanceof \ReflectionMethod)
|
||||
return sprintf(
|
||||
"%s::%s(%s)",
|
||||
$callable->class,
|
||||
$callable->name,
|
||||
$formatted_args
|
||||
);
|
||||
return sprintf("%s(%s)", varDump($callable), $formatted_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format callable arguments for logging
|
||||
* @param array<mixed> $args Arguments
|
||||
* @return string
|
||||
*/
|
||||
function format_callable_args($args) {
|
||||
if (!is_array($args) || empty($args))
|
||||
return "";
|
||||
$formatted_args = [];
|
||||
foreach($args as $arg)
|
||||
$formatted_args[] = str_replace("\n", '\n', var_export($arg, true));
|
||||
return implode(", ", $formatted_args);
|
||||
}
|
||||
|
||||
function is_empty($val) {
|
||||
|
|
Loading…
Reference in a new issue