From f9ef17a6853cc2a25bb1f0d7939d74e8400d6166 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Mon, 15 Mar 2010 21:06:36 +0000 Subject: [PATCH] No more relative urls by default, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@129 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- app/Action.php | 10 ++-------- app/FrontController.php | 2 +- classes/Env.class.php | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/Action.php b/app/Action.php index dc56f40..63c7cca 100644 --- a/app/Action.php +++ b/app/Action.php @@ -41,16 +41,10 @@ abstract class Action * Redirect * * @param mixed $url - * @param mixed $relative Default to true */ - protected function redirect($url = null, $relative = true) + protected function redirect($url = null) { - $url = ($url) ? $url : Env::getRequestUri(); - - if ($relative) { - $url = FrontController::getInstance()->getBaseUrl() . $url; - } - header('Location: ' . $url); + header('Location: ' . (($url) ? $url : Env::getRequestUri())); exit(); } diff --git a/app/FrontController.php b/app/FrontController.php index ada6599..689025c 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -100,7 +100,7 @@ class FrontController public function execute() { try { - $request = Env::getRequestUri(); + $request = Env::getRequestUri(true); $route = $this->getRouter()->route($request); if (!$route) { throw new Error404Exception('Route for "' . $request . '" not found'); diff --git a/classes/Env.class.php b/classes/Env.class.php index 109c2d1..062c6fd 100644 --- a/classes/Env.class.php +++ b/classes/Env.class.php @@ -14,22 +14,24 @@ class Env { - static protected $request = null; + static protected $request = array(); static protected $params = array(); - static public function getRequestUri() + static public function getRequestUri($trim_base = false) { - if (self::$request === null) { + if (!isset(self::$request[$trim_base])) { // removes get params - list(self::$request, ) = explode('?', Env::Server('REQUEST_URI')); - // removes base url - $base = FrontController::getInstance()->getBaseUrl(); - if (($length = strlen($base)) > 0 && strpos(self::$request, $base) === 0) { - self::$request = (string) substr(self::$request, $length); + list(self::$request[$trim_base], ) = explode('?', Env::Server('REQUEST_URI')); + if ($trim_base) { + // removes base url + $base = FrontController::getInstance()->getBaseUrl(); + if (($length = strlen($base)) > 0 && strpos(self::$request[$trim_base], $base) === 0) { + self::$request[$trim_base] = (string) substr(self::$request[$trim_base], $length); + } } } - return self::$request; + return self::$request[$trim_base]; } static public function Get($key = null, $default = null)