revert back to more sensible architecture.

This commit is contained in:
Taylor Otwell
2011-09-20 23:14:09 -05:00
parent 47db2ff19b
commit 4525eae25a
33 changed files with 1050 additions and 1558 deletions

View File

@@ -2,33 +2,12 @@
class Request {
/**
* The URI for the current request.
*
* @var string
*/
protected $uri;
/**
* The $_SERVER array for the request.
*
* @var array
*/
protected $server;
/**
* The $_POST array for the request.
*
* @var array
*/
protected $post;
/**
* The route handling the current request.
*
* @var Routing\Route
*/
public $route;
public static $route;
/**
* The request data key that is used to indicate the spoofed request method.
@@ -38,35 +17,15 @@ class Request {
const spoofer = '__spoofer';
/**
* Create a new request instance.
* Get the URI for the current request.
*
* @param string $uri
* @param array $server
* @param array $post
* @return void
*/
public function __construct($uri, $server, $post)
{
$this->uri = $uri;
$this->post = $post;
$this->server = $server;
}
/**
* Determine the request URI.
*
* The request URI will be trimmed to remove to the application URL and application index file.
* If the request is to the root of the application, the URI will be set to a forward slash.
*
* If the $_SERVER "PATH_INFO" variable is available, it will be used; otherwise, we will try
* to determine the URI using the REQUEST_URI variable. If neither are available, an exception
* will be thrown by the method.
* Note: This method is the equivalent of calling the URI::get method.
*
* @return string
*/
public function uri()
public static function uri()
{
return $this->uri;
return URI::get();
}
/**
@@ -84,9 +43,9 @@ class Request {
*
* @return string
*/
public function format()
public static function format()
{
return (($extension = pathinfo($this->uri(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
return (($extension = pathinfo(URI::get(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
}
/**
@@ -98,9 +57,9 @@ class Request {
*
* @return string
*/
public function method()
public static function method()
{
return ($this->spoofed()) ? $this->post[Request::spoofer] : $this->server['REQUEST_METHOD'];
return (static::spoofed()) ? $_POST[Request::spoofer] : $_SERVER['REQUEST_METHOD'];
}
/**
@@ -120,9 +79,9 @@ class Request {
* @param mixed $default
* @return string
*/
public function server($key = null, $default = null)
public static function server($key = null, $default = null)
{
return Arr::get($this->server, strtoupper($key), $default);
return Arr::get($_SERVER, strtoupper($key), $default);
}
/**
@@ -134,9 +93,9 @@ class Request {
*
* @return bool
*/
public function spoofed()
public static function spoofed()
{
return is_array($this->post) and array_key_exists(Request::spoofer, $this->post);
return is_array($_POST) and array_key_exists(Request::spoofer, $_POST);
}
/**
@@ -155,19 +114,19 @@ class Request {
* @param mixed $default
* @return string
*/
public function ip($default = '0.0.0.0')
public static function ip($default = '0.0.0.0')
{
if (isset($this->server['HTTP_X_FORWARDED_FOR']))
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
return $this->server['HTTP_X_FORWARDED_FOR'];
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif (isset($this->server['HTTP_CLIENT_IP']))
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
{
return $this->server['HTTP_CLIENT_IP'];
return $_SERVER['HTTP_CLIENT_IP'];
}
elseif (isset($this->server['REMOTE_ADDR']))
elseif (isset($_SERVER['REMOTE_ADDR']))
{
return $this->server['REMOTE_ADDR'];
return $_SERVER['REMOTE_ADDR'];
}
return ($default instanceof \Closure) ? call_user_func($default) : $default;
@@ -181,9 +140,9 @@ class Request {
*
* @return string
*/
public function protocol()
public static function protocol()
{
return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http';
return (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
}
/**
@@ -191,9 +150,9 @@ class Request {
*
* @return bool
*/
public function secure()
public static function secure()
{
return $this->protocol() == 'https';
return static::protocol() == 'https';
}
/**
@@ -201,11 +160,11 @@ class Request {
*
* @return bool
*/
public function ajax()
public static function ajax()
{
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
if ( ! isset($_SERVER['HTTP_X_REQUESTED_WITH'])) return false;
return strtolower($this->server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
}
/**
@@ -213,6 +172,6 @@ class Request {
*
* @return Route
*/
public function route() { return $this->route; }
public function route() { return static::$route; }
}