refactoring.

This commit is contained in:
Taylor Otwell
2011-09-21 21:46:16 -05:00
parent b9b9711921
commit 0c4018ec88
42 changed files with 980 additions and 1330 deletions

View File

@@ -119,13 +119,6 @@ class File {
/**
* Get a file MIME type by extension.
*
* If the MIME type can't be determined, "application/octet-stream" will be returned.
*
* <code>
* // Returns 'application/x-tar'
* $mime = File::mime('path/to/file.tar');
* </code>
*
* @param string $extension
* @param string $default
* @return string
@@ -144,14 +137,6 @@ class File {
*
* The Fileinfo PHP extension will be used to determine the MIME type of the file.
*
* <code>
* // Determine if a file is a JPG image
* $image = File::is('jpg', 'path/to/image.jpg');
*
* // Determine if a file is any one of an array of types
* $image = File::is(array('jpg', 'png', 'gif'), 'path/to/image.jpg');
* </code>
*
* @param array|string $extension
* @param string $path
* @return bool
@@ -170,4 +155,27 @@ class File {
return false;
}
/**
* 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);
}
}