From bcd3bd85911fecadfa32bc251afcf4bac74fb6b8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 28 Mar 2012 22:58:49 -0500 Subject: [PATCH] adding header support. --- laravel/request.php | 54 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/laravel/request.php b/laravel/request.php index 7efeadf7..6ed7fe13 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -21,7 +21,7 @@ class Request { * * @var string */ - const spoofer = '__spoofer'; + const spoofer = '_method'; /** * Get the URI for the current request. @@ -40,12 +40,36 @@ public static function uri() */ public static function method() { - if ($_SERVER['REQUEST_METHOD'] == 'HEAD') - { - return 'GET'; - } + $method = static::foundation()->getMethod(); - return (static::spoofed()) ? $_POST[Request::spoofer] : $_SERVER['REQUEST_METHOD']; + return ($method == 'HEAD') ? 'GET' : $method; + } + + /** + * Get a header from the request. + * + * + * // Get a header from the request + * $referer = Request::header('referer'); + * + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public static function header($key, $default = null) + { + return array_get(static::foundation()->headers->all(), $key, $default); + } + + /** + * Get all of the HTTP request headers. + * + * @return array + */ + public static function headers() + { + return static::foundation()->headers->all(); } /** @@ -57,7 +81,7 @@ public static function method() */ public static function server($key = null, $default = null) { - return array_get($_SERVER, strtoupper($key), $default); + return array_get(static::foundation()->server->all(), $key, $default); } /** @@ -67,7 +91,7 @@ public static function server($key = null, $default = null) */ public static function spoofed() { - return is_array($_POST) and array_key_exists(Request::spoofer, $_POST); + return ! is_null(static::foundation()->get(Request::spoofer)); } /** @@ -81,16 +105,6 @@ public static function ip($default = '0.0.0.0') return value(static::foundation()->getClientIp(), $default); } - /** - * Get the HTTP protocol for the request. - * - * @return string - */ - public static function protocol() - { - return array_get($_SERVER, 'SERVER_PROTOCOL', 'HTTP/1.1'); - } - /** * Get the list of acceptable content types for the request. * @@ -150,7 +164,7 @@ public static function ajax() */ public static function referrer() { - return array_get($_SERVER, 'HTTP_REFERER'); + return static::foundation()->headers->get('referer'); } /** @@ -170,7 +184,7 @@ public static function cli() */ public static function env() { - if (isset($_SERVER['LARAVEL_ENV'])) return $_SERVER['LARAVEL_ENV']; + return static::foundation()->server->get('LARAVEL_ENV'); } /**