<?php
namespace Crea\FloaBundle\EventSubscriber;
use Crea\FloaBundle\Event\FloaExceptionEvent;
use Crea\FloaBundle\Exception\AbstractFloaException;
use Crea\FloaBundle\FloaEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Throwable;
class FloaExceptionEventSubscriber implements EventSubscriberInterface
{
protected KernelInterface $kernel;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
public static function getSubscribedEvents(): array
{
return [
FloaEvents::MISSING_ADAPTER_EXCEPTION => [['handleException', 256]],
FloaEvents::MISSING_ELIGIBILITY_EXCEPTION => [['handleException', 256]],
FloaEvents::CLIENT_TOKEN_EXCEPTION => [['handleException', 256]],
FloaEvents::CLIENT_PRE_ELIGIBILITY_EXCEPTION => [['handleException', 256]],
FloaEvents::CLIENT_ELIGIBILITY_EXCEPTION => [['handleException', 256]],
FloaEvents::CLIENT_PAYMENT_SESSION_EXCEPTION => [['handleException', 256]],
];
}
public function handleException(FloaExceptionEvent $event)
{
if ($this->supportException($exception = $event->getException())) {
if ($this->kernel->getEnvironment() === "dev") {
dump($exception);
}
}
}
private function supportException(Throwable $exception): bool
{
return $exception instanceof AbstractFloaException;
}
}