src/InsuranceCompany/Armeec/SOAP/Subscriber/ErrorHandlingSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\InsuranceCompany\Armeec\SOAP\Subscriber;
  3. use App\SoapClient\Event\ResponseEvent as CustomResponseEvent;
  4. use Phpro\SoapClient\Event\ResponseEvent;
  5. use RuntimeException;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. /**
  8.  * Class ErrorHandlingSubscriber
  9.  */
  10. class ErrorHandlingSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @param ResponseEvent $event
  14.      */
  15.     public function onClientResponse(ResponseEvent $event)
  16.     {
  17. //        $response = $event->getResponse();
  18. //
  19. //        if (!($response instanceof ResultProviderInterface)) {
  20. //            throw new UnexpectedValueException('Response type is not a result provider');
  21. //        }
  22.         // TODO
  23.     }
  24.     /**
  25.      * @param CustomResponseEvent $event
  26.      */
  27.     public function onEngineResponse(CustomResponseEvent $event)
  28.     {
  29.         if (str_contains($event->getResponse()->getPayload(), '<title>403 Forbidden</title>')) {
  30.             throw new RuntimeException(
  31.                 'В момента няма връзка със застрахователна компания Армеец през услугата за интеграция. ' .
  32.                 'Моля ползвайте портала на компанията.'
  33.             );
  34.         }
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      * @noinspection PhpArrayShapeAttributeCanBeAddedInspection
  39.      */
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             ResponseEvent::class => 'onClientResponse',
  44.             CustomResponseEvent::class => 'onEngineResponse',
  45.         ];
  46.     }
  47. }