Skip to content

Commit

Permalink
Find View name from hash
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed May 18, 2016
1 parent 97e8f60 commit 1d1eb50
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : '?';
Expand All @@ -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
*
Expand Down

0 comments on commit 1d1eb50

Please sign in to comment.