var $config_file;
var $config;
var $bdd;
- var $INITED;
- var $logs;
+ var $error;
var $DO_SETUP;
- function mw_app($path_file){
-
- // executer le setup si le fichier de config est absent
- $this->DO_SETUP = true;
-
+ function mw_app($path_file, $DO_SETUP = true){
+ $this->DO_SETUP = $DO_SETUP;
$this->path_file = $path_file;
$this->pathes = array();
$this->config_file = "";
$this->config = array();
$this->bdd = array();
- $this->INITED = false;
- $this->logs = array();
+ $this->error = false;
}
function set_env(&$env){
}
function init(){
- $this->INITED =
- $this->init_pathes()
- && $this->init_config()
- && $this->init_env();
- if(!$this->INITED) return false;
+ if(!$this->init_pathes()) return false;
+ if(!$this->init_config()) return false;
+ if(!$this->init_env()) return false;
if($this->config_file) return true;
- $this->setup();
+ if($this->DO_SETUP) $this->setup();
return false;
}
!$this->path_file
|| !file_exists($this->path_file)
){
- $this->log("path_file introuvable: ".$this->path_file);
+ $this->error("le fichier des chemins est introuvable");
return false;
}
require_once $this->path_file;
!isset($PATHES)
|| !is_array($PATHES)
){
- $this->log("path_file: ".$this->path_file);
- $this->log("variable PATHES non defini");
+ $this->erreur("variable PATHES non defini");
return false;
}
foreach($PATHES as $path_name => $path_value){
|| !isset($this->pathes["mw_path"])
|| !isset($this->pathes["content"])
){
- $this->log("variable PATHES incomplete");
+ $this->error("variable PATHES incomplete");
return false;
}
if(
!file_exists($this->pathes["content"])
|| !is_dir($this->pathes["content"])
){
- $this->log("dossier content introuvable: ".$this->pathes["content"]);
+ $this->error("dossier content introuvable");
return false;
}
if(!is_writable($this->pathes["content"])){
- $this->log("Php ne peut pas ecrire dans le dossier content: ".$this->pathes["content"]);
+ $this->error("Php ne peut pas ecrire dans le dossier content");
return false;
}
return true;
}
}
}
- else $this->log("pas de fichier de config: ".$config_file);
+ else{
+ if(!$this->DO_SETUP){
+ $this->error("fichier config.php manquant");
+ return false;
+ }
+ }
return true;
}
function init_env(){
- $env = false;
- $this->set_env($env);
if(
- ($sxml_class_file = (file_exists($this->pathes["mw_dir"]."libs/sxml.php") ? $this->pathes["mw_dir"]."libs/sxml.php" : ""))
- && ($empty_class_file = (file_exists($this->pathes["mw_dir"]."libs/empty_class.php") ? $this->pathes["mw_dir"]."libs/empty_class.php" : ""))
- && ($env_class_file = (file_exists($this->pathes["mw_dir"]."env/mw_env.php") ? $this->pathes["mw_dir"]."env/mw_env.php" : ""))
+ !($sxml_class_file = (file_exists($this->pathes["mw_dir"]."libs/sxml.php") ? $this->pathes["mw_dir"]."libs/sxml.php" : ""))
+ || !($empty_class_file = (file_exists($this->pathes["mw_dir"]."libs/empty_class.php") ? $this->pathes["mw_dir"]."libs/empty_class.php" : ""))
+ || !($env_class_file = (file_exists($this->pathes["mw_dir"]."env/mw_env.php") ? $this->pathes["mw_dir"]."env/mw_env.php" : ""))
){
- if(!class_exists("sxml")) require_once $sxml_class_file;
- if(!class_exists("empty_class")) require_once $empty_class_file;
- if(!class_exists("mw_env")) require_once $env_class_file;
- if(
- class_exists("sxml")
- && class_exists("empty_class")
- && class_exists("mw_env")
- ){
- $env = new mw_env(true);
- $this->set_env($env);
- $env->load_modules($this->pathes["mw_dir"], "env/modules/");
- $env->set_config_file($this->config_file);
- $env->set_PATHES($this->pathes);
- $env->init_plugins();
- $env->load_config($this->bdd, $this->config);
- $env->init();
- }
+ $this->error("des fichiers sont introuvables. impossible d'initialiser l'environnement");
+ return false;
}
- return $this->env();
+ if(!class_exists("sxml")) require_once $sxml_class_file;
+ if(!class_exists("empty_class")) require_once $empty_class_file;
+ if(!class_exists("mw_env")) require_once $env_class_file;
+ if(
+ !class_exists("sxml")
+ || !class_exists("empty_class")
+ || !class_exists("mw_env")
+ ){
+ $this->error("des classes sont introuvables. impossible d'initialiser l'environnement");
+ return false;
+ }
+ $env = new mw_env(true);
+ $this->set_env($env);
+ $env->load_modules($this->pathes["mw_dir"], "env/modules/");
+ $env->set_config_file($this->config_file);
+ $env->set_PATHES($this->pathes);
+ $env->init_plugins();
+ $env->load_config($this->bdd, $this->config);
+ $env->init();
+ return true;
}
function run($etat = "", $params = array(), $valid_role = true){
- if($this->INITED){
- $env = $this->env();
- $etat = ($etat === false ? false : ($etat ? $etat : (isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "")));
- if($etat !== false) $env->run($etat, $params, $valid_role);
- return true;
- }
- $this->log("run sans init. l'application ne s'est pas executee");
- return false;
+ $env = $this->env();
+ if(!is_callable(array($env, "run"))) return false;
+ $env->run(
+ $etat ?
+ $etat
+ : (isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : ""),
+ $params,
+ $valid_role
+ );
+ return true;
}
function display(){
}
}
- function log($content){
- $this->logs[] = array(
- "time" => date("Y-m-d H:i:s"),
- "value" => $content
- );
+ function setup(){
+ $env = $this->env();
+ $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install";
+ $env->run($etat, array(), false);
+ $this->display();
+ exit;
}
- function setup(){
- if($this->DO_SETUP){
- $env = $this->env();
- $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install";
- $env->run($etat, array(), false);
- $this->display();
- exit;
- }
+ function error($content){
+ $this->error = $content;
}
- function show_logs(){
- foreach($this->logs as $log_time => $log_value){
- $log_value = is_bool($log_value) ? "bool(".($log_value ? "true" : "false").")" : $log_value;
- echo PHP_SAPI == "cli" ?
- "\n".print_r($log_value, true)."\n"
- : "<pre>".htmlentities(print_r($log_value, true), ENT_QUOTES, "UTF-8")."</pre>";
- }
+ function show_error(){
+ echo $this->error;
}
}
-
-?>
\ No newline at end of file