<?php
namespace App\InsuranceCompany\Armeec\SOAP\Subscriber;
use App\SoapClient\Event\ResponseEvent as CustomResponseEvent;
use Phpro\SoapClient\Event\ResponseEvent;
use RuntimeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ErrorHandlingSubscriber
*/
class ErrorHandlingSubscriber implements EventSubscriberInterface
{
/**
* @param ResponseEvent $event
*/
public function onClientResponse(ResponseEvent $event)
{
// $response = $event->getResponse();
//
// if (!($response instanceof ResultProviderInterface)) {
// throw new UnexpectedValueException('Response type is not a result provider');
// }
// TODO
}
/**
* @param CustomResponseEvent $event
*/
public function onEngineResponse(CustomResponseEvent $event)
{
if (str_contains($event->getResponse()->getPayload(), '<title>403 Forbidden</title>')) {
throw new RuntimeException(
'В момента няма връзка със застрахователна компания Армеец през услугата за интеграция. ' .
'Моля ползвайте портала на компанията.'
);
}
}
/**
* {@inheritdoc}
* @noinspection PhpArrayShapeAttributeCanBeAddedInspection
*/
public static function getSubscribedEvents(): array
{
return [
ResponseEvent::class => 'onClientResponse',
CustomResponseEvent::class => 'onEngineResponse',
];
}
}