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

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\Core\Framework\Routing\Annotation\RouteScope;
  6. use Shopware\Core\PlatformRequest;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. class KernelSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var VersionCompare
  14.      */
  15.     private $versionCompare;
  16.     /**
  17.      * @param VersionCompare $versionCompare
  18.      */
  19.     public function __construct(VersionCompare $versionCompare)
  20.     {
  21.         $this->versionCompare $versionCompare;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             KernelEvents::CONTROLLER => 'onModifyRouteScope'
  27.         ];
  28.     }
  29.     /**
  30.      * the route scopes are added as array to routes.xml in SW 6.4 those are inside RouteScope class. so we convert our array to class
  31.      * @param ControllerEvent $event
  32.      * @return void
  33.      */
  34.     public function onModifyRouteScope(ControllerEvent $event): void
  35.     {
  36.         //there are cases where the class RouteScope still exists even in SW 6.5
  37.         if ($this->versionCompare->gte('6.5.0.0')) {
  38.             return;
  39.         }
  40.         if (! class_exists(RouteScope::class)) {
  41.             return;
  42.         }
  43.         $attributes $event->getRequest()->attributes;
  44.         /** @var null|array<string>|RouteScope $routeScope */
  45.         $routeScope $attributes->get(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE);
  46.         if ($routeScope === null) {
  47.             return;
  48.         }
  49.         if ($routeScope instanceof RouteScope) {
  50.             return;
  51.         }
  52.         $routeScope = new RouteScope(['scopes' => $routeScope]);
  53.         $attributes->set(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE$routeScope);
  54.     }
  55. }