added uri class. refactored.
This commit is contained in:
@@ -27,40 +27,14 @@ class Request {
|
||||
* Get the URI for the current request.
|
||||
*
|
||||
* If the request is to the root of the application, a single forward slash
|
||||
* will be returned. Otherwise, the URI will be returned without any leading
|
||||
* or trailing slashes.
|
||||
* will be returned. Otherwise, the URI will be returned with all of the
|
||||
* leading and trailing slashes removed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function uri()
|
||||
{
|
||||
if ( ! is_null(static::$uri)) return static::$uri;
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
// Remove the root application URL from the request URI. If the application
|
||||
// is nested within a sub-directory of the web document root, this will get
|
||||
// rid of all of the the sub-directories from the request URI.
|
||||
$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 ($index !== '/' and strpos($uri, $index) === 0)
|
||||
{
|
||||
$uri = substr($uri, strlen($index));
|
||||
}
|
||||
|
||||
$uri = trim($uri, '/');
|
||||
|
||||
// Format the final request URI. If there is nothing left, we will just
|
||||
// return a single forward slash. Otherwise, we'll remove all of the
|
||||
// leading and trailing spaces from the URI before returning it.
|
||||
return static::$uri = ($uri !== '') ? $uri : '/';
|
||||
return URI::get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user