refactoring classes.
This commit is contained in:
parent
695a8848ed
commit
7225ec0a9e
|
@ -27,6 +27,28 @@ public static function uri()
|
||||||
{
|
{
|
||||||
if ( ! is_null(static::$uri)) return static::$uri;
|
if ( ! is_null(static::$uri)) return static::$uri;
|
||||||
|
|
||||||
|
$uri = static::raw_uri();
|
||||||
|
|
||||||
|
if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0)
|
||||||
|
{
|
||||||
|
$uri = substr($uri, strlen($base));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($uri, $index = '/index.php') === 0)
|
||||||
|
{
|
||||||
|
$uri = substr($uri, strlen($index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the raw request URI from the $_SERVER array.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function raw_uri()
|
||||||
|
{
|
||||||
if (isset($_SERVER['PATH_INFO']))
|
if (isset($_SERVER['PATH_INFO']))
|
||||||
{
|
{
|
||||||
$uri = $_SERVER['PATH_INFO'];
|
$uri = $_SERVER['PATH_INFO'];
|
||||||
|
@ -45,17 +67,7 @@ public static function uri()
|
||||||
throw new \Exception("Malformed request URI. Request terminated.");
|
throw new \Exception("Malformed request URI. Request terminated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0)
|
return $uri;
|
||||||
{
|
|
||||||
$uri = substr($uri, strlen($base));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($uri, $index = '/index.php') === 0)
|
|
||||||
{
|
|
||||||
$uri = substr($uri, strlen($index));
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -133,7 +133,10 @@ public static function prepare($response)
|
||||||
*/
|
*/
|
||||||
public function send()
|
public function send()
|
||||||
{
|
{
|
||||||
if ( ! array_key_exists('Content-Type', $this->headers)) $this->header('Content-Type', 'text/html; charset=utf-8');
|
if ( ! array_key_exists('Content-Type', $this->headers))
|
||||||
|
{
|
||||||
|
$this->header('Content-Type', 'text/html; charset=utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! headers_sent()) $this->send_headers();
|
if ( ! headers_sent()) $this->send_headers();
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,15 @@ public static function load($id)
|
||||||
{
|
{
|
||||||
static::$session = ( ! is_null($id)) ? static::driver()->load($id) : null;
|
static::$session = ( ! is_null($id)) ? static::driver()->load($id) : null;
|
||||||
|
|
||||||
if (static::invalid(static::$session)) static::$session = array('id' => Str::random(40), 'data' => array());
|
if (static::invalid(static::$session))
|
||||||
|
{
|
||||||
|
static::$session = array('id' => Str::random(40), 'data' => array());
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! static::has('csrf_token')) static::put('csrf_token', Str::random(16));
|
if ( ! static::has('csrf_token'))
|
||||||
|
{
|
||||||
|
static::put('csrf_token', Str::random(16));
|
||||||
|
}
|
||||||
|
|
||||||
static::$session['last_activity'] = time();
|
static::$session['last_activity'] = time();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue