|
@ -1,24 +1,24 @@ |
|
|
<?php |
|
|
<?php |
|
|
/** |
|
|
/** |
|
|
* Класс для работы с роутерами |
|
|
|
|
|
|
|
|
* Класс для работы с роутерами |
|
|
* |
|
|
* |
|
|
* @copyright |
|
|
|
|
|
* @link |
|
|
|
|
|
|
|
|
* @copyright |
|
|
|
|
|
* @link |
|
|
* @package Majestic |
|
|
* @package Majestic |
|
|
* @subpackage Core |
|
|
* @subpackage Core |
|
|
* @since |
|
|
|
|
|
|
|
|
* @since |
|
|
* @version SVN: $Id$ |
|
|
* @version SVN: $Id$ |
|
|
* @filesource $URL$ |
|
|
* @filesource $URL$ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
final class Router |
|
|
final class Router |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $routes = array(); |
|
|
protected $routes = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static protected $rewrite_base = ''; |
|
|
static protected $rewrite_base = ''; |
|
|
static protected $decorator = DEFAULT_DECORATOR; |
|
|
static protected $decorator = DEFAULT_DECORATOR; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Добавить роутер |
|
|
* Добавить роутер |
|
@ -55,8 +55,14 @@ final class Router |
|
|
*/ |
|
|
*/ |
|
|
function proccess($path) |
|
|
function proccess($path) |
|
|
{ |
|
|
{ |
|
|
$path = explode('/', ltrim($path, self::getRewriteBase())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($trim = self::getRewriteBase()) { |
|
|
|
|
|
if (substr($path, 0 , strlen($trim)) == $trim) { |
|
|
|
|
|
$path = substr($path, strlen($trim)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$path = explode('/', $path); |
|
|
|
|
|
|
|
|
foreach($this->routes as $name => $route) { |
|
|
foreach($this->routes as $name => $route) { |
|
|
if ($route->match($path)) { |
|
|
if ($route->match($path)) { |
|
|
$route->action .= ACTION_POSTFIX; |
|
|
$route->action .= ACTION_POSTFIX; |
|
@ -66,17 +72,17 @@ final class Router |
|
|
} |
|
|
} |
|
|
throw new Exception(E_404); |
|
|
throw new Exception(E_404); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public function setRewriteBase($value = '') |
|
|
static public function setRewriteBase($value = '') |
|
|
{ |
|
|
{ |
|
|
self::$rewrite_base = $value; |
|
|
self::$rewrite_base = $value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public function getRewriteBase() |
|
|
static public function getRewriteBase() |
|
|
{ |
|
|
{ |
|
|
return self::$rewrite_base; |
|
|
return self::$rewrite_base; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public function setDefaultDecorator($decorator) |
|
|
static public function setDefaultDecorator($decorator) |
|
|
{ |
|
|
{ |
|
|
self::$decorator = $decorator.DECORATOR_POSTFIX; |
|
|
self::$decorator = $decorator.DECORATOR_POSTFIX; |
|
|