X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Flibs%2Fempty_class.php;fp=mw%2Flibs%2Fempty_class.php;h=30814be61752fdd777d55ded10b60181d0e1a202;hb=36ed114046cbe3d72a3589230e9f306a54fcc79d;hp=0000000000000000000000000000000000000000;hpb=281c96e95451269f2614684b8de5be25862c8374;p=mtweb diff --git a/mw/libs/empty_class.php b/mw/libs/empty_class.php new file mode 100644 index 0000000..30814be --- /dev/null +++ b/mw/libs/empty_class.php @@ -0,0 +1,113 @@ +root_inst = $this; + else $this->root_inst = $root_inst; + } + + function load_modules($modules_path, $current_modules, $core_modules = null){ + $this->_load_modules($modules_path, $current_modules, $this->root_inst, true); + if(isset($core_modules) && $current_modules != $core_modules){ + $this->_load_modules($modules_path, $core_modules, $this->root_inst, true); + } + } + + function _load_modules($modules_path, $modules_path_suffixe, $root_inst, $recursif = false){ + if(file_exists($modules_path.$modules_path_suffixe) && $dh = opendir($modules_path.$modules_path_suffixe)){ + while(($file = readdir($dh)) !== false){ + if(is_dir($modules_path.$modules_path_suffixe.$file)){ + if($recursif && substr($file, 0, 1) != "."){ + $this->_load_modules($modules_path, $modules_path_suffixe.$file."/", $root_inst, $recursif); + } + } + elseif(strcasecmp(substr($file, -4), ".php") == 0){ + $this->load($modules_path.$modules_path_suffixe.$file, $root_inst); + } + } + closedir($dh); + } + } + + function load($module_file, $root_inst){ + if($module_file && file_exists($module_file)){ + $v_path = explode("/", $module_file); + $file = $v_path[count($v_path) - 1]; + if(strcasecmp(substr($file, -4), ".php") == 0){ + $class_name = substr($file, 0, -4); + if(!class_exists($class_name)){ + require_once $module_file; + if(version_compare(PHP_VERSION, '5.0.0', '>=')){ + if(class_exists($class_name) && !isset($this->modules[$class_name])){ + $this->modules[$class_name] = new $class_name($root_inst); + } + } + else{ + if(class_exists($class_name)){ + aggregate($this, $class_name); + } + } + } + } + } + } + + function __call($method_name, $arguments){ + return $this->empty_class_call($this->root_inst, $method_name, $arguments); + } + + function empty_class_call($inst, $method_name, $arguments){ + $r = false; + $args = ""; + foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]"; + if(isset($inst->modules)) foreach($inst->modules as $module_name => $module){ + if(method_exists($module, $method_name)){ + eval("\$r = \$module->".$method_name."(".$args.");"); + break; + } + else{ + $r = $this->empty_class_call($module, $method_name, $arguments); + if($r !== false) break; + } + } + return $r; + } + + } + +?> \ No newline at end of file