<?php namespace App\Command; use App\Message\PerfTestMessage; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Messenger\MessageBus; use Symfony\Component\Messenger\MessageBusInterface; class GenMessagesCommand extends Command { protected static $defaultName = 'app:gen-messages'; protected static $defaultDescription = 'Messages messages messages'; /** * GenMessagesCommand constructor. */ public function __construct(private MessageBusInterface $bus, string $name = null) { parent::__construct($name); } protected function configure(): void { $this ->setDescription(self::$defaultDescription) ->addArgument('nb', InputArgument::OPTIONAL, 'Numbers of messages', 10000) // ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description') ; } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $number = (int) $input->getArgument('nb'); // // if ($arg1) { // $io->note(sprintf('You passed an argument: %s', $arg1)); // } // // if ($input->getOption('option1')) { // // ... // } for($i = 0; $i < $number; $i++) { $this->bus->dispatch(new PerfTestMessage()); } $io->success("Sended $number messages."); return Command::SUCCESS; } }