|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|