| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Setono\MessageSchedulerBundle\Command; |
||
| 6 | |||
| 7 | use Psr\Log\LoggerAwareInterface; |
||
| 8 | use Setono\MessageSchedulerBundle\Dispatcher\DispatcherInterface; |
||
| 9 | use Symfony\Component\Console\Command\Command; |
||
| 10 | use Symfony\Component\Console\Input\InputInterface; |
||
| 11 | use Symfony\Component\Console\Logger\ConsoleLogger; |
||
| 12 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 13 | |||
| 14 | final class DispatchCommand extends Command |
||
| 15 | { |
||
| 16 | protected static $defaultName = 'setono:message-scheduler:dispatch'; |
||
| 17 | |||
| 18 | private DispatcherInterface $dispatcher; |
||
| 19 | |||
| 20 | 1 | public function __construct(DispatcherInterface $dispatcher) |
|
| 21 | { |
||
| 22 | 1 | parent::__construct(); |
|
| 23 | |||
| 24 | 1 | $this->dispatcher = $dispatcher; |
|
| 25 | 1 | } |
|
| 26 | |||
| 27 | 1 | protected function configure(): void |
|
| 28 | { |
||
| 29 | 1 | $this->setDescription('Will dispatch messages, that are eligible for dispatching'); |
|
| 30 | 1 | } |
|
| 31 | |||
| 32 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 33 | { |
||
| 34 | if ($this->dispatcher instanceof LoggerAwareInterface) { |
||
| 35 | $this->dispatcher->setLogger(new ConsoleLogger($output)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 36 | } |
||
| 37 | |||
| 38 | $this->dispatcher->dispatch(); |
||
| 39 | |||
| 40 | return 0; |
||
| 41 | } |
||
| 42 | } |
||
| 43 |