1
0
mirror of synced 2024-11-25 06:16:06 +03:00
service-bundle/Messenger/MessageHandler/SimpleConsoleRunner.php

41 lines
1.1 KiB
PHP
Raw Normal View History

2021-03-31 11:00:48 +03:00
<?php
namespace RetailCrm\ServiceBundle\Messenger\MessageHandler;
use Psr\Log\LoggerInterface;
use RetailCrm\ServiceBundle\Messenger\CommandMessage;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpKernel\KernelInterface;
class SimpleConsoleRunner implements JobRunner
{
2022-07-20 14:38:42 +03:00
public function __construct(private LoggerInterface $logger, private KernelInterface $kernel)
2021-03-31 11:00:48 +03:00
{
}
public function run(CommandMessage $message): void
{
$application = new Application($this->kernel);
$application->setAutoExit(false);
$input = new ArrayInput(
array_merge(
['command' => $message->getCommandName()],
$message->getFormattedOptions(),
$message->getArguments()
)
);
$output = new BufferedOutput();
if ($application->run($input, $output) > 0) {
$this->logger->error($output->fetch());
return;
}
echo $output->fetch();
}
}