From 31bd77fde04d0dbedc1d6b49ac6c286c7f115711 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Mon, 8 Dec 2008 11:00:15 +0000 Subject: [PATCH] rewrite base & default decorator setup git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@21 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Router.class.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/classes/Router.class.php b/classes/Router.class.php index 8779db7..ba3c256 100644 --- a/classes/Router.class.php +++ b/classes/Router.class.php @@ -13,7 +13,12 @@ final class Router { + protected $routes = array(); + + static protected $rewrite_base = ''; + static protected $decorator = DEFAULT_DECORATOR; + /** * Добавить роутер @@ -26,6 +31,7 @@ final class Router function add($name, $path, $action, $params = array()) { $this->routes[$name] = new Route($path, $action, $params); + $this->routes[$name]->decorator = self::$decorator; } /** @@ -49,9 +55,9 @@ final class Router */ function proccess($path) { - $path = explode('/', $path); - - foreach ($this->routes as $name => $route) { + $path = explode('/', ltrim($path, self::getRewriteBase())); + + foreach($this->routes as $name => $route) { if ($route->match($path)) { $route->action .= ACTION_POSTFIX; Env::setParams($route->params); @@ -60,6 +66,21 @@ final class Router } throw new Exception(E_404); } + + static public function setRewriteBase($value = '') + { + self::$rewrite_base = $value; + } + + static public function getRewriteBase() + { + return self::$rewrite_base; + } + + static public function setDefaultDecorator($decorator) + { + self::$decorator = $decorator.DECORATOR_POSTFIX; + } } /**