* ************** * Core * ************** */ // we are using UTF-8 strings until the end of the script mb_internal_encoding('UTF-8'); // we'll be outputting UTF-8 to the browser mb_http_output('UTF-8'); // include the autoloader include_once __DIR__ . '/classes/Loader.php'; // instantiate the loader $loader = new Loader(); // register the autoloader $loader->register(); // add core classes to autoload $loader->addNamespace('', dirname(__FILE__) . '/../core/classes'); // vendor autoload if (file_exists(base_path('/vendor/autoload.php'))) { include_once base_path('/vendor/autoload.php'); } // set error/exception handlers error_reporting(E_ALL); set_error_handler([new Exceptions\Exception('error_handling'), 'errorHandler']); set_exception_handler([new Exceptions\Exception('exception_handling'), 'exceptionHandler']); /** * ************** * App * ************** */ // add app classes to autoload $loader->addNamespace('', dirname(__FILE__) . '/../app/classes');
/** * 执行应用程序 * @access public * @return void */ public static function run() { // 初始化应用(公共模块) self::initModule(COMMON_MODULE, Config::get()); // 读取扩展配置文件 if (Config::get('extra_config_list')) { foreach (Config::get('extra_config_list') as $name => $file) { $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT; Config::load($file, is_string($name) ? $name : pathinfo($file, PATHINFO_FILENAME)); } } // 获取配置参数 $config = Config::get(); // 注册根命名空间 if (!empty($config['root_namespace'])) { Loader::addNamespace($config['root_namespace']); } // 加载额外文件 if (!empty($config['extra_file_list'])) { foreach ($config['extra_file_list'] as $file) { $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT; if (is_file($file)) { include_once $file; } } } // 设置系统时区 date_default_timezone_set($config['default_timezone']); // 监听app_init APP_HOOK && Hook::listen('app_init'); // 开启多语言机制 if ($config['lang_switch_on']) { // 获取当前语言 defined('LANG_SET') or define('LANG_SET', Lang::range()); // 加载系统语言包 Lang::load(THINK_PATH . 'lang' . DS . LANG_SET . EXT); if (!APP_MULTI_MODULE) { Lang::load(APP_PATH . 'lang' . DS . LANG_SET . EXT); } } // 启动session CLI 不开启 if (!IS_CLI && $config['use_session']) { Session::init($config['session']); } if (empty(self::$dispatch['type'])) { // 未指定调度类型 则进行URL路由检测 self::route($config); } // 记录路由信息 APP_DEBUG && Log::record('[ ROUTE ] ' . var_export(self::$dispatch, true), 'info'); // 监听app_begin APP_HOOK && Hook::listen('app_begin'); // 根据类型调度 switch (self::$dispatch['type']) { case 'redirect': // 执行重定向跳转 header('Location: ' . self::$dispatch['url'], true, self::$dispatch['status']); break; case 'module': // 模块/控制器/操作 $data = self::module(self::$dispatch['module'], $config); break; case 'controller': // 执行控制器操作 $data = Loader::action(self::$dispatch['controller'], self::$dispatch['params']); break; case 'method': // 执行回调方法 $data = self::invokeMethod(self::$dispatch['method'], self::$dispatch['params']); break; case 'function': // 规则闭包 $data = self::invokeFunction(self::$dispatch['function'], self::$dispatch['params']); break; default: throw new Exception('dispatch type not support', 10008); } // 监听app_end APP_HOOK && Hook::listen('app_end', $data); // 输出数据到客户端 return Response::send($data, Response::type(), Config::get('response_return')); }
// +---------------------------------------------------------------------- // | Author: liu21st <*****@*****.**> // +---------------------------------------------------------------------- namespace think; // ThinkPHP 引导文件 // 加载基础文件 require __DIR__ . '/base.php'; require CORE_PATH . 'Loader.php'; // 注册自动加载 Loader::register(); // 加载模式定义文件 $mode = (require MODE_PATH . APP_MODE . EXT); // 加载空间别名定义 if (isset($mode['namespace'])) { Loader::addNamespace(is_array($mode['namespace']) ? $mode['namespace'] : (include $mode['namespace'])); } // 加载模式别名定义 if (isset($mode['alias'])) { Loader::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias'])); } // 注册错误和异常处理机制 Error::register(); // 加载模式配置文件 if (isset($mode['config'])) { is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']); } // 加载模式行为定义 if (APP_HOOK && isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags'])); }
$env = (include ROOT_PATH . 'env' . EXT); foreach ($env as $key => $val) { $name = ENV_PREFIX . $key; putenv("{$name}={$val}"); } } // 自动识别调试模式 if (!defined('APP_DEBUG')) { $debug = getenv(ENV_PREFIX . 'APP_DEBUG'); define('APP_DEBUG', $debug); } // 加载模式定义文件 $mode = (require MODE_PATH . APP_MODE . EXT); // 加载模式命名空间定义 if (isset($mode['namespace'])) { Loader::addNamespace($mode['namespace']); } // 注册自动加载 Loader::register(); // 加载模式别名定义 if (isset($mode['alias'])) { Loader::addMap($mode['alias']); } // 注册错误和异常处理机制 Error::register(); // 加载模式配置文件 if (isset($mode['config'])) { is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']); } // 加载模式行为定义 if (APP_HOOK && isset($mode['tags'])) {
register_shutdown_function('think\\Error::appShutdown'); set_error_handler('think\\Error::appError'); set_exception_handler('think\\Error::appException'); // 加载模式定义文件 $mode = (require MODE_PATH . APP_MODE . EXT); // 加载模式别名定义 if (isset($mode['alias'])) { Loader::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias'])); } // 加载模式配置文件 if (isset($mode['config'])) { is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']); } // 加载模式行为定义 if (APP_HOOK && isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags'])); } // 自动生成 if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) { Build::run(include APP_PATH . 'build.php'); } if (isset($mode['run'])) { call_user_func($mode['run']); } else { if (IN_UNIT_TEST) { Loader::addNamespace('tests', TEST_PATH); } else { // 执行应用 App::run(); } }
<?php /** * Created by PhpStorm. * User: qkl | QQ:80508567 Wechat:qklandy * Date: 2016/1/5 14:32 */ namespace ecui; require ECUI_PATH . 'base.php'; require ECUI_PATH . 'Loader.php'; //注册自动载入 Loader::register(); //动态注册单项目的namespace 单项目的根目录 Loader::addNamespace('app', APP_PATH); Route::dispather();