base.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. define('THINK_VERSION', '5.0.25');
  12. define('THINK_START_TIME', microtime(true));
  13. define('THINK_START_MEM', memory_get_usage());
  14. define('EXT', '.php');
  15. define('DS', DIRECTORY_SEPARATOR);
  16. defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS);
  17. define('LIB_PATH', THINK_PATH . 'library' . DS);
  18. define('CORE_PATH', LIB_PATH . 'think' . DS);
  19. define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
  20. defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
  21. defined('ROOT_PATH') or define('ROOT_PATH', dirname(realpath(APP_PATH)) . DS);
  22. defined('EXTEND_PATH') or define('EXTEND_PATH', ROOT_PATH . 'extend' . DS);
  23. defined('VENDOR_PATH') or define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
  24. defined('RUNTIME_PATH') or define('RUNTIME_PATH', ROOT_PATH . 'runtime' . DS);
  25. defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS);
  26. defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS);
  27. defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
  28. defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
  29. defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
  30. defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀
  31. // 环境常量
  32. define('IS_CLI', PHP_SAPI == 'cli' ? true : false);
  33. define('IS_WIN', strpos(PHP_OS, 'WIN') !== false);
  34. // 载入Loader类
  35. require CORE_PATH . 'Loader.php';
  36. // 加载环境变量配置文件
  37. if (is_file(ROOT_PATH . '.env')) {
  38. $env = parse_ini_file(ROOT_PATH . '.env', true);
  39. foreach ($env as $key => $val) {
  40. $name = ENV_PREFIX . strtoupper($key);
  41. if (is_array($val)) {
  42. foreach ($val as $k => $v) {
  43. $item = $name . '_' . strtoupper($k);
  44. putenv("$item=$v");
  45. }
  46. } else {
  47. putenv("$name=$val");
  48. }
  49. }
  50. }
  51. // 注册自动加载
  52. \think\Loader::register();
  53. // 注册错误和异常处理机制
  54. \think\Error::register();
  55. // 加载惯例配置文件
  56. \think\Config::set(include THINK_PATH . 'convention' . EXT);