From 0566d4e7e025f1abe885e28b3e334fac04fa5a97 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 30 Jul 2017 16:11:14 +0800 Subject: [PATCH] Throw exception when two plugins use the same name definition --- app/Services/PluginManager.php | 8 ++++++++ resources/lang/en/errors.yml | 3 +++ resources/lang/zh_CN/errors.yml | 3 +++ 3 files changed, 14 insertions(+) diff --git a/app/Services/PluginManager.php b/app/Services/PluginManager.php index 89f81cd4..712e1835 100644 --- a/app/Services/PluginManager.php +++ b/app/Services/PluginManager.php @@ -7,6 +7,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use App\Events\PluginWasUninstalled; use Illuminate\Filesystem\Filesystem; +use App\Exceptions\PrettyPageException; use Illuminate\Contracts\Events\Dispatcher; use App\Services\Repositories\OptionRepository; use Illuminate\Contracts\Foundation\Application; @@ -90,6 +91,13 @@ class PluginManager $plugin->setVersion(Arr::get($package, 'version')); $plugin->setEnabled($this->isEnabled($plugin->name)); + if ($plugins->has($plugin->name)) { + throw new PrettyPageException(trans('errors.plugins.duplicate', [ + 'dir1' => $plugin->getDirname(), + 'dir2' => $plugins->get($plugin->name)->getDirname() + ]), 5); + } + $plugins->put($plugin->name, $plugin); } diff --git a/resources/lang/en/errors.yml b/resources/lang/en/errors.yml index b48c0d46..f50c54b2 100644 --- a/resources/lang/en/errors.yml +++ b/resources/lang/en/errors.yml @@ -11,3 +11,6 @@ exception: detail: 'Details: :msg' message: | Whoops, looks like something went wrong. (enable APP_DEBUG in .env to see details) + +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. diff --git a/resources/lang/zh_CN/errors.yml b/resources/lang/zh_CN/errors.yml index 3e2605ee..60163f0b 100644 --- a/resources/lang/zh_CN/errors.yml +++ b/resources/lang/zh_CN/errors.yml @@ -12,3 +12,6 @@ exception: message: | 如果您是访客,这说明网站程序出现了一些错误,请您稍后再试或联系站长。 如果您是站长,请开启 .env 中的 APP_DEBUG 以查看详细信息。 + +plugins: + duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的 plugins 目录,移除其中一个插件或者使用不同的 name 属性。