<?php
/**
* @author Léo BANNHOLTZER (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\AdelyaBundle\EventSubscriber;
use Bluue\AdelyaBundle\Message\ValidateReceiptMessage;
use Bluue\CashRegisterBundle\Event\ReceiptMovementsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
class ReceiptSubscriber implements EventSubscriberInterface
{
/**
* @var MessageBusInterface
*/
private MessageBusInterface $messageBus;
/**
* @param MessageBusInterface $messageBus
*/
public function __construct(MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
ReceiptMovementsEvent::VALIDATE_RECEIPT => 'validateReceipt'
];
}
/**
* @param ReceiptMovementsEvent $event
* @return void
*/
public function validateReceipt(ReceiptMovementsEvent $event): void
{
$receipt = $event->getReceipt();
$this->messageBus->dispatch(new ValidateReceiptMessage((string) $receipt->getId()));
}
}