Code refactoring, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@114 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
65
app/router/Router.php
Normal file
65
app/router/Router.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage app
|
||||
* @since 2010-02-25
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class Router
|
||||
{
|
||||
|
||||
protected $routes = array();
|
||||
|
||||
protected $route_name;
|
||||
|
||||
protected $default_layout = 'Default';
|
||||
|
||||
/**
|
||||
* @var Route
|
||||
*/
|
||||
protected $route;
|
||||
|
||||
public function add($name, $route, $action, $params = null, $layout = null)
|
||||
{
|
||||
if (! $layout) {
|
||||
$layout = $this->default_layout;
|
||||
}
|
||||
$this->routes[$name] = new Route($route, $action, $params, $layout);
|
||||
}
|
||||
|
||||
public function route($request)
|
||||
{
|
||||
$req = explode('/', trim($request, '/'));
|
||||
|
||||
foreach ($this->routes as $name => $route) {
|
||||
if ($route->match($req)) {
|
||||
$this->route_name = $route;
|
||||
$this->route = $route;
|
||||
return $this->route;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setDefaultLayout($layout = 'Default')
|
||||
{
|
||||
$this->default_layout = $layout;
|
||||
}
|
||||
|
||||
public function getRouteName()
|
||||
{
|
||||
return $this->route_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Route
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
return $this->route;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user