<?php
/**
* payever GmbH
*
* NOTICE OF LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade payever Shopware package
* to newer versions in the future.
*
* @category Payever
* @author payever GmbH <service@payever.de>
* @copyright Copyright (c) 2021 payever GmbH (http://www.payever.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
declare(strict_types=1);
namespace Payever\PayeverPayments\EventListener;
use Shopware\Core\PlatformRequest;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Shopware\Core\Framework\Routing\KernelListenerPriorities;
/**
* Class RouteScopeListener
*/
class RouteScopeListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => [
['checkScope', KernelListenerPriorities::KERNEL_CONTROLLER_EVENT_PRIORITY_AUTH_VALIDATE_PRE],
],
];
}
/**
* Checking the compatibility of routers for different versions.
*
* https://github.com/shopware/platform/blob/trunk/UPGRADE-6.4.md#routescope
*/
public function checkScope(ControllerEvent $event): void
{
$attributes = $event->getRequest()->attributes;
if (!$attributes->get('payever') || !$attributes->get('_routeScope')) {
return;
}
$class = 'Shopware\Core\Framework\Routing\Annotation\RouteScope';
$scope = $attributes->get('_routeScope');
//version < 6.5
if (class_exists($class)) {
$scope = new $class(['scopes' => $scope]);
$attributes->set(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE, $scope);
}
}
}