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

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.     public function __construct(VersionCompare $versionCompare)
  17.     {
  18.         $this->versionCompare $versionCompare;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             KernelEvents::CONTROLLER => 'onModifyRouteScope',
  24.         ];
  25.     }
  26.     /**
  27.      * 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
  28.      */
  29.     public function onModifyRouteScope(ControllerEvent $event): void
  30.     {
  31.         // there are cases where the class RouteScope still exists even in SW 6.5
  32.         if ($this->versionCompare->gte('6.5.0.0')) {
  33.             return;
  34.         }
  35.         if (! class_exists(RouteScope::class)) {
  36.             return;
  37.         }
  38.         $attributes $event->getRequest()->attributes;
  39.         /** @var null|array<string>|RouteScope $routeScope */
  40.         $routeScope $attributes->get(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE);
  41.         if ($routeScope === null) {
  42.             return;
  43.         }
  44.         if ($routeScope instanceof RouteScope) {
  45.             return;
  46.         }
  47.         $routeScope = new RouteScope(['scopes' => $routeScope]);
  48.         $attributes->set(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE$routeScope);
  49.     }
  50. }