function eqphp_autoload($lib_name) { $server_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $group = explode(',', config('group|info')); $rq_url = explode('/', trim($server_uri, '/')); $dir_first = array('a' => 'action', 'm' => 'model'); $dir_second = array('a' => $rq_url[0] . '/action', 'm' => $rq_url[0] . '/model'); $dir_arr = in_array($rq_url[0], $group) ? $dir_second : $dir_first; $dir_arr = array_merge($dir_arr, array('s' => 'server', 'p' => 'plugin')); $prefix = substr($lib_name, 0, strpos($lib_name, '_')); $dir_name = in_array($prefix, array_keys($dir_arr)) ? $dir_arr[$prefix] : 'class'; $execute_file = $dir_name . '/' . $lib_name . '.php'; if (strtolower($lib_name) == 'smarty') { $execute_file = 'data/smarty/Smarty.class.php'; } if (file_exists($execute_file)) { return include dc_root . $execute_file; } if ($prefix == 'a') { $tpl_file = dc_root . 'view/' . substr($lib_name, 2) . '.html'; if (file_exists($tpl_file)) { exit(include $tpl_file); } if ($execute_file != 'action/a_.php') { http::send(404, 0); http::out('404 Not Found'); } } if (strpos(strtolower($execute_file), 'smarty_internal_') === false) { echo "class [" . $lib_name . "] is error !<br>"; } }
function eqphp_autoload($class) { if (isset($_SERVER['REQUEST_URI'])) { $root = current(explode('/', trim($_SERVER['REQUEST_URI'], '/'))); } //optimize: $config save memcache or redis $group = config('group.list'); $path = isset($root) && is_array($group) && in_array($root, $group) ? $root . '/' : ''; $module = array('a' => $path . 'action', 'm' => $path . 'model', 'p' => $path . 'plugin', 's' => 'server'); $prefix = substr($class, 0, strpos($class, '_')); $dir_name = in_array($prefix, array('a', 'm', 's', 'p')) ? $module[$prefix] : 'class'; $execute_file = $dir_name . '/' . $class . '.php'; if (file_exists($execute_file)) { return include PATH_ROOT . $execute_file; } //通用加载 if (config('state.common_load') && in_array($prefix, array('a', 'm'), true)) { $common_option = array('a' => 'action/', 'm' => 'model/'); $execute_file = PATH_ROOT . $common_option[$prefix] . $class . '.php'; if (file_exists($execute_file)) { return include $execute_file; } } //贪婪加载 if (config('state.greedy_load')) { $execute_file = file::search(PATH_ROOT . $dir_name, $class, $file_list, true); if ($execute_file) { return include $execute_file; } } if ($prefix === 'a') { logger::notice('class [' . $class . '] not found'); http::send(404); } }
static function bootstrap($controller, $method) { try { if ($controller && $method) { define('CURRENT_ACTION', substr($controller . ':' . $method, 2)); if (property_exists($controller, 'static_class')) { if (method_exists($controller, '__before')) { call_user_func($controller . '::__before'); } call_user_func(array($controller, $method), explode('/', URL_REQUEST)); if (method_exists($controller, '__after')) { call_user_func($controller, '::__after'); } } else { $object = new $controller(); if (method_exists($controller, '__before')) { $object->__before(); } call_user_func_array(array($object, $method), array(explode('/', URL_REQUEST))); if (method_exists($controller, '__after')) { $object->__after(); } } } else { throw new Exception('absent controller or method', 101); } } catch (Exception $e) { logger::exception('exception', $e->getCode() . ' : ' . $e->getMessage()); if (preg_match('/^(similar|product)$/', ENVIRONMENT)) { if (http::is_ajax()) { http::json(array('error' => 4, 'message' => $e->getMessage(), 'data' => null)); } else { http::send(404); } } debug::exception($e); } }
static function tidy() { http::send(500); }