| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace Heanup\Frame;
- // 引入全局常量
- use Heanup\Library\Sentry;
- require_once dirname(__DIR__) . '/constants.php';
- // 引入全局函数
- require_once dirname(__DIR__) . '/functions.php';
- // 引入自动加载
- require_once dirname(__DIR__) . '/Autoload.php';
- require_once dirname(__DIR__) . '/vendor/autoload.php';
- class Init
- {
- /**
- * 环境变量设置
- * @param $configFile
- * @return bool
- */
- public static function setEnvironment($configFile = '')
- {
- // 设置错误显示
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
- ini_set('display_errors', false);
- // 无需浏览器缓存
- header("Cache-Control: no-cache, must-revalidate");
- header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
- // 设置时区和编码
- date_default_timezone_set('Asia/Shanghai');
- setlocale(LC_ALL, 'en_US.utf-8');
- header('Content-type:text/html;charset=utf-8');
- // 设置错误捕获机制
- // set_error_handler('\Heanup\Frame\Init::errorHandler');
- // set_exception_handler('\Heanup\Frame\Init::exceptionHandler');
- // Sentry::instance()->setException();
- // 如果没有附加配置文件的话则可以结束配置了,反之,则要重新设置一些变量
- if (!$configFile || !file_exists($configFile)) {
- return true;
- }
- // 解析配置文件
- $config = parse_ini_file($configFile);
- if (!$config) {
- return true;
- }
- // 调整错误显示
- if (isset($config['display_errors'])) {
- ini_set('display_errors', intval($config['display_errors']));
- }
- // 设置日志路径
- if (isset($config['log_path'])) {
- Logger::setLogPath($config['log_path']);
- }
- // 设置日志等级
- if (isset($config['log_level'])) {
- Logger::setLogLevel(intval($config['log_level']));
- }
- // 设置环境变量
- if (isset($config['mode'])) {
- Request::setMode($config['mode']);
- }
- return true;
- }
- /**
- * 异常捕获
- * @param $ex
- */
- public static function exceptionHandler($ex)
- {
- // Sentry::instance()->exceptionHandler($ex);
- // Logger::error($ex, 'uncaught_exception');
- }
- }
|