function load($namespace) { $path_args = explode('\\', $namespace); $path_count = count($path_args); $ns_path = explode('\\', $namespace); //define BASE in your root path for ($i = 0; $i < $path_count; $i++) { $ns_path .= $path_args[$i]; if (!($i + 1 == $path_count)) { $ns_path .= '/'; } } $loc = $ns_path; if (is_dir($loc) && !is_dir($loc . '.php')) { //Requre all files in directory ending with ".php" $scripts = array(); //glob is faster than readdir etc, so why not! foreach (glob($loc . '/*.php') as $f) { $scripts[] = $f; } if (is_array($scripts) && count($scripts) > 0) { foreach ($scripts as $f) { loadPath($loc . $f); } } return; } loadPath($loc . '.php'); return; }
/** * 初始化工作 * */ public function initApplication() { do { // 配置检查 $appConfigs = array('logger', 'bootstrap'); foreach ($appConfigs as $config) { if (loadPath($config) === false) { exit('missing basic config ' . $config); } } } while (0); }
<?php Fx::context()->path = loadPath(Fx::context()->selfId); $struct_db = Fx::db()->find(Fx::service_context()->namespace['struct_db']); Fx::context()->struct_db = array(); foreach ($struct_db as $v) { Fx::context()->struct_db[$v['code']] = $v; } // Левое меню Fx::context()->leftMenu = ''; // Формируем левое меню class Path { public $result = array(); function __construct($path) { $this->path = $path; $this->rec(0); $this->result = implode('', $this->result); } public function find($a, $b = array(), $callback = null) { return Fx::db()->find($a, $b, $callback); } public function perform($a, $b) { return Fx::db()->extract(Fx::db()->go(array('event' => 'find', 'from' => $a, 'where' => $b, 'order' => 'num'))); } private function rec($id) { $find = $this->perform(Fx::service_context()->namespace['construct_db'], array('parent' => $id));