Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?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;
}
}