Find the Leo entry point call in a stack trace.

@param array $trace The stack trace.

@return array|null The call, or null if unable to determine the entry point.
555270
public static function traceLeoCall(array $trace)
    {
        for ($i = count($trace) - 1; $i >= 0; --$i) {
            if (self::isLeoTraceEntry($trace[$i])) {
                return $trace[$i];
            }
        }

        return null;
    }
299546
public function trace(string $operation): int
    {
        $this->buffTrace[] = [
            'operation' => $operation, 
            'time'      => microtime(true), 
            'result'    => '', 
            'stack'     => 9 == self::C_DEBUG_LEVEL ? debug_backtrace(): null, 
        ];
        return count($this->buffTrace) - 1;
    }
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;
	}
1257000
function trace(array $trace=NULL,$format=TRUE) {
		if (!$trace) {
			$trace=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
			$frame=$trace[0];
			if (isset($frame['file']) && $frame['file']==__FILE__)
				array_shift($trace);
		}
		$debug=$this->hive['DEBUG'];
		$trace=array_filter(
			$trace,
			function($frame) use($debug) {
				return isset($frame['file']) &&
					($debug>1 ||
					($frame['file']!=__FILE__ || $debug) &&
					(empty($frame['function']) ||
					!preg_match('/^(?:(?:trigger|user)_error|'.
						'__call|call_user_func)/',$frame['function'])));
			}
		);
		if (!$format)
			return $trace;
		$out='';
		$eol="\n";
		// Analyze stack trace
		foreach ($trace as $frame) {
			$line='';
			if (isset($frame['class']))
				$line.=$frame['class'].$frame['type'];
			if (isset($frame['function']))
				$line.=$frame['function'].'('.
					($debug>2 && isset($frame['args'])?
						$this->csv($frame['args']):'').')';
			$src=$this->fixslashes(str_replace($_SERVER['DOCUMENT_ROOT'].
				'/','',$frame['file'])).':'.$frame['line'];
			$out.='['.$src.'] '.$line.$eol;
		}
		return $out;
	}
898724
private function renderTrace($trace)
    {
        foreach ($trace as $i => $entry) {
            $s = '';
            if (!empty($entry['file'])) {
                $s .= $this->stripFile($entry['file']);
                if (!empty($entry['line'])) {
                    $s .= ' (line ' . $entry['line'] . ')';
                }
            }
            if (!empty($entry['function'])) {
                $class = !empty($entry['class']) ? $entry['class'] . $entry['type'] : '';
                $args  = !empty($entry['args']) ? $this->dumpArgs($entry['args']) : '' ;
                $s .= ':<br/>&nbsp;&nbsp;&nbsp;' . $class . $entry['function'] . '(' . $args . ')';
            }
            $trace[$i] = '<li>' . $s . '</li>';
        }

        return '<code><ul>' . implode('<br/>', $trace) . '</ul></code>';
    }
757065
final public function addTrace($trace) {
    Helpers::checkType('trace', 'string', $trace);
    array_splice($this->trace, 0, 0, [$trace]);
    return $this;
  }
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;
    }
609012
private static function whereCall($call, $helper)
    {
        $tracer = new Trace();

        foreach ($tracer->getChronology() as $trace) {
            if ($trace->call === $helper) {
                return $trace;
                break;
            } elseif ($trace->call === $call) {
                return $trace;
                break;
            }
        }
    }
397347
private static function resolveLogCaller(array &$context) {
        if (!key_exists('trace', $context))
            self::generateStackTrace($context);
        $trace = $context['trace'];

        $context['class'] = isset($trace[0]['class']) ? $trace[0]['class'] : '';
    }
1204356
private function findTraced($className = null)
    {
        $traces     = debug_backtrace();
        $reflection = new ReflectionClass($className);
        $filename   = $reflection->getFileName();
        $traced     = null;


        foreach ($traces as $trace) {
            if (isset($trace['file']) and $filename == $trace['file']) {
                $traced = $trace;
                break;
            }
        }
        return $traced;
    }
