00001 <?php
00002
00003 require_once("GenieGate/Api/Plugin.php");
00004 require_once("GenieGate/View/Php.php");
00005
00015 class GenieGate_Controller {
00016
00020 var $CFG;
00021
00025 var $DBH;
00026
00031 var $DISPATCH = array();
00032
00036 var $APP_NAME = "Controller";
00041 var $API_VERSION = "1.0";
00042
00043 var $LISTENERS = array();
00044
00051 function GenieGate_Controller(&$conf){
00052 $this->CFG = &$conf;
00053
00054
00055 if($conf[WORKDIR]){
00056 $lib = "$conf[WORKDIR]/lib";
00057 ini_set("include_path", $lib . ":" . ini_get("include_path"));
00058 }
00059
00060 $dbc = $this->CFG[database];
00061
00062 if($dbc[PERSISTANT] ){
00063 $this->DBH = mysql_pconnect($dbc[HOST],$dbc[USER],$dbc[PASS]);
00064 }else{
00065 $this->DBH = mysql_connect($dbc[HOST],$dbc[USER],$dbc[PASS]);
00066 }
00067 if(! $this->DBH){
00068 die(mysql_errno() . " " . mysql_error());
00069 }
00070 if(! mysql_select_db($dbc[DATABASE],$this->DBH)){
00071 die(mysql_errno() . " " . mysql_error());
00072 }
00073 }
00074
00081 function addPlugins(){
00082 $php = explode(":",$this->CFG[PLUGINS]);
00083 foreach($php as $file){
00084 if(strlen($file)){
00085 require_once($file);
00086 }
00087 }
00088 }
00089
00099 function addListener(&$listener){
00100 array_push($this->LISTENERS,$listener);
00101 }
00102
00112 function getView($view_id, $params = FALSE){
00113 $dir = $this->CFG[Views][$this->APP_NAME];
00114 $vw = new GenieGate_View_Php($dir . $view_id . ".php", $dir . "shell.php");
00115 if($params){
00116 foreach($params as $p => $v){
00117 $vw->param($p,$v);
00118 }
00119 }
00120 return($vw);
00121 }
00122
00131 function run($method = FALSE) {
00132
00133 if($method){
00134 $this->fireDispatchStart("",$method);
00135 $view = $this->$method();
00136 $this->fireDispatchEnd($meth,$view);
00137 return($view);
00138 }
00139 foreach($_REQUEST as $v => $val){
00140 if(isset($this->DISPATCH[$v])){
00141 $meth = $this->DISPATCH[$v];
00142 $this->fireDispatchStart($v,$meth);
00143 $view = $this->$meth();
00144 $this->fireDispatchEnd($meth,$view);
00145 return($view);
00146 }
00147 }
00148 return(FALSE);
00149 }
00150
00154 function finish(){
00155
00156 }
00157
00164 function fireDispatchStart($trigger,$method){
00165 foreach($this->LISTENERS as $l){
00166 $l->dispatchStart($this,$trigger,$method);
00167 }
00168 }
00175 function fireDispatchEnd($method,&$view){
00176 foreach($this->LISTENERS as $l){
00177 $l->dispatchEnd($this,$method,$view);
00178 }
00179 }
00180 }
00181 ?>