[1] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class data |
---|
| 4 | { |
---|
| 5 | public $env; |
---|
| 6 | public $sql; |
---|
| 7 | public $modules; |
---|
| 8 | |
---|
| 9 | public $parent; |
---|
| 10 | |
---|
| 11 | function __construct($sql, $env, $parent = null) |
---|
| 12 | { $this->env = $env; |
---|
| 13 | $this->sql = $sql; |
---|
| 14 | $this->modules = array(); |
---|
| 15 | $this->parent = $parent; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | function load($file_path) |
---|
| 19 | { if($file_path && file_exists($file_path)) |
---|
| 20 | { $v_path = explode("/", $file_path); |
---|
| 21 | $file = $v_path[count($v_path) - 1]; |
---|
| 22 | if(strcasecmp(substr($file, -4), ".php") == 0) |
---|
| 23 | { $class_name = substr($file, 0, -4); |
---|
| 24 | require_once $file_path; |
---|
| 25 | if(class_exists($class_name) && !$this->modules[$class_name]) |
---|
| 26 | { $this->modules[$class_name] = new $class_name($this->sql, $this->env, $this); |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | function load_modules($modules_path, $recursif = false) |
---|
| 33 | { if($dh = opendir($modules_path)) |
---|
| 34 | { while(($file = readdir($dh)) !== false) |
---|
| 35 | { if(is_dir($modules_path.$file)) |
---|
| 36 | { if($recursif && substr($file, 0, 1) != ".") $this->load_modules($modules_path.$file."/", $recursif); |
---|
| 37 | } |
---|
| 38 | elseif(strcasecmp(substr($file, -4), ".php") == 0) $this->load($modules_path.$file); |
---|
| 39 | } |
---|
| 40 | closedir($dh); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | function __call($method_name, $arguments) |
---|
| 45 | { $root = $this; |
---|
| 46 | while(isset($root->parent)) $root = $root->parent; |
---|
| 47 | return $this->data_call($root, $method_name, $arguments); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function data_call($data_impl, $method_name, $arguments) |
---|
| 51 | { $r = false; |
---|
| 52 | $args = ""; |
---|
| 53 | foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]"; |
---|
| 54 | foreach($data_impl->modules as $module_name => $module) |
---|
| 55 | { if(method_exists($module, $method_name)) |
---|
| 56 | { eval("\$r = \$module->".$method_name."(".$args.");"); |
---|
| 57 | break; |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { $r = $this->data_call($module, $method_name, $arguments); |
---|
| 61 | if($r !== false) break; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | return $r; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | ?> |
---|