<?php
namespace App\EventListener;
use App\Service\Bus\Publisher\ProductPublisher;
use Symfony\Component\Workflow\Event\TransitionEvent;
class GoodWorkflowListener
{
private ProductPublisher $goodsPublisher;
public function __construct(ProductPublisher $goodsPublisher)
{
$this->goodsPublisher = $goodsPublisher;
}
public function onTransition(TransitionEvent $ev)
{
$method = $ev->getTransition()->getName();
if (method_exists($this, $method)) {
$this->$method($ev);
} else {
// Log
}
}
// transitions handle
private function initToMedia(TransitionEvent $ev)
{
return true;
}
//При публикации продукта отправляем его в шину формируя релиз для фронтов
/**
* @throws \Exception
*/
private function moderationToPublished(TransitionEvent $ev): void
{
$this->goodsPublisher->create($ev->getSubject());
}
}