src/EventSubscriber/LeaveCancellationRequestStatusWorkflowSubscriber.php line 24
<?phpnamespace App\EventSubscriber;use Generator;use App\Notifier\NotificationType;use App\Notifier\NotificationFactory;use Doctrine\ORM\EntityManagerInterface;use App\Entity\LeaveCancellationRequest;use Symfony\Component\Workflow\WorkflowInterface;use Symfony\Component\Workflow\Event\CompletedEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class LeaveCancellationRequestStatusWorkflowSubscriber implements EventSubscriberInterface{public function __construct(private readonly EntityManagerInterface $entityManager,private readonly NotificationFactory $notificationFactory,protected readonly WorkflowInterface $leaveStateMachine,) {}public function completedDecline(CompletedEvent $event){$leaveCancellationRequest = $event->getSubject();if ($leaveCancellationRequest instanceof LeaveCancellationRequest) {$notification = $this->notificationFactory->getNotification(NotificationType::LEAVE_CANCELLATION_REQUEST_DECLINED__REQUESTER,['leaveCancellationRequest' => $leaveCancellationRequest]);$this->entityManager->persist($notification);}}public function completedCancel(CompletedEvent $event){$leaveCancellationRequest = $event->getSubject();if ($leaveCancellationRequest instanceof LeaveCancellationRequest) {$notification = $this->notificationFactory->getNotification(NotificationType::LEAVE_CANCELLATION_REQUEST_CANCELLED_BY_REQUESTER__HR,['leaveCancellationRequest' => $leaveCancellationRequest]);$this->entityManager->persist($notification);}}public function completedAccept(CompletedEvent $event){$leaveCancellationRequest = $event->getSubject();if ($leaveCancellationRequest instanceof LeaveCancellationRequest) {$this->leaveStateMachine->apply($leaveCancellationRequest->getLeave(),'cancel_via_request',);$notification = $this->notificationFactory->getNotification(NotificationType::LEAVE_CANCELLATION_REQUEST_ACCEPTED__REQUESTER,['leaveCancellationRequest' => $leaveCancellationRequest]);$this->entityManager->persist($notification);} else {die('test');}}public static function getSubscribedEvents(): Generator{$workflowName = 'leave_cancellation_request';// Leave cancellations requests only happen on creation (no draft status)// The notification must be sent post persist to know the ID$transitionNames = ['accept' => ['completedAccept'],'cancel' => ['completedCancel'],'decline' => ['completedDecline'],];foreach ($transitionNames as $transitionName => $functionNames) {yield 'workflow.' . $workflowName . '.completed.' . $transitionName => $functionNames;}}}