services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Request,Entity,Migrations,Tests,Kernel.php}'
App\Console\:
resource: '../src/Console'
public: true
tags: ['console.command']
App\Command\:
resource: '../src/Command'
tags:
- { name: tactician.handler, typehints: true }
League\Tactician\CommandBus: '@tactician.commandbus'
class CreateCliRequest extends ContainerAwareCommand
{
/**
* @var CommandBus
*/
private $commandBus;
public function __construct(?string $name = null, CommandBus $commandBus)
{
parent::__construct($name);
$this->commandBus = $commandBus;
}
protected function configure()
{
$this
->setName('create:cli:req')
->addArgument('name', InputArgument::REQUIRED)
->setDescription('Some command');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$request = new CreateRequest(12, $input->getArgument('name'));
$result = $this->commandBus->handle($request);
$output
->writeln('<info>' .$result . '</info>');
}
}