Add .env variables for customizing the path to load plugins from
This commit is contained in:
parent
89ae8480da
commit
c45b478de2
|
|
@ -73,3 +73,6 @@ FS_DRIVER = local
|
|||
REDIS_HOST = 127.0.0.1
|
||||
REDIS_PASSWORD = null
|
||||
REDIS_PORT = 6379
|
||||
|
||||
PLUGINS_DIR = null
|
||||
PLUGINS_URL = null
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ class PluginController extends Controller
|
|||
return Datatables::of($installed)
|
||||
->setRowId('plugin-{{ $name }}')
|
||||
->editColumn('title', function ($plugin) {
|
||||
return trans($plugin->title);
|
||||
return trans($plugin->title ?: 'EMPTY');
|
||||
})
|
||||
->editColumn('description', function ($plugin) {
|
||||
return trans($plugin->description);
|
||||
return trans($plugin->description ?: 'EMPTY');
|
||||
})
|
||||
->editColumn('author', function ($plugin) {
|
||||
return ['author' => trans($plugin->author), 'url' => $plugin->url];
|
||||
return ['author' => trans($plugin->author ?: 'EMPTY'), 'url' => $plugin->url];
|
||||
})
|
||||
->addColumn('status', function ($plugin) {
|
||||
return trans('admin.plugins.status.'.($plugin->isEnabled() ? 'enabled' : 'disabled'));
|
||||
|
|
|
|||
|
|
@ -104,7 +104,9 @@ class Plugin implements Arrayable, ArrayAccess
|
|||
|
||||
public function assets($relativeUri)
|
||||
{
|
||||
return url("plugins/{$this->getDirname()}/$relativeUri");
|
||||
$baseUrl = config('plugins.url') ?: url('plugins');
|
||||
|
||||
return "$baseUrl/{$this->getDirname()}/$relativeUri";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -61,31 +61,38 @@ class PluginManager
|
|||
|
||||
$installed = [];
|
||||
|
||||
$resource = opendir(base_path('plugins'));
|
||||
try {
|
||||
$resource = opendir($this->getPluginsDir());
|
||||
} catch (\Exception $e) {
|
||||
throw new PrettyPageException(trans('errors.plugins.directory', ['msg' => $e->getMessage()]), 500);
|
||||
}
|
||||
|
||||
// traverse plugins dir
|
||||
while($filename = @readdir($resource)) {
|
||||
if ($filename == "." || $filename == "..")
|
||||
if ($filename == '.' || $filename == '..')
|
||||
continue;
|
||||
|
||||
$path = base_path('plugins')."/".$filename;
|
||||
$path = $this->getPluginsDir().DIRECTORY_SEPARATOR.$filename;
|
||||
|
||||
if (is_dir($path)) {
|
||||
if (file_exists($path."/package.json")) {
|
||||
$packageJsonPath = $path.DIRECTORY_SEPARATOR.'package.json';
|
||||
|
||||
if (file_exists($packageJsonPath)) {
|
||||
// load packages installed
|
||||
$installed[$filename] = json_decode($this->filesystem->get($path."/package.json"), true);
|
||||
$installed[$filename] = json_decode($this->filesystem->get($packageJsonPath), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir($resource);
|
||||
|
||||
foreach ($installed as $path => $package) {
|
||||
foreach ($installed as $dirname => $package) {
|
||||
|
||||
// Instantiates an Plugin object using the package path and package.json file.
|
||||
$plugin = new Plugin($this->getPluginsDir().'/'.$path, $package);
|
||||
$plugin = new Plugin($this->getPluginsDir().DIRECTORY_SEPARATOR.$dirname, $package);
|
||||
|
||||
// Per default all plugins are installed if they are registered in composer.
|
||||
$plugin->setDirname($path);
|
||||
$plugin->setDirname($dirname);
|
||||
$plugin->setInstalled(true);
|
||||
$plugin->setNameSpace(Arr::get($package, 'namespace'));
|
||||
$plugin->setVersion(Arr::get($package, 'version'));
|
||||
|
|
@ -255,7 +262,7 @@ class PluginManager
|
|||
*/
|
||||
protected function getPluginsDir()
|
||||
{
|
||||
return $this->app->basePath().'/plugins';
|
||||
return config('plugins.directory') ?: base_path('plugins');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
25
config/plugins.php
Normal file
25
config/plugins.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Plugins Directory
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The absolute path for loading plugins.
|
||||
| Defaults to `base_path()."/plugins"`.
|
||||
|
|
||||
*/
|
||||
'directory' => menv('PLUGINS_DIR'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Plugins Assets URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The URL to access plugin's assets (CSS, JavaScript etc.).
|
||||
| Defaults to `http://site_url/plugins`.
|
||||
|
|
||||
*/
|
||||
'url' => menv('PLUGINS_URL'),
|
||||
];
|
||||
|
|
@ -14,3 +14,4 @@ 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
|
||||
|
|
|
|||
|
|
@ -14,4 +14,5 @@ exception:
|
|||
如果您是站长,请开启 .env 中的 APP_DEBUG 以查看详细信息。
|
||||
|
||||
plugins:
|
||||
duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的 plugins 目录,移除其中一个插件或者使用不同的 name 属性。
|
||||
duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的插件目录,移除其中一个插件或者使用不同的 name 属性。
|
||||
directory: 配置文件 .env 中指定的插件加载目录(PLUGINS_DIR)不存在或无法打开,请检查您的配置。错误信息::msg
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user