webman/console 명령어 플러그인

webman/consolesymfony/console을 기반으로 합니다.

설치

composer require webman/console

지원하는 명령어

사용 방법
php webman 명령어
예: php webman version

提示
Linux 시스템에서는 ./webman 명령어로 간단하게 사용할 수 있습니다.

지원하는 명령어

version

webman 버전 번호를 출력합니다.

route:list

현재 라우트 구성을 출력합니다.

make:controller

컨트롤러 파일을 생성합니다.
예: php webman make:controller adminapp/controller/AdminController.php를 생성합니다.
예: php webman make:controller api/userapp/api/controller/UserController.php를 생성합니다.

make:model

모델 파일을 생성합니다.
예: php webman make:model adminapp/model/Admin.php를 생성합니다.
예: php webman make:model api/userapp/api/model/User.php를 생성합니다.

make:middleware

미들웨어 파일을 생성합니다.
예: php webman make:middleware Authapp/middleware/Auth.php를 생성합니다.

make:command

사용자 정의 명령어 파일을 생성합니다.
예: php webman make:command db:configapp/command/DbConfigCommand.php를 생성합니다.

plugin:create

기본 플러그인을 생성합니다.
예: php webman plugin:create --name=foo/adminconfig/plugin/foo/adminvendor/foo/admin 두 디렉토리를 생성합니다.
자세한 내용은 기본 플러그인 생성을 참조하십시오.

plugin:export

기본 플러그인을 내보냅니다.
예: php webman plugin:export --name=foo/admin
자세한 내용은 기본 플러그인 생성을 참조하십시오.

plugin:export

응용 플러그인을 내보냅니다.
예: php webman plugin:export shop
자세한 내용은 응용 플러그인을 참조하십시오.

build:phar

webman 프로젝트를 phar 파일로 패키징합니다.
자세한 내용은 phar 패키징을 참조하십시오.

build:bin

webman 프로젝트를 직접 실행 가능한 바이너리 파일로 패키징합니다.
자세한 내용은 phar 패키징을 참조하십시오.

사용자 정의 명령어

사용자는 자신의 명령어를 정의할 수 있으며, 아래는 데이터베이스 구성을 출력하는 명령어의 예입니다.

  • php webman make:command config:mysql 실행
  • app/command/ConfigMySQLCommand.php를 열어 다음과 같이 수정합니다.
<?php

namespace app\command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ConfigMySQLCommand extends Command
{
    protected static $defaultName = 'config:mysql';
    protected static $defaultDescription = '현재 MySQL 서버 구성을 표시합니다.';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $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 self::SUCCESS;
    }
}

테스트

명령줄에서 php webman config:mysql를 실행합니다.

결과는 대략 다음과 유사합니다:

+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+
| name  | default | driver | host      | port | database | username | password | unix_socket | charset | collation       | prefix | strict | engine | schema | sslmode |
+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+
| mysql | true    | mysql  | 127.0.0.1 | 3306 | mysql    | root     | ******   |             | utf8    | utf8_unicode_ci |        | 1      |        |        |         |
+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+

추가 자료 참조

http://www.symfonychina.com/doc/current/components/console.html