refactored error handling for better architecture.

This commit is contained in:
Taylor Otwell
2011-08-16 12:26:52 -05:00
parent e2c69d0c84
commit 5c3c2e2d9c
5 changed files with 259 additions and 126 deletions

View File

@@ -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.
*