huttopia/console-bundle

为 symfony/console 添加一些优秀功能

1.3.3 2020-04-03 08:58 UTC

This package is auto-updated.

Last update: 2024-09-19 17:46:35 UTC


README

version symfony symfony Lines Total Downloads

ConsoleBundle

允许排除某些命令。

例如,如果您不想在 prod 环境中拥有 doctrine:schema:update 命令:现在您可以:)。

doctrine:schema:update 添加配置以获取每个连接的多个数据库的查询。

变更日志

安装

composer require huttopia/console-bundle ^1.3

替换 bin/console 的一部分

# Replace use Symfony\Bundle\FrameworkBundle\Console\Application; by this one
use Huttopia\ConsoleBundle\Application;

# Add this line before $input = new ArgvInput();
$allCommands = \Huttopia\ConsoleBundle\CommandOption\AllCommandsOption::parseAllCommandsOption($argv);
$input = new ArgvInput();

# Replace Application creation (it should be the last 2 lines of your bin/console)
// $application = new Application($kernel);
// $application->run($input);
(new Application($kernel))
    ->setAllCommands($allCommands)
    ->run($input);

Symfony <= 3

# app/AppKernel.php
class AppKernel
{
    public function registerBundles()
    {
        $bundles = [
            new \Huttopia\ConsoleBundle\ConsoleBundle()
        ];
    }
}

Symfony >= 4

# config/bundles.php
return [
    Huttopia\ConsoleBundle\ConsoleBundle::class => ['all' => true]
];

排除命令

# Symfony <= 3: app/config/config.yml
# Symfony >= 4: config/packages/console_bundle.yaml
console:
    excluded:
        - 'foo:bar:baz'
        - 'bar:foo:baz'

隐藏命令列表的一部分

当您调用 bin/consolebin/console list 时,您将看到命令列表。

输出被切割成 4 部分

  • Symfony 版本、环境和调试模式状态
  • 使用语法帮助
  • 所有命令可用选项的帮助
  • 命令列表

您可以为每个部分配置显示的详细程度。

详细程度可以是 01(《-v》)、2(《-vv》)或 3(《-vvv》)。

# Symfony <= 3: app/config/config.yml
# Symfony >= 4: config/packages/console_bundle.yaml
console:
    list:
        symfonyVersionVerbosityLevel: 1
        usageVerbosityLevel: 1
        optionsVerbosityLevel: 1
        availableCommandsVerbosityLevel: 0

彩色命令

当您调用 bin/consolebin/console list 时,您将看到命令列表。

您可以更改命令名称和描述的每个部分的颜色

console:
    list:
        output:
            # See https://symfony.com.cn/doc/current/console/coloring.html
            styles:
                foo:
                    foreground: cyan # 1st parameter of new OutputFormatterStyle()
                    background: green # 2nd parameter of new OutputFormatterStyle()
                    options: [bold, underscore] # 3rd parameter of new OutputFormatterStyle()
            commands:
                generate:benchmark: "<foo>%%s</>%%s%%s" # 1st %s is command name, 2nd is spaces between name and description and 3rd is the description
            highlights: # Shortcut for "<highlight>%%s</>%%s<highlight>%%s</>" who will write command name and description in cyan instead of green and white
                - 'cache:clear'

为多个数据库提供 doctrine:schema:update

doctrine:schema:update 对于我们来说有一个主要问题:每个连接仅管理一个数据库。

在我们的项目中,每个连接有多个数据库,所以 doctrine:schema:update 不显示我们所有数据库的查询。

UpdateDatabaseSchemaCommand 替换了 doctrine:schema:update 并为所有配置的数据库调用旧的 doctrine:schema:update

配置

# Symfony <= 3: app/config/config.yml
# Symfony >= 4: config/packages/console_bundle.yaml
console:
    databases:
        - database_name_1
        - database_name_2