From ad9756b0b72852c82165e824570f21b039fcb359 Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Mon, 9 Jun 2014 17:32:05 +0200 Subject: [PATCH] implementations sgbd dans env/sgbd --- mw/app/controllers/install/index.php | 2 +- mw/app/data/modules/share/mw_data_sgbds.php | 35 ------- mw/app/init/0300_data.php | 22 +++-- mw/env/modules/mw_env_data.php | 68 ------------- mw/env/modules/mw_env_sgbds.php | 105 +++++++++++++++++++++ mw/{app/data/impl => env/sgbd}/mw_mysql.php | 0 mw/{app/data/impl => env/sgbd}/mw_pdo_mysql.php | 0 mw/{app/data/impl => env/sgbd}/mw_pdo_sqlite.php | 0 mw/{app/data/impl => env/sgbd}/mw_xml.php | 10 +- mw/{app/data/impl => env/sgbd}/xml/mw_xml_data.php | 0 .../impl => env/sgbd}/xml/mw_xml_data_handler.php | 0 11 files changed, 128 insertions(+), 114 deletions(-) delete mode 100644 mw/app/data/modules/share/mw_data_sgbds.php create mode 100644 mw/env/modules/mw_env_sgbds.php rename mw/{app/data/impl => env/sgbd}/mw_mysql.php (100%) rename mw/{app/data/impl => env/sgbd}/mw_pdo_mysql.php (100%) rename mw/{app/data/impl => env/sgbd}/mw_pdo_sqlite.php (100%) rename mw/{app/data/impl => env/sgbd}/mw_xml.php (92%) rename mw/{app/data/impl => env/sgbd}/xml/mw_xml_data.php (100%) rename mw/{app/data/impl => env/sgbd}/xml/mw_xml_data_handler.php (100%) diff --git a/mw/app/controllers/install/index.php b/mw/app/controllers/install/index.php index 96b917d..16cc9e4 100644 --- a/mw/app/controllers/install/index.php +++ b/mw/app/controllers/install/index.php @@ -19,7 +19,7 @@ "email" => "", "password" => "" ); - if(($sgbds = $data->sgbds()) === false){ + if(($sgbds = $env->sgbds()) === false){ $env->erreur("impossible de lister les sgbds disponibles"); return; } diff --git a/mw/app/data/modules/share/mw_data_sgbds.php b/mw/app/data/modules/share/mw_data_sgbds.php deleted file mode 100644 index c40af56..0000000 --- a/mw/app/data/modules/share/mw_data_sgbds.php +++ /dev/null @@ -1,35 +0,0 @@ -env(); - $sgbds = array(); - $impls_dir = $env->app_file("data/impl"); - 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($env); - if($impl->extention_ok($env)) $sgbds[$class_name] = $impl; - } - } - } - } - } - else{ - return false; - } - return $sgbds; - } - - } diff --git a/mw/app/init/0300_data.php b/mw/app/init/0300_data.php index 672de25..9d376e2 100644 --- a/mw/app/init/0300_data.php +++ b/mw/app/init/0300_data.php @@ -1,15 +1,16 @@ plugins("DESC")) === false){ - $this->erreur("Impossible de lire les plugins pour charger les modules de donnees", true); - } - $data = new mw_data(true); + // ------------------------------------------------------------------------- + // sgbd + // + + $sgbd_impl_file = $this->path("mw_dir")."env/sgbd/mw_".$this->bdd("sgbd").".php"; if($this->bdd("sgbd")){ - if(!$this->app_file_exists("data/impl/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 $this->app_file("data/impl/".$sgbd_impl.".php"); + 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); } @@ -26,6 +27,15 @@ $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas installée", true); } } + + // ------------------------------------------------------------------------- + // data + // + + if(($plugins = $this->plugins("DESC")) === false){ + $this->erreur("Impossible de lire les plugins pour charger les modules de donnees", true); + } + $data = new mw_data(true); foreach($plugins as $plugin_name => $plugin){ if($plugin["installed"] && $plugin["enabled"]){ $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/share/"); diff --git a/mw/env/modules/mw_env_data.php b/mw/env/modules/mw_env_data.php index 3cb19d1..7d12265 100644 --- a/mw/env/modules/mw_env_data.php +++ b/mw/env/modules/mw_env_data.php @@ -25,71 +25,3 @@ } } - - // ------------------------------------------------------------------------------------------- - // 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 - ); - } - - } diff --git a/mw/env/modules/mw_env_sgbds.php b/mw/env/modules/mw_env_sgbds.php new file mode 100644 index 0000000..dfdb74f --- /dev/null +++ b/mw/env/modules/mw_env_sgbds.php @@ -0,0 +1,105 @@ +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; + } + + } + + // ------------------------------------------------------------------------------------------- + // 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 + ); + } + + } diff --git a/mw/app/data/impl/mw_mysql.php b/mw/env/sgbd/mw_mysql.php similarity index 100% rename from mw/app/data/impl/mw_mysql.php rename to mw/env/sgbd/mw_mysql.php diff --git a/mw/app/data/impl/mw_pdo_mysql.php b/mw/env/sgbd/mw_pdo_mysql.php similarity index 100% rename from mw/app/data/impl/mw_pdo_mysql.php rename to mw/env/sgbd/mw_pdo_mysql.php diff --git a/mw/app/data/impl/mw_pdo_sqlite.php b/mw/env/sgbd/mw_pdo_sqlite.php similarity index 100% rename from mw/app/data/impl/mw_pdo_sqlite.php rename to mw/env/sgbd/mw_pdo_sqlite.php diff --git a/mw/app/data/impl/mw_xml.php b/mw/env/sgbd/mw_xml.php similarity index 92% rename from mw/app/data/impl/mw_xml.php rename to mw/env/sgbd/mw_xml.php index 67f2447..e134bec 100644 --- a/mw/app/data/impl/mw_xml.php +++ b/mw/env/sgbd/mw_xml.php @@ -36,14 +36,16 @@ } public function validate_extention(){ + $mw_xml_data_file = $this->env->path("mw_dir")."env/sgbd/xml/mw_xml_data.php"; + $mw_xml_data_handler_file = $this->env->path("mw_dir")."env/sgbd/xml/mw_xml_data_handler.php"; if( - !file_exists($this->env->app_file("data/impl/xml/mw_xml_data.php")) - || !file_exists($this->env->app_file("data/impl/xml/mw_xml_data_handler.php")) + !file_exists($mw_xml_data_file) + || !file_exists($mw_xml_data_handler_file) ){ return false; } - if(!class_exists("mw_xml_data")) require_once $this->env->app_file("data/impl/xml/mw_xml_data.php"); - if(!class_exists("mw_xml_data_handler")) require_once $this->env->app_file("data/impl/xml/mw_xml_data_handler.php"); + if(!class_exists("mw_xml_data")) require_once $mw_xml_data_file; + if(!class_exists("mw_xml_data_handler")) require_once $mw_xml_data_handler_file; if( !class_exists("mw_xml_data") || !class_exists("mw_xml_data_handler") diff --git a/mw/app/data/impl/xml/mw_xml_data.php b/mw/env/sgbd/xml/mw_xml_data.php similarity index 100% rename from mw/app/data/impl/xml/mw_xml_data.php rename to mw/env/sgbd/xml/mw_xml_data.php diff --git a/mw/app/data/impl/xml/mw_xml_data_handler.php b/mw/env/sgbd/xml/mw_xml_data_handler.php similarity index 100% rename from mw/app/data/impl/xml/mw_xml_data_handler.php rename to mw/env/sgbd/xml/mw_xml_data_handler.php -- 2.1.4