<?php
namespace Stimactiv\LogBundle\EventListener;
use Stimactiv\LogBundle\Model\SiteLogManager;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
class SiteLogListener
{
private SiteLogManager $logger;
/**
* Constructor
*
* @param SiteLogManager $logger
*/
public function __construct(SiteLogManager $logger)
{
$this->logger = $logger;
}
public function onKernelException(ExceptionEvent $event): JsonResponse
{
// get the exception object from the received event
$exception = $event->getThrowable();
$result = $this->logger->reportPHPErrorIntoDB($exception);
return new JsonResponse([
'success' => $result
]);
}
public function onConsoleError(ConsoleErrorEvent $event): void
{
$this->logger->reportBatchErrorIntoDB($event);
}
}