3 namespace Friendica\Util;
6 * Get Introspection information about the current call
10 private $skipStackFramesCount;
12 private $skipClassesPartials;
14 private $skipFunctions = [
16 'call_user_func_array',
20 * @param array $skipClassesPartials An array of classes to skip during logging
21 * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call
23 public function __construct($skipClassesPartials = array(), $skipStackFramesCount = 0)
25 $this->skipClassesPartials = $skipClassesPartials;
26 $this->skipStackFramesCount = $skipStackFramesCount;
30 * Adds new classes to get skipped
31 * @param array $classNames
33 public function addClasses(array $classNames)
35 $this->skipClassesPartials = array_merge($this->skipClassesPartials, $classNames);
39 * Returns the introspection record of the current call
43 public function getRecord()
45 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
49 while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
53 $i += $this->skipStackFramesCount;
56 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null,
57 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
58 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
63 * Checks if the current trace class or function has to be skipped
65 * @param array $trace The current trace array
66 * @param int $index The index of the current hierarchy level
67 * @return bool True if the class or function should get skipped, otherwise false
69 private function isTraceClassOrSkippedFunction(array $trace, $index)
71 if (!isset($trace[$index])) {
75 if (isset($trace[$index]['class'])) {
76 foreach ($this->skipClassesPartials as $part) {
77 if (strpos($trace[$index]['class'], $part) !== false) {
81 } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) {