xervice / console
2.1.1
2022-02-09 09:22 UTC
Requires
- symfony/console: ^3.4|^4.0|^5.0|^6.0
- xervice/core: ^4.0.0
Requires (Dev)
- codeception/codeception: *
- phpstan/phpstan: ^0.12.0
- symfony/var-dumper: *
README
基于 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); } }