From: x2000habouzit Date: Thu, 13 Jul 2006 21:23:17 +0000 (+0000) Subject: simplify class, put the search for hook in a separate function , to be able to reuse... X-Git-Tag: xorg/0.9.11~436 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=7c6e0aff436315e844c17e13ab470be86ee60694;p=platal.git simplify class, put the search for hook in a separate function , to be able to reuse that on X.net more easily git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@464 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/classes/Platal.php b/classes/Platal.php index 92604db..68c7f81 100644 --- a/classes/Platal.php +++ b/classes/Platal.php @@ -45,16 +45,9 @@ class Platal $this->__mods[$module] =& $m; $this->__hooks += $m->handlers(); } - - krsort($this->__hooks); - } - - function load_class($cls) - { - require_once dirname(__FILE__).'/../classes/'.$cls.'.php'; } - function call_hook(&$page) + function find_hook() { $p = $this->path; @@ -64,24 +57,38 @@ class Platal $p = substr($p, 0, strrpos($p, '/')); } + if (empty($this->__hooks[$p])) { - return PL_NOT_FOUND; + return null; } $hook = $this->__hooks[$p]; if (!is_callable($hook['hook'])) { + return null; + } + + $this->argv = explode('/', substr($this->path, strlen($p))); + $this->argv[0] = $p; + + return $hook; + } + + function call_hook(&$page) + { + $hook = $this->find_hook(); + + if (is_null($hook)) { return PL_NOT_FOUND; } - $args = explode('/', substr($this->path, strlen($p))); - $args[0] = $p; - $this->argv = $args; - $args[0] = &$page; + $args = $this->argv; + $args[0] = &$page; if ($hook['auth'] > Session::get('auth', AUTH_PUBLIC)) { $_SESSION['session']->doAuth($page); } + return call_user_func_array($hook['hook'], $args); }