示例#1
0
 public function run()
 {
     global $config;
     session_start();
     Logger::init();
     if ($config["test"]) {
         $config["siteUrl"] = "http://127.0.0.1:8090/";
     }
     extract($config["database"]);
     $db = $config["database"];
     DAO::connect($db["dbName"], @$db["serverName"], @$db["port"], @$db["user"], @$db["password"]);
     $url = $_GET["c"];
     if (!$url) {
         $url = $config["documentRoot"];
     }
     if (StrUtils::endswith($url, "/")) {
         $url = substr($url, 0, strlen($url) - 1);
     }
     $this->urlParts = explode("/", $url);
     $u = $this->urlParts;
     $urlSize = sizeof($this->urlParts);
     if (class_exists($this->urlParts[0]) && StrUtils::startswith($this->urlParts[0], "_") === false) {
         //Construction de l'instance de la classe (1er élément du tableau)
         try {
             $obj = new $this->urlParts[0]();
             $obj->initialize();
             try {
                 switch ($urlSize) {
                     case 1:
                         $obj->index();
                         break;
                     case 2:
                         //Appel de la méthode (2ème élément du tableau)
                         if (method_exists($obj, $u[1])) {
                             $obj->{$u}[1]();
                         } else {
                             print "La méthode `{$u[1]}` n'existe pas sur le contrôleur `" . $u[0] . "`<br/>";
                         }
                         break;
                     default:
                         //Appel de la méthode en lui passant en paramètre le reste du tableau
                         $obj->{$u}[1](array_slice($u, 2));
                         break;
                 }
             } catch (\Exception $e) {
                 print "Error!: " . $e->getMessage() . "<br/>";
                 die;
             }
         } catch (\Exception $e) {
             print "Error!: " . $e->getMessage() . "<br/>";
             die;
         }
         $obj->finalize();
     } else {
         print "Le contrôleur `" . $u[0] . "` n'existe pas <br/>";
     }
 }
示例#2
0
	public function run(){
		$config=$GLOBALS["config"];
		set_error_handler(array($this, 'errorHandler'));
		$config=$GLOBALS["config"];
		try {
			if(array_key_exists("templateEngine", $config)){
				$engine=new $config["templateEngine"]();
				if ($engine instanceof TemplateEngine)
					$GLOBALS["config"]["templateEngine"]=$engine;
			}
		} catch (\Exception $e) {
			echo $e->getTraceAsString();
		}
		session_start();
		\Logger::init();
		if($config["test"]){
			$GLOBALS["config"]["siteUrl"]="http://127.0.0.1:8090/";
		}
		extract($config["database"]);
		$db=$config["database"];
		DAO::connect($db["dbName"],@$db["serverName"],@$db["port"],@$db["user"],@$db["password"]);
		$url=$_GET["c"];

		if(!$url){
			$url=$config["documentRoot"];
		}
		if(StrUtils::endswith($url, "/"))
			$url=substr($url, 0,strlen($url)-1);
		$this->urlParts=explode("/", $url);

		$u=$this->urlParts;

		if(class_exists($u[0]) && StrUtils::startswith($u[0],"_")===false){
			//Construction de l'instance de la classe (1er élément du tableau)
			try{
				if(array_key_exists("onStartup", $config)){
					if(is_callable($config['onStartup'])){
						$config["onStartup"]($u);
					}
				}
				self::runAction($u);
			}catch (\Exception $e){
				print "Error!: " . $e->getMessage() . "<br/>";
				die();
			}

		}else{
			print "Le contrôleur `".$u[0]."` n'existe pas <br/>";
		}
	}
示例#3
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     global $config;
     DAO::connect($config["database"]["dbName"]);
 }