refactored error handling for better architecture.
This commit is contained in:
@@ -48,6 +48,29 @@ class File {
|
||||
return pathinfo($path, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lines surrounding a given line in a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $line
|
||||
* @param int $padding
|
||||
* @return array
|
||||
*/
|
||||
public static function snapshot($path, $line, $padding = 5)
|
||||
{
|
||||
if ( ! file_exists($path)) return array();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a file MIME type by extension.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user