From 1d1eb50246aba576362773187565bcf79a0593bd Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 18 May 2016 10:19:30 +0200 Subject: [PATCH] Find View name from hash --- src/DataCollector/QueryCollector.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/DataCollector/QueryCollector.php b/src/DataCollector/QueryCollector.php index 38e9a192..a2a4a791 100644 --- a/src/DataCollector/QueryCollector.php +++ b/src/DataCollector/QueryCollector.php @@ -211,7 +211,13 @@ protected function findSource() if (isset($trace['object']) && is_a($trace['object'], 'Twig_Template')) { list($file, $line) = $this->getTwigInfo($trace); } elseif (strpos($trace['file'], storage_path()) !== false) { - return 'Template file'; + $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'] : '?'; @@ -224,6 +230,26 @@ protected function findSource() } } + /** + * Find the template name from the hash. + * + * @param string $hash + * @return null|string + */ + protected function findViewFromHash($hash) + { + $finder = app('view')->getFinder(); + $reflection = new \ReflectionClass($finder); + $property = $reflection->getProperty('views'); + $property->setAccessible(true); + + foreach ($property->getValue($finder) as $name => $path){ + if (sha1($path) == $hash) { + return $name; + } + } + } + /** * Get the filename/line from a Twig template trace *