mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 10:41:40 +09:00
Revert "singleton 객체를 사용하는 대신에 static method로 변경"
This reverts commit 9cbad3147b.
This commit is contained in:
parent
cece2c6b4a
commit
b62fce5948
2 changed files with 88 additions and 51 deletions
|
|
@ -369,7 +369,8 @@ class Context
|
|||
// If using rewrite module, initializes router
|
||||
if($this->allow_rewrite)
|
||||
{
|
||||
Router::proc();
|
||||
$oRouter = Router::getInstance();
|
||||
$oRouter->proc();
|
||||
}
|
||||
|
||||
// set locations for javascript use
|
||||
|
|
@ -1574,9 +1575,10 @@ class Context
|
|||
'act.document_srl.key.mid.vid' => ($act == 'trackback') ? "$vid/$mid/$srl/$key/$act" : ''
|
||||
);
|
||||
|
||||
Router::setMap($target_map);
|
||||
$oRouter = Router::getInstance();
|
||||
$oRouter->setMap($target_map);
|
||||
|
||||
$query = Router::makePrettyUrl($target);
|
||||
$query = $oRouter->makePrettyUrl($target);
|
||||
}
|
||||
|
||||
if(!$query)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@
|
|||
*/
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* Singleton
|
||||
* @var object
|
||||
*/
|
||||
private static $theInstance = null;
|
||||
|
||||
/**
|
||||
* URI Segments
|
||||
* @var array
|
||||
|
|
@ -16,45 +22,35 @@ class Router
|
|||
* Routes
|
||||
* @var array
|
||||
*/
|
||||
private static $routes = array(
|
||||
// rss , blogAPI
|
||||
'(rss|atom)' => array('module' => 'rss', 'act' => '$1'),
|
||||
'([a-zA-Z0-9_]+)/(rss|atom|api)' => array('mid' => '$1', 'act' => '$2'),
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/(rss|atom|api)' => array('vid' => '$1', 'mid' => '$2', 'act' => '$3'),
|
||||
// trackback
|
||||
'([0-9]+)/(.+)/trackback' => array('document_srl' => '$1', 'key' => '$2', 'act' => 'trackback'),
|
||||
'([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback' => array('mid' => '$1', 'document_srl' => '$2', 'key' => '$3', 'act' => 'trackback'),
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback' => array('vid' => '$1', 'mid' => '$2', 'document_srl' => '$3' , 'key' => '$4', 'act' => 'trackback'),
|
||||
// mid
|
||||
'([a-zA-Z0-9_]+)/?' => array('mid' => '$1'),
|
||||
// mid + document_srl
|
||||
'([a-zA-Z0-9_]+)/([0-9]+)' => array('mid' => '$1', 'document_srl' => '$2'),
|
||||
// vid + mid
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/' => array('vid' => '$1', 'mid' => '$2'),
|
||||
// vid + mid + document_srl
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([0-9]+)?' => array('vid' => '$1', 'mid' => '$2', 'document_srl' => '$3'),
|
||||
// document_srl
|
||||
'([0-9]+)' => array('document_srl' => '$1'),
|
||||
// mid + entry title
|
||||
'([a-zA-Z0-9_]+)/entry/(.+)' => array('mid' => '$1', 'entry' => '$2'),
|
||||
// vid + mid + entry title
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/entry/(.+)' => array('vid' => '$1', 'mid' => '$2', 'entry' => '$3'),
|
||||
// shop / vid / [category|product] / identifier
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\.-]+)' => array('act' => 'route', 'vid' => '$1', 'type' => '$2', 'identifier'=> '$3')
|
||||
);
|
||||
private $routes = array();
|
||||
|
||||
/**
|
||||
* Rewrite map
|
||||
* @var array
|
||||
*/
|
||||
private static $rewrite_map = array();
|
||||
private $rewrite_map = array();
|
||||
|
||||
/**
|
||||
* @brief returns static context object (Singleton). It's to use Router without declaration of an object
|
||||
* @return object Instance
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if(!isset(self::$theInstance))
|
||||
{
|
||||
self::$theInstance = new Router();
|
||||
}
|
||||
|
||||
return self::$theInstance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Applys routes.
|
||||
* @see This function should be called only once
|
||||
* @return void
|
||||
*/
|
||||
public static function proc()
|
||||
public function proc()
|
||||
{
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
|
||||
|
|
@ -85,9 +81,39 @@ class Router
|
|||
unset(self::$segments[0]);
|
||||
}
|
||||
|
||||
if(isset(self::$routes[$path]))
|
||||
$self = Router::getInstance();
|
||||
|
||||
// Set default routes
|
||||
$self->routes = array(
|
||||
// rss , blogAPI
|
||||
'(rss|atom)' => array('module' => 'rss', 'act' => '$1'),
|
||||
'([a-zA-Z0-9_]+)/(rss|atom|api)' => array('mid' => '$1', 'act' => '$2'),
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/(rss|atom|api)' => array('vid' => '$1', 'mid' => '$2', 'act' => '$3'),
|
||||
// trackback
|
||||
'([0-9]+)/(.+)/trackback' => array('document_srl' => '$1', 'key' => '$2', 'act' => 'trackback'),
|
||||
'([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback' => array('mid' => '$1', 'document_srl' => '$2', 'key' => '$3', 'act' => 'trackback'),
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback' => array('vid' => '$1', 'mid' => '$2', 'document_srl' => '$3' , 'key' => '$4', 'act' => 'trackback'),
|
||||
// mid
|
||||
'([a-zA-Z0-9_]+)/?' => array('mid' => '$1'),
|
||||
// mid + document_srl
|
||||
'([a-zA-Z0-9_]+)/([0-9]+)' => array('mid' => '$1', 'document_srl' => '$2'),
|
||||
// vid + mid
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/' => array('vid' => '$1', 'mid' => '$2'),
|
||||
// vid + mid + document_srl
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([0-9]+)?' => array('vid' => '$1', 'mid' => '$2', 'document_srl' => '$3'),
|
||||
// document_srl
|
||||
'([0-9]+)' => array('document_srl' => '$1'),
|
||||
// mid + entry title
|
||||
'([a-zA-Z0-9_]+)/entry/(.+)' => array('mid' => '$1', 'entry' => '$2'),
|
||||
// vid + mid + entry title
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/entry/(.+)' => array('vid' => '$1', 'mid' => '$2', 'entry' => '$3'),
|
||||
// shop / vid / [category|product] / identifier
|
||||
'([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\.-]+)' => array('act' => 'route', 'vid' => '$1', 'type' => '$2', 'identifier'=> '$3'),
|
||||
);
|
||||
|
||||
if(isset($self->routes[$path]))
|
||||
{
|
||||
foreach(self::$routes[$path] as $key => $val)
|
||||
foreach($self->routes[$path] as $key => $val)
|
||||
{
|
||||
$val = preg_replace('#^\$([0-9]+)$#e', '\$matches[$1]', $val);
|
||||
|
||||
|
|
@ -98,7 +124,7 @@ class Router
|
|||
}
|
||||
|
||||
// Apply routes
|
||||
foreach(self::$routes as $regex => $query)
|
||||
foreach($self->routes as $regex => $query)
|
||||
{
|
||||
if(preg_match('#^' . $regex . '$#', $path, $matches))
|
||||
{
|
||||
|
|
@ -117,9 +143,10 @@ class Router
|
|||
* @param array $map
|
||||
* @return void
|
||||
*/
|
||||
public static function setMap($map)
|
||||
public function setMap($map)
|
||||
{
|
||||
self::$rewrite_map = array_merge(self::$rewrite_map, $map);
|
||||
$self = Router::getInstance();
|
||||
$self->rewrite_map = array_merge($self->rewrite_map, $map);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -128,9 +155,10 @@ class Router
|
|||
* @param array $query
|
||||
* @return void
|
||||
*/
|
||||
public static function add($target, $query)
|
||||
public function add($target, $query)
|
||||
{
|
||||
self::$routes[$target] = $query;
|
||||
$self = Router::getInstance();
|
||||
$self->routes[$target] = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,7 +168,8 @@ class Router
|
|||
*/
|
||||
public function adds($routes)
|
||||
{
|
||||
self::$routes = array_merge(self::$routes, $routes);
|
||||
$self = Router::getInstance();
|
||||
$self->routes = array_merge($self->routes, $routes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,9 +177,10 @@ class Router
|
|||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public static function getSegment($index)
|
||||
public function getSegment($index)
|
||||
{
|
||||
return self::$segments[$index];
|
||||
$self = Router::getInstance();
|
||||
return $self->segments[$index];
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -159,9 +189,10 @@ class Router
|
|||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public static function getSegments()
|
||||
public function getSegments()
|
||||
{
|
||||
return self::$segments;
|
||||
$self = Router::getInstance();
|
||||
return $self->segments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,18 +200,20 @@ class Router
|
|||
* @param string $regex
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoute($regex)
|
||||
public function getRoute($regex)
|
||||
{
|
||||
return self::$routes[$regex];
|
||||
$self = Router::getInstance();
|
||||
return $self->routes[$regex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get routes list
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoutes()
|
||||
public function getRoutes()
|
||||
{
|
||||
return self::$routes;
|
||||
$self = Router::getInstance();
|
||||
return $self->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,9 +221,10 @@ class Router
|
|||
* @param string $regex
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isExistsRoute($regex)
|
||||
public function isExistsRoute($regex)
|
||||
{
|
||||
return isset(self::$routes[$regex]);
|
||||
$self = Router::getInstance();
|
||||
return isset($self->routes[$regex]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,8 +232,9 @@ class Router
|
|||
* @param string $regex
|
||||
* @return string
|
||||
*/
|
||||
public static function makePrettyUrl($regex)
|
||||
public function makePrettyUrl($regex)
|
||||
{
|
||||
return self::$rewrite_map[$regex];
|
||||
$self = Router::getInstance();
|
||||
return $self->rewrite_map[$regex];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue