webman/console コマンドラインプラグイン
webman/console
は symfony/console
に基づいています。
インストール
composer require webman/console
サポートされているコマンド
使用方法
php webman コマンド
例えば php webman version
ヒント
linux システムでは./webman コマンド
に簡略化できます。
サポートされているコマンド
version
webman のバージョン番号を表示します。
route:list
現在のルート設定を表示します。
make:controller
コントローラファイルを作成します。
例えば php webman make:controller admin
は app/controller/AdminController.php
を作成します。
例えば php webman make:controller api/user
は app/api/controller/UserController.php
を作成します。
make:model
モデルファイルを作成します。
例えば php webman make:model admin
は app/model/Admin.php
を作成します。
例えば php webman make:model api/user
は app/api/model/User.php
を作成します。
make:middleware
ミドルウェアファイルを作成します。
例えば php webman make:middleware Auth
は app/middleware/Auth.php
を作成します。
make:command
カスタムコマンドファイルを作成します。
例えば php webman make:command db:config
は app\command\DbConfigCommand.php
を作成します。
plugin:create
基本プラグインを作成します。
例えば php webman plugin:create --name=foo/admin
は config/plugin/foo/admin
と vendor/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