mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-08 09:00:58 +08:00
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Nexus\Plugin\BasePlugin;
|
|
|
|
class Plugin extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'plugin {action} {name}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Plugin management, arguments: action plugin';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$plugin = new \Nexus\Plugin\Plugin();
|
|
$action = $this->argument('action');
|
|
$name = $this->argument('name');
|
|
/** @var BasePlugin $mainClass */
|
|
$mainClass = $plugin->getMainClass($name);
|
|
if (!$mainClass) {
|
|
$this->error("Can not find plugin: $name");
|
|
return 1;
|
|
}
|
|
try {
|
|
$mainClass->checkMainApplicationVersion();
|
|
} catch (\Exception $exception) {
|
|
$this->error($exception->getMessage());
|
|
return 1;
|
|
}
|
|
if ($action == 'install') {
|
|
call_user_func([$mainClass, 'install']);
|
|
} elseif ($action == 'uninstall') {
|
|
call_user_func([$mainClass, 'uninstall']);
|
|
} else {
|
|
$this->error("Not support action: $action");
|
|
return 1;
|
|
}
|
|
$log = sprintf("[%s], %s plugin: %s successfully !", nexus()->getRequestId(), $action, $name);
|
|
$this->info($log);
|
|
do_log($log);
|
|
return 0;
|
|
}
|
|
}
|