Allow to enable or disable a plugin via CLI

This commit is contained in:
Pig Fang 2019-08-08 23:03:48 +08:00
parent aa635c16af
commit c281a444f0
7 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Console\Commands;
use App\Services\PluginManager;
use Illuminate\Console\Command;
class DisablePlugin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'plugin:disable {name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Disable a plugin';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(PluginManager $plugins)
{
$plugins->disable($this->argument('name'));
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Console\Commands;
use App\Services\PluginManager;
use Illuminate\Console\Command;
class EnablePlugin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'plugin:enable {name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enable a plugin';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(PluginManager $plugins)
{
$plugins->enable($this->argument('name'));
}
}

View File

@ -19,5 +19,7 @@ class Kernel extends ConsoleKernel
Commands\MigrateCloset::class,
Commands\ExecuteInstallation::class,
Commands\RegressLikesField::class,
Commands\EnablePlugin::class,
Commands\DisablePlugin::class,
];
}

View File

@ -1,6 +1,8 @@
## Added
- Plugin system: `config.blade.php` as default config file name.
- Allow to enable a plugin by running `php artisan plugin:enable {name}`.
- Allow to disable a plugin by running `php artisan plugin:disable {name}`.
## Tweaked

View File

@ -1,6 +1,8 @@
## 新增
- 插件系统:`config.blade.php` 为默认情况下配置视图文件名
- 支持以 `php artisan plugin:enable {name}` 的方式开启插件
- 支持以 `php artisan plugin:disable {name}` 的方式关闭插件
## 调整

View File

@ -0,0 +1,16 @@
<?php
namespace Tests;
use App\Services\PluginManager;
class DisablePluginTest extends TestCase
{
public function testDisablePlugin()
{
$this->mock(PluginManager::class, function ($mock) {
$mock->shouldReceive('disable')->with('my-plugin')->once();
});
$this->artisan('plugin:disable my-plugin');
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Tests;
use App\Services\PluginManager;
class EnablePluginTest extends TestCase
{
public function testEnablePlugin()
{
$this->mock(PluginManager::class, function ($mock) {
$mock->shouldReceive('enable')->with('my-plugin')->once();
});
$this->artisan('plugin:enable my-plugin');
}
}