webman/console Befehlszeilen-Plugin

webman/console basiert auf symfony/console

Installation

composer require webman/console

Unterstützte Befehle

Verwendung
php webman Befehl
Beispiel php webman version

Hinweis
Unter Linux-Systemen kann es vereinfacht werden zu ./webman Befehl

Unterstützte Befehle

version

Gibt die webman-Version aus

route:list

Gibt die aktuelle Routen-Konfiguration aus

make:controller

Erstellt eine Controller-Datei
Beispiel php webman make:controller admin erstellt eine app/controller/AdminController.php
Beispiel php webman make:controller api/user erstellt eine app/api/controller/UserController.php

make:model

Erstellt eine Model-Datei
Beispiel php webman make:model admin erstellt eine app/model/Admin.php
Beispiel php webman make:model api/user erstellt eine app/api/model/User.php

make:middleware

Erstellt eine Middleware-Datei
Beispiel php webman make:middleware Auth erstellt eine app/middleware/Auth.php

make:command

Erstellt eine benutzerdefinierte Befehlsdatei
Beispiel php webman make:command db:config erstellt eine app\command\DbConfigCommand.php

plugin:create

Erstellt ein Basis-Plugin
Beispiel php webman plugin:create --name=foo/admin erstellt die Verzeichnisse config/plugin/foo/admin und vendor/foo/admin
Siehe Basis-Plugin erstellen

plugin:export

Exportiert das Basis-Plugin
Beispiel php webman plugin:export --name=foo/admin
Siehe Basis-Plugin erstellen

plugin:export

Exportiert das Anwendungs-Plugin
Beispiel php webman plugin:export shop
Siehe Anwendungs-Plugins

build:phar

Packt das webman-Projekt in eine phar-Datei
Siehe phar-Paketierung

build:bin

Packt das webman-Projekt in eine ausführbare Binärdatei
Siehe phar-Paketierung

Benutzerdefinierte Befehle

Benutzer können ihre eigenen Befehle definieren, zum Beispiel der folgende Befehl gibt die Datenbankkonfiguration aus

  • Führen Sie php webman make:command config:mysql aus
  • Öffnen Sie app/command/ConfigMySQLCommand.php und ändern Sie es wie folgt
<?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 = 'Zeigt die aktuelle MySQL-Server-Konfiguration an';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('MySQL-Konfigurationsinformationen sind wie folgt:');
        $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;
    }
}

Test

Führen Sie in der Befehlszeile php webman config:mysql aus

Das Ergebnis sieht ähnlich aus wie folgt:

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

Weitere Informationen

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