<?php
namespace App\EventSubscriber;
use App\Event\SendSmsEvent;
use App\Exception\CommandValidateException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Service\SmsMessage\CreateSmsMessageCommand;
use App\Service\SmsMessage\Handler\CreateSmsMessageCommandHandler;
class SendSmsEventSubscriber implements EventSubscriberInterface
{
private $createSmsMessageCommandHandler;
/**
* CreatePatientEventSubscriber constructor.
*/
public function __construct(CreateSmsMessageCommandHandler $createSmsMessageCommandHandler)
{
$this->createSmsMessageCommandHandler = $createSmsMessageCommandHandler;
}
public static function getSubscribedEvents(): array
{
return [
SendSmsEvent::NAME => [
['createSmsMessage', 0],
],
];
}
/**
* @throws CommandValidateException
*/
public function createSmsMessage(SendSmsEvent $event)
{
$createPatientCommand = new CreateSmsMessageCommand();
$createPatientCommand->phoneNumber = $event->getPhoneNumber();
$createPatientCommand->messageType = $event->getMessageType();
$this->createSmsMessageCommandHandler->handle($createPatientCommand);
}
}