modify plugin name

This commit is contained in:
2022-06-16 17:38:22 +08:00
parent 0233acb279
commit 0051f1f15c
25 changed files with 928 additions and 1055 deletions
+90 -56
View File
@@ -10,6 +10,7 @@ use Kiri\Abstracts\Config;
use Kiri\Exception\ConfigException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -24,67 +25,100 @@ class ServerCommand extends Command
{
const ACTIONS = ['start', 'stop', 'restart'];
const ACTIONS = ['start', 'stop', 'restart'];
/**
*
*/
protected function configure()
{
$this->setName('sw:server')
->setDescription('server start|stop|reload|restart')
->addArgument('action', InputArgument::OPTIONAL, 'run action', 'start')
->addOption('daemon', 'd', InputOption::VALUE_OPTIONAL, 'is run daemonize');
}
/**
* @return void
*/
protected function configure(): void
{
$this->setName('sw:server')
->setDescription('server start|stop|reload|restart')
->addArgument('action', InputArgument::OPTIONAL, 'run action', 'start')
->addOption('daemon', 'd', InputOption::VALUE_OPTIONAL, 'is run daemonize');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \ReflectionException
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
$manager = Kiri::app()->getServer();
$manager->setDaemon((int)!is_null($input->getOption('daemon')));
$this->scan_file();
$action = $input->getArgument('action');
if (is_null($action)) {
throw new Exception('I don\'t know what I want to do.');
}
if (!in_array($action, self::ACTIONS)) {
throw new Exception('I don\'t know what I want to do.');
}
if ($action == 'restart' || $action == 'stop') {
$manager->shutdown();
if ($action == 'stop') {
return 1;
}
}
$manager->start();
return 1;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
return match ($input->getArgument('action')) {
'restart' => $this->restart($input),
'stop' => $this->stop(),
'start' => $this->start($input),
default =>
throw new Exception('I don\'t know what I want to do.')
};
}
/**
* @return void
* @throws ConfigException
* @throws \ReflectionException
*/
protected function scan_file(): void
{
$config = Config::get('reload.scanner', []);
if (is_array($config)) foreach ($config as $key => $value) {
scan_directory($value, $key);
}
}
/**
* @param InputInterface $input
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
protected function restart(InputInterface $input): int
{
$this->stop();
$this->start($input);
return 1;
}
/**
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function stop(): int
{
$manager = Kiri::app()->getServer();
$manager->shutdown();
return 1;
}
/**
* @param InputInterface $input
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
protected function start(InputInterface $input): int
{
$this->scan_file();
$manager = Kiri::app()->getServer();
$manager->setDaemon((int)!is_null($input->getOption('daemon')));
$manager->start();
return 1;
}
/**
* @return void
* @throws ConfigException
* @throws ReflectionException
*/
protected function scan_file(): void
{
$config = Config::get('reload.scanner', []);
if (is_array($config)) foreach ($config as $key => $value) {
scan_directory($value, $key);
}
}
}