sgbds)) return $this->sgbds; $this->sgbds = array(); $impls_dir = $this->path("mw_dir")."env/sgbd"; if(!file_exists($impls_dir) || !is_dir($impls_dir)){ return false; } if($dh = opendir($impls_dir)){ $OK = true; while($OK && ($impl_file = readdir($dh)) !== false){ if(substr($impl_file, 0 ,1) !== "." && substr($impl_file, -4) == ".php"){ require_once $impls_dir."/".$impl_file; if(class_exists($class_name = substr($impl_file, 0, -4))){ if( method_exists($class_name, "name") && method_exists($class_name, "extention_ok") ){ $impl = new $class_name($this); if($impl->extention_ok($this)) $this->sgbds[$class_name] = $impl; } } } } } else{ return false; } return $this->sgbds; } public function load_sgbd(){ if(($data = $this->data()) && $this->bdd("sgbd")){ $sgbd_impl_file = $this->path("mw_dir")."env/sgbd/mw_".$this->bdd("sgbd").".php"; if(!file_exists($sgbd_impl_file)){ $this->erreur("Impossible de trouver le fichier d'implementation du sgbd ".$this->bdd("sgbd"), true); } $sgbd_impl = "mw_".$this->bdd("sgbd"); if(!class_exists($sgbd_impl)) require_once $sgbd_impl_file; if(!class_exists($sgbd_impl)){ $this->erreur("Impossible de trouver la classe d'implementation du sgbd ".$this->bdd("sgbd"), true); } $sgbd = new $sgbd_impl( $this, array( "host" => $this->bdd("host"), "base" => $this->bdd("base"), "user" => $this->bdd("user"), "password" => $this->bdd("password") ) ); if(!$sgbd->extention_ok()){ $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas installée", true); } $data->set_sgbd($sgbd); } } } // ------------------------------------------------------------------------------------------- // class mw_sgbd // abstract class mw_sgbd{ public $env; public $link; public $host; public $base; public $user; public $password; public $EXTENTION_OK; public function __construct($env, $params = array()){ $this->env = $env; $default_params = $this->default_params(); $params = $this->prepare_params($params); $this->host = isset($params["host"]) ? $params["host"] : $default_params["host"]; $this->base = isset($params["base"]) ? $params["base"] : $default_params["base"]; $this->user = isset($params["user"]) ? $params["user"] : $default_params["user"]; $this->password = isset($params["password"]) ? $params["password"] : $default_params["password"]; $this->EXTENTION_OK = $this->validate_extention(); } public function name(){ return ""; } public function default_params(){ return array( "host" => "", "base" => "", "user" => "", "password" => "" ); } public function prepare_params($params){ return $params; } public function validate_extention(){ return false; } public function authentication_required(){ return false; } public function get_link(){ return $this->link; } public function extention_ok(){ return $this->EXTENTION_OK; } public function replace_prefixes($content){ return ( ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ? str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $content) : $content ); } }