mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-25 18:51:42 +02:00
Allow overwriting the trace finder on Messages (#758)
This commit is contained in:
@@ -30,6 +30,12 @@ class MessagesCollector extends AbstractLogger implements DataCollectorInterface
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $collectFile = false;
|
protected $collectFile = false;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
protected $backtraceLimit = 5;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $backtraceExcludePaths = ['/vendor/'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
@@ -44,6 +50,45 @@ class MessagesCollector extends AbstractLogger implements DataCollectorInterface
|
|||||||
$this->collectFile = $enabled;
|
$this->collectFile = $enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $limit
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function limitBacktrace($limit)
|
||||||
|
{
|
||||||
|
$this->backtraceLimit = $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set paths to exclude from the backtrace
|
||||||
|
*
|
||||||
|
* @param array $excludePaths Array of file paths to exclude from backtrace
|
||||||
|
*/
|
||||||
|
public function addBacktraceExcludePaths($excludePaths)
|
||||||
|
{
|
||||||
|
$this->backtraceExcludePaths = array_merge($this->backtraceExcludePaths, $excludePaths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given file is to be excluded from analysis
|
||||||
|
*
|
||||||
|
* @param string $file
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function fileIsInExcludedPath($file)
|
||||||
|
{
|
||||||
|
$normalizedPath = str_replace('\\', '/', $file);
|
||||||
|
|
||||||
|
foreach ($this->backtraceExcludePaths as $excludedPath) {
|
||||||
|
if (strpos($normalizedPath, $excludedPath) !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $messageHtml
|
* @param string|null $messageHtml
|
||||||
* @param mixed $message
|
* @param mixed $message
|
||||||
@@ -60,6 +105,24 @@ class MessagesCollector extends AbstractLogger implements DataCollectorInterface
|
|||||||
return $messageHtml;
|
return $messageHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $stacktrace
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getStackTraceItem($stacktrace)
|
||||||
|
{
|
||||||
|
foreach ($stacktrace as $trace) {
|
||||||
|
if (!isset($trace['file']) || $this->fileIsInExcludedPath($trace['file'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $trace;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stacktrace[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a message
|
* Adds a message
|
||||||
*
|
*
|
||||||
@@ -83,16 +146,7 @@ class MessagesCollector extends AbstractLogger implements DataCollectorInterface
|
|||||||
|
|
||||||
$stackItem = [];
|
$stackItem = [];
|
||||||
if ($this->collectFile) {
|
if ($this->collectFile) {
|
||||||
$stacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
|
$stackItem = $this->getStackTraceItem(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $this->backtraceLimit));
|
||||||
$stackItem = $stacktrace[0];
|
|
||||||
foreach ($stacktrace as $trace) {
|
|
||||||
if (!isset($trace['file']) || strpos($trace['file'], '/vendor/') !== false) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stackItem = $trace;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->messages[] = array(
|
$this->messages[] = array(
|
||||||
|
Reference in New Issue
Block a user