vendor/store.shopware.com/agiqonoci/src/Subscriber/InspectSubscriber.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace AgiqonOci\Subscriber;
  3. use AgiqonOci\Models\CxmlSession;
  4. use AgiqonOci\Models\OciSession;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
  10. class InspectSubscriber implements EventSubscriberInterface
  11. {
  12.     public const INSPECT_URI '/AgiqonCxmlEntry/inspect';
  13.     public const LOGOUT_URI '/AgiqonOciEntry/logout';
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             KernelEvents::RESPONSE => 'onKernelResponse'
  18.         ];
  19.     }
  20.     public function onKernelResponse(ResponseEvent $event)
  21.     {
  22.         $requestUri $event->getRequest()->getRequestUri();
  23.         try {
  24.             $ociSession $event->getRequest()->getSession()->get(OciSession::OCI_SESSION_NAME);
  25.         } catch (SessionNotFoundException $exception) {
  26.             return;
  27.         }
  28.         if ($ociSession instanceof CxmlSession
  29.             && $ociSession->getSystem() === 'cxml'
  30.             && $ociSession->getOperation() === 'inspect'
  31.             && $requestUri !== self::INSPECT_URI
  32.             && $requestUri !== self::LOGOUT_URI
  33.             && !$this->isWdt($requestUri)) {
  34.             $redirectResponse = new RedirectResponse(self::INSPECT_URI);
  35.             $event->setResponse($redirectResponse);
  36.         }
  37.     }
  38.     private function isWdt(string $requestUri): bool
  39.     {
  40.         return strpos($requestUri'_wdt') !== false;
  41.     }
  42. }