Use a router singleton
This commit is contained in:
parent
fbecbcb693
commit
bba1dbdb40
|
@ -51,7 +51,7 @@ function main() {
|
|||
|
||||
$path = getPath($_REQUEST);
|
||||
|
||||
$r = new Router();
|
||||
$r = Router::get();
|
||||
|
||||
$args = $r->map($path);
|
||||
|
||||
|
|
|
@ -48,6 +48,15 @@ require_once 'Net/URL/Mapper.php';
|
|||
class Router
|
||||
{
|
||||
static $m = null;
|
||||
static $inst = null;
|
||||
|
||||
static function get()
|
||||
{
|
||||
if (!Router::$inst) {
|
||||
Router::$inst = new Router();
|
||||
}
|
||||
return Router::$inst;
|
||||
}
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
@ -344,7 +353,7 @@ class Router
|
|||
$action_arg = array('action' => $action);
|
||||
|
||||
if ($args) {
|
||||
$args = array_merge($args, $action_arg);
|
||||
$args = array_merge($action_arg, $args);
|
||||
} else {
|
||||
$args = $action_arg;
|
||||
}
|
||||
|
|
|
@ -669,8 +669,12 @@ function common_relative_profile($sender, $nickname, $dt=null)
|
|||
|
||||
function common_local_url($action, $args=null, $fragment=null)
|
||||
{
|
||||
$r = new Router();
|
||||
common_debug("Action = $action, args = " . (($args) ? '(' . implode($args, ',') . ')' : $args) . ", fragment = $fragment");
|
||||
$r = Router::get();
|
||||
$start = microtime();
|
||||
$path = $r->build($action, $args, $fragment);
|
||||
$end = microtime();
|
||||
common_debug("Pathbuilding took " . ($end - $start));
|
||||
if ($path) {
|
||||
}
|
||||
if (common_config('site','fancy')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user