<?php
namespace FlexApp\EventSubscriber;
use Exception;
use FlexApp\Events\BugEvent;
use FlexApp\Events\Style43\CommentErrorEvent;
use FlexApp\Events\Style43\GeneralErrorEvent;
use FlexApp\Events\Style43\NotValidPortalApiServerRequestEvent;
use FlexApp\Events\Style43\UserErrorEvent;
use FlexApp\Service\DevsAndAdminsNotifier;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ErrorNotifierSubscriber implements EventSubscriberInterface
{
private DevsAndAdminsNotifier $notifier;
/**
* @param DevsAndAdminsNotifier $notifier
*/
public function __construct(DevsAndAdminsNotifier $notifier)
{
$this->notifier = $notifier;
}
public static function getSubscribedEvents()
{
/*По каждому типу косяка уведомляем только тех
людей (разрабочиков/админов), которые имеют отношение
к данному типу косяка*/
return [
CommentErrorEvent::class => [
['notifyAboutCommentComponentError', 0],
],
UserErrorEvent::class => [
['notifyAboutUserComponentError', 0],
],
GeneralErrorEvent::class => [
['notifyAboutGeneralError', 0],
],
NotValidPortalApiServerRequestEvent::class => [
['notifyAboutGeneralError', 0],
],
];
}
/**
* @param BugEvent $bugEvent
*
* @throws Exception
*/
public function notifyAboutCommentComponentError(BugEvent $bugEvent)
{
$this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'comment_fails_emails');
}
/**
* @param \FlexApp\Events\BugEvent $bugEvent
*
* @throws Exception
*/
public function notifyAboutGeneralError(BugEvent $bugEvent)
{
$this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'general_fails_emails');
}
/**
* @param \FlexApp\Events\BugEvent $bugEvent
*
* @throws Exception
*/
public function notifyAboutUserComponentError(BugEvent $bugEvent)
{
$this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'user_fails_emails');
}
}