Commit 54311a41 authored by Taylor Otwell's avatar Taylor Otwell

Added file context to error class.

parent f6ff5370
......@@ -86,7 +86,8 @@ class Error {
->bind('message', $message)
->bind('file', $file)
->bind('line', $e->getLine())
->bind('trace', $e->getTraceAsString());
->bind('trace', $e->getTraceAsString())
->bind('contexts', static::context($file, $e->getLine()));
Response::make($view, 500)->send();
}
......@@ -96,4 +97,36 @@ class Error {
}
}
/**
* Get the code surrounding a given line in a file.
*
* @param string $path
* @param int $line
* @param int $padding
* @return string
*/
private static function context($path, $line, $padding = 5)
{
if (file_exists($path))
{
$file = file($path, FILE_IGNORE_NEW_LINES);
array_unshift($file, '');
if (($start = $line - $padding) < 0)
{
$start = 0;
}
if (($length = ($line - $start) + $padding + 1) < 0)
{
$length = 0;
}
return array_slice($file, $start, $length, true);
}
return array();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment