💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] * * * * * ## 1 全局变量文件源代码(thinkphp/base.php) ~~~ define('START_TIME', microtime(true)); define('START_MEM', memory_get_usage()); define('THINK_VERSION', '5.0.0 RC1'); defined('DS') or define('DS', DIRECTORY_SEPARATOR); defined('THINK_PATH') or define('THINK_PATH', dirname(__FILE__) . DS); defined('LIB_PATH') or define('LIB_PATH', THINK_PATH . 'library' . DS); defined('EXTEND_PATH') or define('EXTEND_PATH', THINK_PATH . 'extend' . DS); defined('MODE_PATH') or define('MODE_PATH', THINK_PATH . 'mode' . DS); defined('CORE_PATH') or define('CORE_PATH', LIB_PATH . 'think' . DS); defined('ORG_PATH') or define('ORG_PATH', LIB_PATH . 'org' . DS); defined('TRAIT_PATH') or define('TRAIT_PATH', LIB_PATH . 'traits' . DS); defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS); defined('APP_NAMESPACE') or define('APP_NAMESPACE', 'app'); defined('COMMON_MODULE') or define('COMMON_MODULE', 'common'); defined('RUNTIME_PATH') or define('RUNTIME_PATH', realpath(APP_PATH) . DS . 'runtime' . DS); defined('DATA_PATH') or define('DATA_PATH', RUNTIME_PATH . 'data' . DS); defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS); defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS); defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS); defined('VENDOR_PATH') or define('VENDOR_PATH', THINK_PATH . 'vendor' . DS); defined('EXT') or define('EXT', '.php'); defined('MODEL_LAYER') or define('MODEL_LAYER', 'model'); defined('VIEW_LAYER') or define('VIEW_LAYER', 'view'); defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller'); defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); defined('APP_DEBUG') or define('APP_DEBUG', false); defined('APP_HOOK') or define('APP_HOOK', false); defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); defined('IS_API') or define('IS_API', false); defined('APP_AUTO_BUILD') or define('APP_AUTO_BUILD', false); defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', false); defined('APP_ROUTE_ON') or define('APP_ROUTE_ON', true); defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); defined('APP_MODE') or define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common'); define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0); define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0); define('IS_CLI', PHP_SAPI == 'cli' ? 1 : 0); define('IS_AJAX', (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false); define('NOW_TIME', $_SERVER['REQUEST_TIME']); define('REQUEST_METHOD', IS_CLI ? 'GET' : $_SERVER['REQUEST_METHOD']); define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); ~~~ ## 2 分析 首先使用defined检测默认全局变量是否定义,然后使用define定义默认全局变量 ## 3 总结 全局变量可以在入口文件/public/index.php中自定义。通常用来控制项目的总体架构。