diff --git a/src/DataCollector/QueryCollector.php b/src/DataCollector/QueryCollector.php index 941647ecf..59abbd6e2 100644 --- a/src/DataCollector/QueryCollector.php +++ b/src/DataCollector/QueryCollector.php @@ -34,6 +34,7 @@ class QueryCollector extends PDOCollector '/vendor/october/rain', '/vendor/barryvdh/laravel-debugbar', ]; + protected static $customFrameParsers = []; /** * @param TimeDataCollector $timeCollector @@ -43,6 +44,14 @@ public function __construct(TimeDataCollector $timeCollector = null) $this->timeCollector = $timeCollector; } + /** + * Add a custom frame parser for a specific object type. + */ + public static function addCustomFrameParser(string $objectType, callable $customFrameParser): void + { + static::$customFrameParsers[$objectType] = $customFrameParser; + } + /** * @param int|null $softLimit After the soft limit, no parameters/backtrace are captured * @param int|null $hardLimit After the hard limit, queries are ignored @@ -334,6 +343,15 @@ protected function parseTrace($index, array $trace) ) { $frame->file = $trace['file']; + foreach (static::$customFrameParsers as $objectType => $customFrameParser) { + if (isset($trace['object']) && is_a($trace['object'], $objectType)) { + $frame->line = '?'; + $frame = $customFrameParser($frame, $trace); + $frame->name = $this->normalizeFilePath($frame->file); + return $frame; + } + } + if (isset($trace['object']) && is_a($trace['object'], 'Twig_Template')) { list($frame->file, $frame->line) = $this->getTwigInfo($trace); } elseif (strpos($frame->file, storage_path()) !== false) {