From 6448b3bbab0b6fdd600782b0a44ee6e9c2504e4b Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 24 Feb 2018 19:21:04 +0800 Subject: [PATCH] Set UTF-8 encoding for error messages --- app/Providers/AppServiceProvider.php | 5 ++++- app/helpers.php | 24 ++++++++++++++++++++---- bootstrap/autoload.php | 5 +++-- index.php | 5 +++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6da1676c..3a682558 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -53,7 +53,10 @@ class AppServiceProvider extends ServiceProvider if (class_exists($className)) { $this->app->singleton('cipher', $className); } else { - exit(sprintf("No such encrypt method: [%s], please check your .env configuration.", config('secure.cipher'))); + die_with_utf8_encoding(sprintf( + '[Error] Unsupported encryption method: < %1$s >, please check your .env configuration
'. + '[错误] 不支持的密码加密方式 < %1$s >,请检查你的 .env 配置文件' + , config('secure.cipher'))); } $this->app->singleton('users', \App\Services\Repositories\UserRepository::class); diff --git a/app/helpers.php b/app/helpers.php index cf7bd501..96972617 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -406,7 +406,7 @@ if (! function_exists('runtime_check')) { { foreach ($requirements['extensions'] as $extension) { if (! extension_loaded($extension)) { - exit( + die_with_utf8_encoding( "[Error] You have not installed the $extension extension
". "[错误] 你尚未安装 $extension 扩展!安装方法请自行搜索,蟹蟹。" ); @@ -416,16 +416,32 @@ if (! function_exists('runtime_check')) { foreach (array_get($requirements, 'write_permission', []) as $dir) { $realPath = realpath(__DIR__."/../$dir"); + if (! file_exists($realPath)) { + die_with_utf8_encoding( + "[Error] The directory < $dir > does not exist
". + "[错误] 目录 < $dir > 不存在,请在程序根目录下手动创建" + ); + } + if (! is_writable($realPath)) { - exit( - "[Error] The program lacks write permission to directory $dir
". - "[错误] 程序缺少对 $dir 目录的写权限或目录不存在,请手动授权/创建" + die_with_utf8_encoding( + "[Error] The program lacks write permission to directory < $dir >
". + "[错误] 程序缺少对 < $dir > 目录的写权限,请手动授权" ); } } } } +if (! function_exists('die_with_utf8_encoding')) { + + function die_with_utf8_encoding($error) + { + header('Content-Type: text/html; charset=UTF-8'); + exit($error); + } +} + if (! function_exists('get_db_type')) { function get_db_type($type = null) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 9ce776cf..035a1f89 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -17,9 +17,10 @@ define('LARAVEL_START', microtime(true)); if (file_exists($autoload = __DIR__.'/../vendor/autoload.php')) { require $autoload; } else { + header('Content-Type: text/html; charset=UTF-8'); exit( - "No vendor folder found. Have you installed the dependencies with composer?
". - "根目录下未发现 vendor 文件夹,请参照安装说明使用 composer 安装依赖库。" + "[Error] No vendor folder found. Have you installed the dependencies with composer?
". + "[错误] 根目录下未发现 vendor 文件夹,请使用 composer 安装依赖库。详情请阅读 http://t.cn/REyMUqA" ); } diff --git a/index.php b/index.php index d6764d43..1725bb38 100755 --- a/index.php +++ b/index.php @@ -11,9 +11,10 @@ // Check PHP version if (version_compare(PHP_VERSION, '5.5.9', '<')) { + header('Content-Type: text/html; charset=UTF-8'); exit( - '[Error] Blessing Skin Server needs PHP version >= 5.5.9, you are now using '.PHP_VERSION.'
'. - '[错误] 你的 PHP 版本过低('.PHP_VERSION.'),Blessing Skin Server 要求至少为 5.5.9' + '[Error] Blessing Skin requires PHP version >= 5.5.9, you are now using '.PHP_VERSION.'
'. + '[错误] 你的 PHP 版本过低('.PHP_VERSION.'),Blessing Skin 要求至少为 5.5.9' ); }