webman/console Plugin de ligne de commande

webman/console basé sur symfony/console

Installation

composer require webman/console

Commandes prises en charge

Utilisation
php webman commande
Par exemple php webman version

Indication
Sous les systèmes Linux, cela peut être simplifié en ./webman commande

Commandes prises en charge

version

Imprime le numéro de version de webman

route:list

Imprime la configuration des routes actuelle

make:controller

Crée un fichier contrôleur
Par exemple php webman make:controller admin créera un fichier app/controller/AdminController.php
Par exemple php webman make:controller api/user créera un fichier app/api/controller/UserController.php

make:model

Crée un fichier de modèle
Par exemple php webman make:model admin créera un fichier app/model/Admin.php
Par exemple php webman make:model api/user créera un fichier app/api/model/User.php

make:middleware

Crée un fichier de middleware
Par exemple php webman make:middleware Auth créera un fichier app/middleware/Auth.php

make:command

Crée un fichier de commande personnalisée
Par exemple php webman make:command db:config créera un fichier app\command\DbConfigCommand.php

plugin:create

Crée un plugin de base
Par exemple php webman plugin:create --name=foo/admin créera deux répertoires config/plugin/foo/admin et vendor/foo/admin
Voir Créer un plugin de base

plugin:export

Exporte un plugin de base
Par exemple php webman plugin:export --name=foo/admin
Voir Créer un plugin de base

plugin:export

Exporte un plugin d'application
Par exemple php webman plugin:export shop
Voir Plugin d'application

build:phar

Emballer le projet webman en un fichier phar
Voir Emballage phar

build:bin

Emballer le projet webman en un fichier binaire exécutable
Voir Emballage phar

Commandes personnalisées

L'utilisateur peut définir ses propres commandes, par exemple la commande suivante affiche la configuration de la base de données

  • Exécutez php webman make:command config:mysql
  • Ouvrez app/command/ConfigMySQLCommand.php et modifiez-le comme suit
<?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 = 'Affiche la configuration actuelle du serveur MySQL';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Les informations de configuration MySQL sont les suivantes :');
        $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;
    }
}

Tests

Exécution de la commande php webman config:mysql

Le résultat ressemble à ceci :

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

Références supplémentaires

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