refactoring container for speed.
This commit is contained in:
@@ -9,25 +9,7 @@ class URI {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $uri;
|
||||
|
||||
/**
|
||||
* The $_SERVER array for the current request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* Create a new URI parser instance.
|
||||
*
|
||||
* @param array $server
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($server)
|
||||
{
|
||||
$this->server = $server;
|
||||
}
|
||||
protected static $uri;
|
||||
|
||||
/**
|
||||
* Determine the request URI.
|
||||
@@ -41,16 +23,16 @@ class URI {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get()
|
||||
public static function get()
|
||||
{
|
||||
if ( ! is_null($this->uri)) return $this->uri;
|
||||
if ( ! is_null(static::$uri)) return static::$uri;
|
||||
|
||||
if (($uri = $this->from_server()) === false)
|
||||
if (($uri = static::from_server()) === false)
|
||||
{
|
||||
throw new \Exception('Malformed request URI. Request terminated.');
|
||||
}
|
||||
|
||||
return $this->uri = $this->format($this->clean($uri));
|
||||
return static::$uri = static::format(static::clean($uri));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +50,9 @@ class URI {
|
||||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public function segment($segment = null, $default = null)
|
||||
public static function segment($segment = null, $default = null)
|
||||
{
|
||||
$segments = Arr::without(explode('/', $this->get()), array(''));
|
||||
$segments = Arr::without(explode('/', static::get()), array(''));
|
||||
|
||||
if ( ! is_null($segment)) $segment = $segment - 1;
|
||||
|
||||
@@ -82,20 +64,20 @@ class URI {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function from_server()
|
||||
protected static function from_server()
|
||||
{
|
||||
// If the PATH_INFO $_SERVER element is set, we will use since it contains
|
||||
// the request URI formatted perfectly for Laravel's routing engine.
|
||||
if (isset($this->server['PATH_INFO']))
|
||||
if (isset($_SERVER['PATH_INFO']))
|
||||
{
|
||||
return $this->server['PATH_INFO'];
|
||||
return $_SERVER['PATH_INFO'];
|
||||
}
|
||||
|
||||
// If the REQUEST_URI is set, we need to extract the URL path since this
|
||||
// should return the URI formatted in a manner similar to PATH_INFO.
|
||||
elseif (isset($this->server['REQUEST_URI']))
|
||||
elseif (isset($_SERVER['REQUEST_URI']))
|
||||
{
|
||||
return parse_url($this->server['REQUEST_URI'], PHP_URL_PATH);
|
||||
return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
}
|
||||
|
||||
throw new \Exception('Unable to determine the request URI.');
|
||||
@@ -110,7 +92,7 @@ class URI {
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function clean($uri)
|
||||
protected static function clean($uri)
|
||||
{
|
||||
foreach (array(parse_url(Config::get('application.url'), PHP_URL_PATH), '/index.php') as $value)
|
||||
{
|
||||
@@ -128,7 +110,7 @@ class URI {
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function format($uri)
|
||||
protected static function format($uri)
|
||||
{
|
||||
return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user