diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index c4d7d954..0fd9a521 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -7,7 +7,9 @@ use Event;
use Utils;
use App\Events;
use App\Models\User;
+use ReflectionException;
use Illuminate\Support\ServiceProvider;
+use App\Exceptions\PrettyPageException;
class AppServiceProvider extends ServiceProvider
{
@@ -40,6 +42,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')]));
+ }
}
/**
@@ -49,19 +57,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 {
- header('Content-Type: text/html; charset=UTF-8');
- exit(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 876d9e19..fce6fb0b 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 配置文件