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(!isset($this->modules[$class_name])){ 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; if(($module = $this->get_module_for_method($inst, $method_name)) !== false){ $args = ""; foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]"; eval("\$r = \$module->".$method_name."(".$args.");"); } else $r = $this->call_default($inst, $method_name, $arguments); return $r; } function get_module_for_method($inst, $method_name){ $module = false; if(isset($inst->modules)) foreach($inst->modules as $module_name => $module_impl){ if(method_exists($module_impl, $method_name)){ $module = $module_impl; break; } else{ $module = $this->get_module_for_method($module_impl, $method_name); if($module !== false) break; } } return $module; } function call_default($inst, $method_name, $arguments){ return false; } }