got rid of URI class and brought URI determination back to into request class.
This commit is contained in:
@@ -82,7 +82,7 @@ class Form {
|
|||||||
*/
|
*/
|
||||||
protected static function action($action, $https)
|
protected static function action($action, $https)
|
||||||
{
|
{
|
||||||
return HTML::entities(URL::to(((is_null($action)) ? Request::uri()->get() : $action), $https));
|
return HTML::entities(URL::to(((is_null($action)) ? Request::uri() : $action), $https));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ if (Config::$items['session']['driver'] !== '')
|
|||||||
* Manually load some core classes that are used on every request
|
* Manually load some core classes that are used on every request
|
||||||
* This allows to avoid using the loader for these classes.
|
* This allows to avoid using the loader for these classes.
|
||||||
*/
|
*/
|
||||||
require SYS_PATH.'uri'.EXT;
|
|
||||||
require SYS_PATH.'input'.EXT;
|
require SYS_PATH.'input'.EXT;
|
||||||
require SYS_PATH.'request'.EXT;
|
require SYS_PATH.'request'.EXT;
|
||||||
require SYS_PATH.'response'.EXT;
|
require SYS_PATH.'response'.EXT;
|
||||||
@@ -91,7 +90,7 @@ Input::$input = $input;
|
|||||||
*/
|
*/
|
||||||
Routing\Filter::register(require APP_PATH.'filters'.EXT);
|
Routing\Filter::register(require APP_PATH.'filters'.EXT);
|
||||||
|
|
||||||
list($uri, $method) = array(Request::uri()->get(), Request::method());
|
list($uri, $method) = array(Request::uri(), Request::method());
|
||||||
|
|
||||||
Request::$route = IoC::container()->core('routing.router')->route($method, $uri);
|
Request::$route = IoC::container()->core('routing.router')->route($method, $uri);
|
||||||
|
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ class Paginator {
|
|||||||
// We will assume the page links should use HTTPS if the current request
|
// We will assume the page links should use HTTPS if the current request
|
||||||
// is also using HTTPS. Since pagination links automatically point to
|
// is also using HTTPS. Since pagination links automatically point to
|
||||||
// the current URI, this makes pretty good sense.
|
// the current URI, this makes pretty good sense.
|
||||||
list($uri, $secure) = array(Request::uri()->get(), Request::secure());
|
list($uri, $secure) = array(Request::uri(), Request::secure());
|
||||||
|
|
||||||
$appendage = $this->appendage($element, $page);
|
$appendage = $this->appendage($element, $page);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Request {
|
|||||||
/**
|
/**
|
||||||
* The request URI for the current request.
|
* The request URI for the current request.
|
||||||
*
|
*
|
||||||
* @var URI
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static $uri;
|
public static $uri;
|
||||||
|
|
||||||
@@ -24,13 +24,37 @@ class Request {
|
|||||||
const spoofer = '__spoofer';
|
const spoofer = '__spoofer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the URI instance for the current request.
|
* Get the current request's URI.
|
||||||
*
|
*
|
||||||
* @return URI
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uri()
|
public static function uri()
|
||||||
{
|
{
|
||||||
return (is_null(static::$uri)) ? static::$uri = new URI($_SERVER) : static::$uri;
|
if ( ! is_null(static::$uri)) return static::$uri;
|
||||||
|
|
||||||
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
// 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 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If all we are left with is an empty string, we will return a single forward
|
||||||
|
// slash indicating the request is to the root of the application. If we have
|
||||||
|
// something left, we will its remove the leading and trailing slashes.
|
||||||
|
return static::$uri = (($uri = trim($uri, '/')) !== '') ? $uri : '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
<?php namespace Laravel;
|
|
||||||
|
|
||||||
class URI {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The request URI for the current request.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $uri;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The $_SERVER global array for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance of the URI class.
|
|
||||||
*
|
|
||||||
* @param array $server
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($server)
|
|
||||||
{
|
|
||||||
$this->server = $server;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the request 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 with all leading
|
|
||||||
* and trailing slashes removed. The application URL and index file will
|
|
||||||
* also be removed since they are not used when routing the request.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function get()
|
|
||||||
{
|
|
||||||
if ( ! is_null($this->uri)) return $this->uri;
|
|
||||||
|
|
||||||
return $this->uri = $this->format($this->clean($this->parse($this->server['REQUEST_URI'])));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove extraneous information from the given request URI.
|
|
||||||
*
|
|
||||||
* @param string $uri
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function clean($uri)
|
|
||||||
{
|
|
||||||
$uri = $this->remove($uri, $this->parse(Config::$items['application']['url']));
|
|
||||||
|
|
||||||
if (($index = '/'.Config::$items['application']['index']) !== '/')
|
|
||||||
{
|
|
||||||
$uri = $this->remove($uri, $index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a given string URI using PHP_URL_PATH to remove the domain.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function parse($uri)
|
|
||||||
{
|
|
||||||
return parse_url($uri, PHP_URL_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a string from the beginning of a URI.
|
|
||||||
*
|
|
||||||
* @param string $uri
|
|
||||||
* @param string $remove
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function remove($uri, $remove)
|
|
||||||
{
|
|
||||||
return (strpos($uri, $remove) === 0) ? substr($uri, strlen($remove)) : $uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format the URI for use throughout the framework.
|
|
||||||
*
|
|
||||||
* @param string $uri
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function format($uri)
|
|
||||||
{
|
|
||||||
return (($uri = trim($uri, '/')) !== '') ? $uri : '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,7 @@ class RequestTest extends PHPUnit_Framework_TestCase {
|
|||||||
public function test_correct_uri_is_returned_when_request_uri_is_used($uri, $expectation)
|
public function test_correct_uri_is_returned_when_request_uri_is_used($uri, $expectation)
|
||||||
{
|
{
|
||||||
$_SERVER['REQUEST_URI'] = $uri;
|
$_SERVER['REQUEST_URI'] = $uri;
|
||||||
$this->assertEquals($expectation, Laravel\Request::uri()->get());
|
$this->assertEquals($expectation, Laravel\Request::uri());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_request_method_returns_spoofed_method_if_uri_is_spoofed()
|
public function test_request_method_returns_spoofed_method_if_uri_is_spoofed()
|
||||||
|
|||||||
Reference in New Issue
Block a user