Barryvdh\Debugbar\DataCollector\QueryCollector::findSource PHP Method

findSource() protected method

Use a backtrace to search for the origin of the query.
protected findSource ( )
    protected function findSource()
    {
        $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
        foreach ($traces as $trace) {
            if (isset($trace['class']) && isset($trace['file']) && strpos($trace['file'], DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) === false) {
                if (isset($trace['object']) && is_a($trace['object'], 'Twig_Template')) {
                    list($file, $line) = $this->getTwigInfo($trace);
                } elseif (strpos($trace['file'], storage_path()) !== false) {
                    $hash = pathinfo($trace['file'], PATHINFO_FILENAME);
                    $line = isset($trace['line']) ? $trace['line'] : '?';
                    if ($name = $this->findViewFromHash($hash)) {
                        return 'view::' . $name . ':' . $line;
                    }
                    return 'view::' . $hash . ':' . $line;
                } else {
                    $file = $trace['file'];
                    $line = isset($trace['line']) ? $trace['line'] : '?';
                }
                return $this->normalizeFilename($file) . ':' . $line;
            } elseif (isset($trace['function']) && $trace['function'] == 'Illuminate\\Routing\\{closure}') {
                return 'Route binding';
            }
        }
    }