webman/console plugin della riga di comando
webman/console
si basa su symfony/console
Installazione
composer require webman/console
Comandi supportati
Modo d'uso
php webman comando
Ad esempio php webman version
Suggerimento
Può essere semplificato su sistemi linux come./webman comando
Comandi supportati
version
Stampa il numero di versione di webman
route:list
Stampa la configurazione delle rotte attuali
make:controller
Crea un file controller
Ad esempio php webman make:controller admin
creerà un file app/controller/AdminController.php
Ad esempio php webman make:controller api/user
creerà un file app/api/controller/UserController.php
make:model
Crea un file model
Ad esempio php webman make:model admin
creerà un file app/model/Admin.php
Ad esempio php webman make:model api/user
creerà un file app/api/model/User.php
make:middleware
Crea un file middleware
Ad esempio php webman make:middleware Auth
creerà un file app/middleware/Auth.php
make:command
Crea un file di comando personalizzato
Ad esempio php webman make:command db:config
creerà un file app\command\DbConfigCommand.php
plugin:create
Crea un plugin di base
Ad esempio php webman plugin:create --name=foo/admin
creerà le directory config/plugin/foo/admin
e vendor/foo/admin
Fai riferimento a Creazione di un plugin di base
plugin:export
Esporta un plugin di base
Ad esempio php webman plugin:export --name=foo/admin
Fai riferimento a Creazione di un plugin di base
plugin:export
Esporta un plugin applicativo
Ad esempio php webman plugin:export shop
Fai riferimento a Plugin applicativi
build:phar
Compila il progetto webman in un file phar
Fai riferimento a Assemblaggio phar
build:bin
Compila il progetto webman in un file binario eseguibile direttamente
Fai riferimento a Assemblaggio phar
Comandi personalizzati
Gli utenti possono definire i propri comandi, ad esempio il seguente comando stampa la configurazione del database
- Esegui
php webman make:command config:mysql
- Apri
app/command/ConfigMySQLCommand.php
e modificare come segue
<?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 = 'Mostra la configurazione attuale del server MySQL';
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Le informazioni di configurazione di MySQL sono le seguenti:');
$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
Esegui il comando php webman config:mysql
Il risultato sarà simile a questo:
+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+
| 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 | | | |
+-------+---------+--------+-----------+------+----------+----------+----------+-------------+---------+-----------------+--------+--------+--------+--------+---------+
Ulteriori informazioni
http://www.symfonychina.com/doc/current/components/console.html