国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman/console 命令行插件

webman/console 基于 symfony/console

安裝

composer require webman/console

支持的命令

使用方法
php webman 命令
例如 php webman version

提示
linux系統(tǒng)下可簡化為 ./webman 命令

支持的命令

version

打印webman版本號

route:list

打印當(dāng)前路由配置

make:controller

創(chuàng)建一個(gè)控制器文件
例如 php webman make:controller admin 將創(chuàng)建一個(gè) app/controller/AdminController.php
例如 php webman make:controller api/user 將創(chuàng)建一個(gè) app/api/controller/UserController.php

make:model

創(chuàng)建一個(gè)model文件
例如 php webman make:model admin 將創(chuàng)建一個(gè) app/model/Admin.php
例如 php webman make:model api/user 將創(chuàng)建一個(gè) app/api/model/User.php

make:middleware

創(chuàng)建一個(gè)中間件文件
例如 php webman make:middleware Auth 將創(chuàng)建一個(gè) app/middleware/Auth.php

make:command

創(chuàng)建自定義命令文件
例如 php webman make:command db:config 將創(chuàng)建一個(gè) app\command\DbConfigCommand.php

plugin:create

創(chuàng)建一個(gè)基礎(chǔ)插件
例如 php webman plugin:create --name=foo/admin 將創(chuàng)建config/plugin/foo/adminvendor/foo/admin 兩個(gè)目錄
參見創(chuàng)建基礎(chǔ)插件

plugin:export

導(dǎo)出基礎(chǔ)插件
例如 php webman plugin:export --name=foo/admin
參見創(chuàng)建基礎(chǔ)插件

plugin:export

導(dǎo)出應(yīng)用插件
例如 php webman plugin:export shop
參見應(yīng)用插件

phar:pack

將webman項(xiàng)目打包成phar文件
參見phar打包

自定義命令

用戶可以定義自己的命令,例如以下是打印數(shù)據(jù)庫配置的命令

  • 執(zhí)行 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 = '顯示當(dāng)前MySQL服務(wù)器配置';

    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;
    }
}

測試

命令行運(yùn)行 php webman config:mysql

結(jié)果類似如下:

+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+
| 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

編輯于2025-02-06 21:20:07 完善本頁 +發(fā)起討論
贊助商