Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ncssl/source/src/Command/EventCoreNotifierCommand.php
<?php
namespace App\Command;
use App\Service\Message\EventCoreNotifierInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'app:event-core-notifier:send-event',
description: 'Add a short description for your command',
)]
class EventCoreNotifierCommand extends Command
{
public function __construct(
private readonly EventCoreNotifierInterface $service,
private readonly LoggerInterface $logger,
){
parent::__construct();
}
private function getAllowedEventCodes(): array
{
return [
EventCoreNotifierInterface::SUCCESS_INSTALLATION_EVENT_CODE,
EventCoreNotifierInterface::ERROR_ACTIVATION_DVC_FILE_ABSENT_EVENT_CODE,
EventCoreNotifierInterface::ERROR_INSTALLATION_GENERAL_EVENT_CODE,
EventCoreNotifierInterface::ERROR_INSTALLATION_DOMAIN_NOT_FOUND_EVENT_CODE
];
}
protected function configure(): void
{
$this
->addArgument('eventCode', InputArgument::REQUIRED, 'Event code')
->addArgument('certificateId', InputArgument::REQUIRED, 'Certificate ID')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$eventCode = $input->getArgument('eventCode');
$allowedEventCode = $this->getAllowedEventCodes();
if (!in_array($eventCode, $allowedEventCode)) {
throw new InvalidArgumentException('Event code should be one of ' . implode(', ', $allowedEventCode));
}
$response = $this->service->sendEvent($input->getArgument('eventCode'), $input->getArgument('certificateId'));
dump($response);
return Command::SUCCESS;
} catch (\Exception $e) {
$this->logger->error(sprintf('Error occurred get list request: %s', $e->getMessage()));
return Command::FAILURE;
}
}
}
Back to Directory
File Manager