Commit b1342a59 by Taylor Otwell

Refactoring the Request class.

parent af7ba046
......@@ -35,47 +35,43 @@ class Request {
elseif (isset($_SERVER['REQUEST_URI']))
{
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if ($uri === false)
{
throw new \Exception("Malformed request URI. Request terminated.");
}
}
else
{
throw new \Exception('Unable to determine the request URI.');
}
// -------------------------------------------------------
// Remove the application URL.
// -------------------------------------------------------
$base_url = parse_url(Config::get('application.url'), PHP_URL_PATH);
if (strpos($uri, $base_url) === 0)
if ($uri === false)
{
$uri = (string) substr($uri, strlen($base_url));
throw new \Exception("Malformed request URI. Request terminated.");
}
// -------------------------------------------------------
// Remove the application index and any extra slashes.
// -------------------------------------------------------
$index = Config::get('application.index');
if (strpos($uri, '/'.$index) === 0)
{
$uri = (string) substr($uri, strlen('/'.$index));
}
$uri = static::remove_from_uri($uri, parse_url(Config::get('application.url'), PHP_URL_PATH));
$uri = static::remove_from_uri($uri, '/'.Config::get('application.index'));
$uri = trim($uri, '/');
// -------------------------------------------------------
// If the requests is to the root of the application, we
// always return a single forward slash.
// -------------------------------------------------------
return ($uri == '') ? '/' : strtolower($uri);
}
/**
* Remove a string from the beginning of a URI.
*
* @param string $uri
* @param string $value
* @return string
*/
private static function remove_from_uri($uri, $value)
{
if (strpos($uri, $value) === 0)
{
$uri = (string) substr($uri, strlen($value));
}
return $uri;
}
/**
* Get the request method.
*
* The request method may be spoofed if a hidden "REQUEST_METHOD" POST element
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment