refactoring. added default controller. added uri class.
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
|
||||
class Request {
|
||||
|
||||
/**
|
||||
* The request URI for the current request.
|
||||
*
|
||||
* @var URI
|
||||
*/
|
||||
public static $uri;
|
||||
|
||||
/**
|
||||
* The route handling the current request.
|
||||
*
|
||||
@@ -9,13 +16,6 @@ class Request {
|
||||
*/
|
||||
public static $route;
|
||||
|
||||
/**
|
||||
* The request URI for the current request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $uri;
|
||||
|
||||
/**
|
||||
* The request data key that is used to indicate a spoofed request method.
|
||||
*
|
||||
@@ -24,79 +24,36 @@ class Request {
|
||||
const spoofer = '__spoofer';
|
||||
|
||||
/**
|
||||
* Get the URI for the current request.
|
||||
* Get the URI instance for the current request.
|
||||
*
|
||||
* Note: This method is the equivalent of calling the URI::get method.
|
||||
*
|
||||
* @return string
|
||||
* @return URI
|
||||
*/
|
||||
public static function uri()
|
||||
{
|
||||
if ( ! is_null(static::$uri)) return static::$uri;
|
||||
|
||||
// Sniff the request URI out of the $_SERVER array. The PATH_IFNO
|
||||
// variable contains the URI without the base URL or index page,
|
||||
// so we will use that if possible, otherwise we will parse the
|
||||
// URI out of the REQUEST_URI element.
|
||||
if (isset($_SERVER['PATH_INFO']))
|
||||
{
|
||||
$uri = $_SERVER['PATH_INFO'];
|
||||
}
|
||||
elseif (isset($_SERVER['REQUEST_URI']))
|
||||
{
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
if ($uri === false)
|
||||
{
|
||||
throw new \Exception("Invalid request URI. Request terminated.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception("Unable to determine the request URI.");
|
||||
}
|
||||
|
||||
// Remove the application URL and the application index page from
|
||||
// the request URI. Both of these elements will interfere with the
|
||||
// routing engine and are extraneous, so they will be removed.
|
||||
$base = parse_url(Config::$items['application']['url'], PHP_URL_PATH);
|
||||
|
||||
if (strpos($uri, $base) === 0)
|
||||
{
|
||||
$uri = substr($uri, strlen($base));
|
||||
}
|
||||
|
||||
$index = '/'.Config::$items['application']['index'];
|
||||
|
||||
if (trim($index) !== '/' and strpos($uri, $index) === 0)
|
||||
{
|
||||
$uri = substr($uri, strlen($index));
|
||||
}
|
||||
|
||||
// Request URIs to the root of the application will be returned
|
||||
// as a single forward slash. Otherwise, the request URI will be
|
||||
// returned without leading or trailing slashes.
|
||||
return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
||||
return (is_null(static::$uri)) ? static::$uri = new URI($_SERVER) : static::$uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request format.
|
||||
*
|
||||
* The format is determined by essentially taking the "extension" of the URI.
|
||||
* The format is determined by taking the "extension" of the URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public static function format()
|
||||
public static function format($uri = null)
|
||||
{
|
||||
return (($extension = pathinfo(static::uri(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
|
||||
if (is_null($uri)) $uri = static::uri()->get();
|
||||
|
||||
return (($extension = pathinfo($uri, PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request method.
|
||||
*
|
||||
* Typically, this will be the value of the REQUEST_METHOD $_SERVER variable.
|
||||
* However, when the request is being spoofed by a hidden form value, the request
|
||||
* method will be stored in the $_POST array.
|
||||
* This will usually be the value of the REQUEST_METHOD $_SERVER variable
|
||||
* However, when the request method is spoofed using a hidden form value,
|
||||
* the method will be stored in the $_POST array.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -122,10 +79,6 @@ class Request {
|
||||
/**
|
||||
* Determine if the request method is being spoofed by a hidden Form element.
|
||||
*
|
||||
* Hidden elements are used to spoof PUT and DELETE requests since they are not supported
|
||||
* by HTML forms. If the request is being spoofed, Laravel considers the spoofed request
|
||||
* method the actual request method throughout the framework.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function spoofed()
|
||||
|
||||
Reference in New Issue
Block a user