From 5ae53acbb95940b631aac08bec17bdbf424f2109 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 22 Jul 2018 11:10:33 +0800 Subject: [PATCH] Throw PrettyPageException when cipher is invalid --- app/Providers/AppServiceProvider.php | 21 +++++++++------------ resources/lang/en/errors.yml | 3 +++ resources/lang/zh_CN/errors.yml | 3 +++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 92f4b391..3a871108 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,7 +5,9 @@ namespace App\Providers; use Event; use Utils; use App\Events; +use ReflectionException; use Illuminate\Support\ServiceProvider; +use App\Exceptions\PrettyPageException; class AppServiceProvider extends ServiceProvider { @@ -38,6 +40,12 @@ class AppServiceProvider extends ServiceProvider $event->addContent(''); }); + + try { + $this->app->make('cipher'); + } catch (ReflectionException $e) { + throw new PrettyPageException(trans('errors.cipher.unsupported', ['cipher' => config('secure.cipher')])); + } } /** @@ -47,18 +55,7 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - // Register default cipher - $className = "App\Services\Cipher\\".config('secure.cipher'); - - if (class_exists($className)) { - $this->app->singleton('cipher', $className); - } else { - 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('cipher', 'App\Services\Cipher\\'.config('secure.cipher')); $this->app->singleton('users', \App\Services\Repositories\UserRepository::class); $this->app->singleton('parsedown', \Parsedown::class); } diff --git a/resources/lang/en/errors.yml b/resources/lang/en/errors.yml index d5791f96..5ca15e17 100644 --- a/resources/lang/en/errors.yml +++ b/resources/lang/en/errors.yml @@ -16,3 +16,6 @@ exception: plugins: duplicate: The plugin [:dir1] has a duplicated plugin name definition which is same to plugin [:dir2]. Please check your plugins directory, remove one of them or use another name definition. directory: We can't approach the path for loading plugins specified by the PLUGINS_DIR in .env file. Please check your configuration. Error :msg + +cipher: + unsupported: Unsupported encryption method `:cipher`, please check your `.env` configuration diff --git a/resources/lang/zh_CN/errors.yml b/resources/lang/zh_CN/errors.yml index ca102381..62786603 100644 --- a/resources/lang/zh_CN/errors.yml +++ b/resources/lang/zh_CN/errors.yml @@ -17,3 +17,6 @@ exception: plugins: duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的插件目录,移除其中一个插件或者使用不同的 name 属性。 directory: 配置文件 .env 中指定的插件加载目录(PLUGINS_DIR)不存在或无法打开,请检查您的配置。错误信息::msg + +cipher: + unsupported: 不支持的密码加密方式 `:cipher`,请检查你的 .env 配置文件