env = $env; $this->sql = $sql; $this->modules = array(); $this->parent = $parent; } function load($file_path) { if($file_path && file_exists($file_path)) { $v_path = explode("/", $file_path); $file = $v_path[count($v_path) - 1]; if(strcasecmp(substr($file, -4), ".php") == 0) { $class_name = substr($file, 0, -4); require_once $file_path; if(class_exists($class_name) && !$this->modules[$class_name]) { $this->modules[$class_name] = new $class_name($this->sql, $this->env, $this); } } } } function load_modules($modules_path, $recursif = false) { if($dh = opendir($modules_path)) { while(($file = readdir($dh)) !== false) { if(is_dir($modules_path.$file)) { if($recursif && substr($file, 0, 1) != ".") $this->load_modules($modules_path.$file."/", $recursif); } elseif(strcasecmp(substr($file, -4), ".php") == 0) $this->load($modules_path.$file); } closedir($dh); } } function __call($method_name, $arguments) { $root = $this; while(isset($root->parent)) $root = $root->parent; return $this->data_call($root, $method_name, $arguments); } function data_call($data_impl, $method_name, $arguments) { $r = false; $args = ""; foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]"; foreach($data_impl->modules as $module_name => $module) { if(method_exists($module, $method_name)) { eval("\$r = \$module->".$method_name."(".$args.");"); break; } else { $r = $this->data_call($module, $method_name, $arguments); if($r !== false) break; } } return $r; } } ?>