255255
public function getBetterTrace() {
        $trace = $this->betterTrace;

        if (!$trace) {
            // transform the original stacktrace into a better one
            $trace = DebugHelper::fixTrace($this->getTrace(), $this->getFile(), $this->getLine());

            // drop the first frame if the exception was created in the registered error handler
            if (DebugHelper::getFQFunctionName($trace[0]) == ErrorHandler::class.'::handleError') {
                \array_shift($trace);

                // if the error was triggered by include/require/_once: fix the next frame, it's wrong
                if (sizeof($trace) > 1) {
                    $function = DebugHelper::getFQFunctionName($trace[0]);
                    if ($function=='include' || $function=='include_once' || $function=='require' || $function=='require_once') {
                        if (isset($trace[0]['file']) && isset($trace[1]['file'])) {
                            if ($trace[0]['file'] == $trace[1]['file']) {
                                if (isset($trace[0]['line']) && isset($trace[1]['line'])) {
                                    if ($trace[0]['line'] == $trace[1]['line']) {
                                        unset($trace[0]['file'], $trace[0]['line']);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // store the new stacktrace
            $this->betterTrace = $trace;
        }
        return $trace;
    }
23
public static function trace($trace = null, $addObject = false)
    {
        if (!self::isDebug()) {
            return false;
        }

        $_this = self::i();

        $trace = $trace ? $trace : debug_backtrace($addObject);
        unset($trace[0]);

        $result = $_this->convertTrace($trace, $addObject);

        return $_this->dump($result, '! backtrace !');
    }
428477
public static function debugBacktraceString($trace = null) {
		$result = [];
		if (!\Debug::$debug) return $result;
		$i = 1;
		// if trace is not provided
		if (empty($trace)) {
			$trace = debug_backtrace();
			unset($trace[0]);
		}
		foreach($trace as $v) {
			$stack = '#' . $i . ' ' . (isset($v['file']) ? $v['file'] : 'Unknown');
			if (isset($v['line'])) {
				$stack.= '(' . $v['line'] . ')';
			}
			// do not show error handler
			if (!(isset($v['class']) && $v['class'] == 'error' && $v['function'] == 'error_handler')) {
				$stack.= ': ';
				if(isset($v['class'])) {
					$stack.= $v['class'] . $v['type'];
				}
				$params = [];
				if (isset($v['args'])) {
					foreach ($v['args'] as $v2) {
						if (gettype($v2) == 'string') {
							$params[] = str_replace(["\n", "\r", "\t"], ' ', $v2);
						} else if (is_array($v2)) {
							$temp = var_export_condensed($v2, ['skip_objects' => true]);
							$params[] = substr($temp, 0, 100) . '...';
						} else {
							$params[] = var_export_condensed($v2, ['skip_objects' => true]);
						}
					}
				}
				$stack.= $v['function'] . '(' . implode(', ', $params) . ');';
			}
			$i++;
			$result[] = $stack;
		}
		return $result;
	}
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);
    }
1316855
public function parse(array $trace)
    {
        $this->trace = &$trace;
        $traceCount = count($trace);
        
        for($this->eachIndex = $traceCount - 1; $this->eachIndex >= 0; --$this->eachIndex)
        {
            $traceLine = $trace[$this->eachIndex];
            if($this->isFindingBeanRealCall)
            {
                if($this->isKeep($traceLine))
                {
                    $this->isFindingBeanRealCall = false;
                }
                else
                {
                    unset($trace[$this->eachIndex]);
                }
            }
            else
            {
                if(isset($traceLine['class']))
                {
                    $ref = new \ReflectionClass($traceLine['class']);
                    if($ref->implementsInterface(IBean::class))
                    {
                        $this->beanRealCallRealClassName = $this->getBeanRealCallRealClassName();
                        if(null === $this->beanRealCallRealClassName)
                        {
                            continue;
                        }
                        $this->isFindingBeanRealCall = true;
                        unset($trace[$this->eachIndex]);
                        --$this->eachIndex;
                        unset($trace[$this->eachIndex]);
                    }
                }
            }
        }
        return array_values($trace);
    }
1021844
private function traceCLI(array $trace, $label) {
            foreach ($trace as $k => $v) {
                $func = $loc = $line = '';
                $argsPresent = isset($v['args']) && !empty($v['args']);

                self::formatTraceLine($v, $func, $loc, $line);

                $this->console->write('<' . $label . 'b>#' . $k . ': </>')
                              ->write('<' . $label . '>' . ($loc ? $loc : '<<unknown file>>') . '</> ')
                              ->write('<' . $label . '>(' . ($line ? 'line ' . $line : 'unknown line') . ')</>')
                              ->write('<' . $label . '> | </>')
                              ->write('<' . $label . '>' . $func . '</>', true);

                if ($argsPresent) {
                    $this->console->write('<' . $label . 'b>Arguments:</>', true);
                    VarDumper::dump($v['args']);
                }

                $this->console->writeln('');
            }
        }
925920
protected function _inferCategory($traces)
    {
        foreach ($traces as $trace) {
            if (isset($trace['object'])) {
                $object = $trace['object'];
                if ($object instanceof LogCategorizable) {
                    return $object->categorizeLog();
                }
            }
        }
        return 'unknown';
    }