custom/plugins/MolliePayments/src/Subscriber/CsrfSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Kiener\MolliePayments\Subscriber;
  4. use Kiener\MolliePayments\Compatibility\VersionCompare;
  5. use Shopware\Storefront\Event\StorefrontRenderEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CsrfSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var VersionCompare
  11.      */
  12.     private $versionCompare;
  13.     public function __construct(string $shopwareVersion)
  14.     {
  15.         $this->versionCompare = new VersionCompare($shopwareVersion);
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             StorefrontRenderEvent::class => 'onStorefrontRender',
  21.         ];
  22.     }
  23.     /**
  24.      * @throws \Exception
  25.      */
  26.     public function onStorefrontRender(StorefrontRenderEvent $event): void
  27.     {
  28.         // we have conditional includes in TWIG to add files with the csrf function.
  29.         // this is required to support both Shopware 6.4 and 6.5 in the storefront.
  30.         $hasCSRF $this->versionCompare->lt('6.5.0');
  31.         $event->setParameter('mollie_csrf_available'$hasCSRF);
  32.     }
  33. }