Browse Source

rewrite base & default decorator setup

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@21 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
pzinovkin 16 years ago
parent
commit
31bd77fde0
  1. 25
      classes/Router.class.php

25
classes/Router.class.php

@ -13,8 +13,13 @@
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);
$path = explode('/', ltrim($path, self::getRewriteBase()));
foreach ($this->routes as $name => $route) {
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;
}
}
/**

Loading…
Cancel
Save