xervice/console

2.1.1 2022-02-09 09:22 UTC

This package is auto-updated.

Last update: 2024-09-09 15:33:04 UTC


README

Scrutinizer Code Quality Code Coverage

基于 symfony console 的 Xervice 控制台服务。

安装

composer require xervice/console

配置

没有需要配置的内容。但若要添加您的命令,您需要扩展控制台模块,并在依赖提供者中覆盖 "getCommandList" 方法。

<?php

namespace App\Console;

use Xervice\Console\ConsoleDependencyProvider as XerviceConsoleDependencyProvider;

class ConsoleDependencyProvider extends XerviceConsoleDependencyProvider
{
    /**
     * @return array
     */
    protected function getCommandList(): array
    {
        return [
            new MyCommand()
        ];
    }
}

使用方法

vendor/bin/xervice <command>

新命令

<?php

namespace App\MyModule\Communication\Console\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Xervice\Console\Business\Model\Command\AbstractCommand;

/**
 * @method \App\MyModule\Business\MyModuleFacade getFacade()
 * @method \App\MyModule\Communication\MyModuleCommunicationFactory getFactory()
 */
class MyCommand extends AbstractCommand
{
    /**
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
     */
    protected function configure(): void
    {
        $this
            ->setName('mymodule:mycommand')
            ->setDescription('Command description');
    }

    /**
     * @param \Symfony\Component\Console\Input\InputInterface $input
     * @param \Symfony\Component\Console\Output\OutputInterface $output
     *
     * @return int|void
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
     */
    public function run(InputInterface $input, OutputInterface $output)
    {
        $this->getFacade()->runMyCommand($output);
    }

}