15declare(strict_types=1);
17namespace raklib\utils;
19use
function array_reverse;
21use
function function_exists;
22use
function get_class;
24use
function is_object;
25use
function method_exists;
26use
function str_replace;
29use
function xdebug_get_function_stack;
32 public function __construct(
33 private string $mainPath
41 public function getTrace(
int $start = 0, ?array $trace =
null) : array{
43 if(function_exists(
"xdebug_get_function_stack") && count($trace = @xdebug_get_function_stack()) !== 0){
44 $trace = array_reverse($trace);
46 $e = new \Exception();
47 $trace = $e->getTrace();
53 for($i = $start; isset($trace[$i]); ++$i, ++$j){
55 if(isset($trace[$i][
"args"]) or isset($trace[$i][
"params"])){
56 if(isset($trace[$i][
"args"])){
57 $args = $trace[$i][
"args"];
59 $args = $trace[$i][
"params"];
61 foreach($args as $name => $value){
62 $params .= (is_object($value) ? get_class($value) .
" " . (method_exists($value,
"__toString") ? $value->__toString() :
"object") : gettype($value) .
" " . @strval($value)) .
", ";
65 $messages[] =
"#$j " . (isset($trace[$i][
"file"]) ? $this->cleanPath($trace[$i][
"file"]) :
"") .
"(" . (isset($trace[$i][
"line"]) ? $trace[$i][
"line"] :
"") .
"): " . (isset($trace[$i][
"class"]) ? $trace[$i][
"class"] . (($trace[$i][
"type"] ===
"dynamic" or $trace[$i][
"type"] ===
"->") ?
"->" :
"::") :
"") . $trace[$i][
"function"] .
"(" . substr($params, 0, -2) .
")";
71 public function cleanPath(
string $path) : string{
72 return str_replace([
"\\",
".php",
"phar://", str_replace([
"\\",
"phar://"], [
"/",
""], $this->mainPath)], [
"/",
"",
"",
""], $path);
getTrace(int $start=0, ?array $trace=null)