From 766fa9831a9b3c83092eb5cac9d8503dd9053227 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Sep 2011 22:45:50 -0500 Subject: [PATCH] tweaking code and adding comments. --- application/views/error/exception.php | 25 +-------------- laravel/cookie.php | 4 ++- laravel/file.php | 45 ++++++++++++--------------- 3 files changed, 24 insertions(+), 50 deletions(-) diff --git a/application/views/error/exception.php b/application/views/error/exception.php index a1aac7e9..25b3987e 100644 --- a/application/views/error/exception.php +++ b/application/views/error/exception.php @@ -3,7 +3,7 @@ - Laravel - Uncaught Exception + Laravel - <?php echo $severity; ?> @@ -71,19 +61,6 @@

Stack Trace

getTraceAsString(); ?>
- -

Snapshot

- - getFile(), $exception->getLine()) as $num => $context) - { - $lines[] = $num.': '.$context; - } - ?> - -
\ No newline at end of file diff --git a/laravel/cookie.php b/laravel/cookie.php index 669f0cf0..7e9ab82c 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -83,7 +83,9 @@ class Cookie { if ($minutes < 0) unset($_COOKIE[$name]); - $time = ($minutes != 0) ? time() + ($minutes * 60) : 0; + // Since PHP needs the cookie lifetime in seconds, we will calculate it here. + // A "0" lifetime means the cookie expires when the browser closes. + $time = ($minutes !== 0) ? time() + ($minutes * 60) : 0; return setcookie($name, $value, $time, $path, $domain, $secure, $http_only); } diff --git a/laravel/file.php b/laravel/file.php index 58eeed14..8a4d6f24 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -104,21 +104,31 @@ class File { } /** - * Move an uploaded file to permanenet storage. + * Move an uploaded file to permanent storage. * * @param string $key * @param string $path * @param array $files * @return bool */ - public static function upload($key, $path, $files) + public static function upload($key, $path, $files = null) { + if (is_null($files)) $files = $_FILES; + return move_uploaded_file($files[$key]['tmp_name'], $path); } /** * Get a file MIME type by extension. * + * + * // Determine the MIME type for the .tar extension + * $mime = File::mime('tar'); + * + * // Return a default value if the MIME can't be determined + * $mime = File::mime('ext', 'application/octet-stream'); + * + * * @param string $extension * @param string $default * @return string @@ -137,6 +147,14 @@ class File { * * The Fileinfo PHP extension will be used to determine the MIME type of the file. * + * + * // Determine if a file is a JPG image + * $jpg = File::is('jpg', 'path/to/file.jpg'); + * + * // Determine if a file is one of a given list of types + * $image = File::is(array('jpg', 'png', 'gif'), 'path/to/file'); + * + * * @param array|string $extension * @param string $path * @return bool @@ -155,27 +173,4 @@ 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); - } - } \ No newline at end of file