Extracts the call stack from the standard PHP backtrace (debug_backtrace).

@param array $btrace
The backtrace.

@return string
Returns the extracted call stack.

@author Oleg Schildt
767948
protected function extract_call_stack($btrace)
    {
        if (empty($btrace) || !is_array($btrace)) {
            return "";
        }
        
        $trace = "";
        
        $indent = "";
        foreach ($btrace as $btrace_entry) {
            
            
            if (!empty($btrace_entry["function"]) && ($btrace_entry["function"] == "handle_error" || strpos($btrace_entry["function"], "{closure}") !== false || $btrace_entry["function"] == "handleError" || $btrace_entry["function"] == "trigger_error")) {
                continue;
            }
            
            if (empty($btrace_entry["file"])) {
                continue;
            }
            
            if (!empty($btrace_entry["function"])) {
                $trace .= $indent . str_replace("SmartFactory\\", "", $btrace_entry["function"]) . "() ";
            }
            
            $trace .= "[";
            
            $trace .= str_replace($this->app_root, "", str_replace("\\", "/", $btrace_entry["file"]));
            
            $trace .= ", ";
            
            if (empty($btrace_entry["line"])) {
                $trace .= "line number undefined";
            } else {
                $trace .= $btrace_entry["line"];
            }
            
            $trace .= "]";
            
            $args = (isset($btrace_entry["args"])) ? $btrace_entry["args"] : [];
            $args_str = $this->make_arg_list($args);
            
            if (!empty($btrace_entry["function"]) && !empty($args_str)) {
                $trace .= "  " . str_replace("SmartFactory\\", "", $btrace_entry["function"]) . "(" . $args_str . ")";
            }
            
            $trace .= "\r\n";
            
            $indent .= "  ";
        }
        
        return trim($trace);
    }
1367324
def extract_stack(f=None, limit=None):
    
    if f is not None:
        raise RuntimeError("Timba.utils.extract_stack: f has to be None, don't ask why")
    # normally we can just use the traceback.extract_stack() function and
    # cut out the last frame (which is just ourselves). However, under psyco
    # this seems to return an empty list, so we use sys._getframe() instead
    lim = limit
    if lim is not None:
        lim += 1
    tb = traceback.extract_stack(None, lim)
    if tb:
        return tb[:-1];  # skip current frame
    # else presumably running under psyco
    return nonportable_extract_stack(f, limit)
155617
private function getStackTrace(MockObject $mock): array
    {
        $mockName = (new \ReflectionObject($mock))->getShortName();

        $trace = [];
        $enableTrace = false;
        foreach (debug_backtrace() as $i => $row) {
            if (isset($row['class']) && $mockName === $row['class']) {
                $enableTrace = true;
            }

            if ($enableTrace) {
                $traceRow = '';

                if (isset($row['class'])) {
                    $traceRow .= $row['class'];
                }

                if (isset($row['type'])) {
                    $traceRow .= $row['type'];
                }

                if (isset($row['function'])) {
                    $traceRow .= $row['function'];
                }

                if (isset($row['file'])) {
                    $traceRow .= sprintf(' (%s:%d)', $row['file'], $row['line']);
                }

                $trace[] = $traceRow;
            }
        }

        krsort($trace);

        return array_values($trace);
    }
1078287
public function getStackTrace()
    {
        if (!isset($this->message[4]) || empty($this->message[4])) {
            return null;
        }

        $traces = array_map(function ($trace) {
            return "in {$trace['file']}:{$trace['line']}";
        }, $this->message[4]);
        return implode("\n", $traces);
    }
486354
@JsonProperty("stack_trace")
	public String getStackTraceString() {
		if (_stackTrace != null)
			return _stackTrace;

		StackTraceElement[] ste = getStackTrace();
		StringBuilder builder = new StringBuilder();
		if (ste != null) {
			for (int i = 0; i < ste.length; i++) {
				if (builder.length() > 0)
					builder.append(" ");
				builder.append(ste[i].toString());
			}
		}
		return builder.toString();
	}
1181182
static public function getCaller()
    {
        $backtrace = debug_backtrace();
        array_shift($backtrace);
        $current = array_shift($backtrace);
        $caller = isset($backtrace[0]) ? $backtrace[0] : $current;
        if (!isset($caller['class']))  $caller['class'] = null;
        if (!isset($caller['object'])) $caller['object'] = null;
        return $caller;
    }
992103
public static function traceBegin()
    {
        $dbg = debug_backtrace();
        $str = '=> ';
        if (!empty ($dbg[1]['class'])) {
            $str .= $dbg[1]['class'] . '::';
        }
        $str .= $dbg[1]['function'] . '(';
        if (is_array($dbg[1]['args'])) {
            foreach ($dbg[1]['args'] as $index => $arg) {
                if ($index != 0) {
                    $str .= ', ';
                }
                if (is_object($arg)) {
                    $str .= get_class($arg);
                } else {
                    $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
                }
            }
        }
        if (isset($dbg[1]['file'])) {
            $file = basename($dbg[1]['file']);
        } else {
            $file = 'unknown_file';
        }
        if (isset($dbg[1]['line'])) {
            $line = $dbg[1]['line'];
        } else {
            $line = 'unknown_line';
        }
        $str .= ') [' . $file . ':' . $line . ']';
        phpCAS :: log($str);
        if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
            self::$_PHPCAS_DEBUG['indent'] = 0;
        } else {
            self::$_PHPCAS_DEBUG['indent']++;
        }
    }
