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

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