src/EventSubscriber/LeaveStatusWorkflowSubscriber.php line 28
<?phpnamespace App\EventSubscriber;use Generator;use App\Notifier\NotificationType;use App\Notifier\NotificationFactory;use Doctrine\ORM\EntityManagerInterface;use App\LeaveManagement\LeaveAllowanceBooker;use App\LeaveManagement\LeaveDurationCalculator;use Symfony\Component\Workflow\WorkflowInterface;use Symfony\Component\Workflow\Event\CompletedEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class LeaveStatusWorkflowSubscriber implements EventSubscriberInterface{use LeaveAllowanceModifying;public function __construct(private readonly EntityManagerInterface $entityManager,private readonly LeaveDurationCalculator $leaveDurationCalculator,private readonly LeaveAllowanceBooker $leaveAllowanceBooker,private readonly NotificationFactory $notificationFactory,protected readonly WorkflowInterface $leaveRequestStateMachine,) {}public function completedCancel(CompletedEvent $event){$leave = $event->getSubject();$this->releaseAllowanceDays($event);$this->voidLeaveRequest($event);$notification = $this->notificationFactory->getNotification(NotificationType::LEAVE_CANCELLED_BY_HR__EMPLOYEE,['leave' => $leave]);$this->entityManager->persist($notification);}public function completedCancelViaRequest(CompletedEvent $event){$leave = $event->getSubject();$this->releaseAllowanceDays($event);$this->voidLeaveRequest($event);}public function voidLeaveRequest(CompletedEvent $event){$request = $event->getSubject()->getRequest();if (!is_null($request)) {$this->leaveRequestStateMachine->apply($request,'void',);}}public static function getSubscribedEvents(): Generator{$workflowName = 'leave';$transitionNames = ['cancel' => ['completedCancel'],'cancel_via_request' => ['completedCancelViaRequest'],];foreach ($transitionNames as $transitionName => $functionNames) {yield 'workflow.' . $workflowName . '.completed.' . $transitionName => $functionNames;}}}