274557
private static function getStackCalls() {

        $i = 1;
        $result = [];
        foreach(xdebug_get_function_stack() as $node) {
            if(isset($node['line']) === true) {
                $result[] = "$i. ".basename($node['file']) .":" .$node['function'] ."(" .$node['line'].")";
            }
            $i++;
        }
        return $result;
    }
520400
public static function toStackTrace($ex)
    {
        $list = [];
        for ($stack = Throwable::getThrowableStack($ex); $stack !== null; $stack = $stack['prev'])
        {
            $list = array_merge($stack['trace'], $list);
        }

        return $list;
    }
665206
protected function getCallerFromStackTrace()
    {
        $trace = collect(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))->forget(0);

        return $trace->first(function ($frame) {
            if (! isset($frame['file'])) {
                return false;
            }

            return ! Str::contains($frame['file'],
                base_path('vendor'.DIRECTORY_SEPARATOR.$this->ignoredVendorPath())
            );
        });
    }
763008
private function getTrace()
    {
        $trace = array();

        if (PHP_VERSION_ID >= 50400) {
            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
        } else if (PHP_VERSION_ID >= 50306) {
            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        } else {
            $trace = debug_backtrace();
        }
        if (empty($trace)) {
            return '';
        }
        array_shift($trace); // ignore $this->getTrace();
        array_shift($trace); // ignore $this->process()
        $i = 0;
        $returnArray = array();
        while (isset($trace[$i]['class']) && false === strpos($trace[$i]['class'], 'Zend\\Log')
            && false === strpos($trace[$i]['class'], 'DhErrorLogging')) {
            $i++;
            $returnArray[] = array(
                'file'     => isset($trace[$i]['file'])   ? $trace[$i]['file']   : null,
                'line'     => isset($trace[$i]['line'])   ? $trace[$i]['line']   : null,
                'class'    => isset($trace[$i]['class'])    ? $trace[$i]['class']    : null,
                'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
            );
        }

        return $returnArray;
    }
106209
public static function trace(array $stack) {
		$result = [];

		foreach ($stack as $frame) {
			if (isset($frame['function'])) {
				if (isset($frame['class'])) {
					$result[] = trim($frame['class'], '\\') . '::' . $frame['function'];
				} else {
					$result[] = $frame['function'];
				}
			}
		}
		return $result;
	}
1251073
protected function getCalleeClass()
    {

        if (PHP_VERSION_ID < 50205)
            $backtrace = debug_backtrace();
        else
            $backtrace = debug_backtrace(false);

        foreach ( $backtrace as $bt ) {
            // Making sure the class we're getting out of the backtrace is not a logger
            if (!is_a($this, $bt['class']) && strpos($bt['class'], 'Logger') === false) {
                return $bt['class'];
            }
        }

        return '';
    }
1182080
public function getTraceAsString()
    {
        $remove = "Stack trace:\n";
        $len = strpos($this->_toString, $remove);
        if ($len === false) {
            return '';
        }
        return substr($this->_toString, $len + strlen($remove));
    }
783557
protected function getBacktrace()
    {
        // Remove the fist step from the backtrace,
        // because that is the internal function in kreXX.
        $backtrace = debug_backtrace();

        // We remove all steps that came from inside the kreXX lib.
        $krexxScr = KREXX_DIR . 'src';
        foreach ($backtrace as $key => $step) {
            if (isset($step[static::TRACE_FILE]) && strpos($step[static::TRACE_FILE], $krexxScr) !== false) {
                unset($backtrace[$key]);
            } else {
                // No need to ga wurther, because we should have passed the
                // kreXX part.
                break;
            }
        }

        // Reset the array keys, because the 0 is now missing.
        return array_values($backtrace);
    }
265350
private function getStackTraceToString($stack) {
        $max = 0;
        $trace = '';

        for ($i = 3; $i < count($stack) && $max < 4; $i++) {
            if (isset($stack[$i]['file']) && preg_match('#(' . preg_quote('System\Orm') . ')#isU', $stack[$i]['file'])) { //ORM
                $trace .= str_replace('\\', '-', $stack[$i]['class']) . '_' . $stack[$i]['function'] . '_' . $stack[$i - 1]['line'] . '__';
            }
        }

        return $trace;
    }
6513
public static function getReport(array $backtrace) {
		$r = '';

		if(static::$format === 'html') {
			$request = \Asgard\Http\Request::singleton();
			$r .= static::getHTMLBacktrace($request, $backtrace);
			$r .= static::getHTMLRequest($request);
		}
		else
			$r .= static::getCLIBacktrace($backtrace);

		return $r;
	}