61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|||
|
|
declare(strict_types=1);
|
||
|
|
/**
|
||
|
|
*+------------------
|
||
|
|
* madong
|
||
|
|
*+------------------
|
||
|
|
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||
|
|
*+------------------
|
||
|
|
* Author: Mr. April (405784684@qq.com)
|
||
|
|
*+------------------
|
||
|
|
* Official Website: http://www.madong.tech
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace app\command\config;
|
||
|
|
|
||
|
|
use app\command\BaseCommand;
|
||
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||
|
|
use Symfony\Component\Console\Command\Command;
|
||
|
|
use Symfony\Component\Console\Helper\Table;
|
||
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
|
|
||
|
|
#[AsCommand(
|
||
|
|
name: 'madong-config:mysql',
|
||
|
|
description: '显示当前MySQL服务器配置',
|
||
|
|
aliases: ['madong-config:mysql']
|
||
|
|
)]
|
||
|
|
class ConfigMySQLCommand extends BaseCommand
|
||
|
|
{
|
||
|
|
public function __invoke(OutputInterface $output): int
|
||
|
|
{
|
||
|
|
$output->writeln('MySQL配置信息如下:');
|
||
|
|
$config = config('database');
|
||
|
|
$headers = ['name', 'default', 'driver', 'host', 'port', 'database', 'username', 'password', 'unix_socket', 'charset', 'collation', 'prefix', 'strict', 'engine', 'schema', 'sslmode'];
|
||
|
|
$rows = [];
|
||
|
|
foreach ($config['connections'] as $name => $db_config) {
|
||
|
|
$row = [];
|
||
|
|
foreach ($headers as $key) {
|
||
|
|
switch ($key) {
|
||
|
|
case 'name':
|
||
|
|
$row[] = $name;
|
||
|
|
break;
|
||
|
|
case 'default':
|
||
|
|
$row[] = $config['default'] == $name ? 'true' : 'false';
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
$row[] = $db_config[$key] ?? '';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($config['default'] == $name) {
|
||
|
|
array_unshift($rows, $row);
|
||
|
|
} else {
|
||
|
|
$rows[] = $row;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$table = new Table($output);
|
||
|
|
$table->setHeaders($headers);
|
||
|
|
$table->setRows($rows);
|
||
|
|
$table->render();
|
||
|
|
return Command::SUCCESS;
|
||
|
|
}
|
||
|
|
}
|