custom/plugins/SheAdminUrl/src/Core/Framework/Routing/ApiRequestContextResolver.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace She\AdminUrl\Core\Framework\Routing;
  4. use Shopware\Administration\Framework\Routing\AdministrationRouteScope;
  5. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  6. use Shopware\Core\Framework\Routing\RequestContextResolverInterface;
  7. use Shopware\Core\Framework\Routing\SalesChannelRequestContextResolver as InnerService;
  8. use Shopware\Core\PlatformRequest;
  9. use Symfony\Component\HttpFoundation\Request;
  10. class ApiRequestContextResolver implements RequestContextResolverInterface
  11. {
  12.     private InnerService $innerService;
  13.     public function __construct(InnerService $innerService)
  14.     {
  15.         $this->innerService $innerService;
  16.     }
  17.     public function resolve(Request $request): void
  18.     {
  19.         $routeScope $request->attributes->get(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE);
  20.         if (!$routeScope instanceof RouteScope || !\in_array(
  21.             AdministrationRouteScope::ID,
  22.             $routeScope->getScopes(),
  23.             true
  24.         )) {
  25.             $this->innerService->resolve($request);
  26.             return;
  27.         }
  28.         $scopes $routeScope->getScopes();
  29.         $scopes[] = 'api';
  30.         $routeScope->setScopes($scopes);
  31.         $request->attributes->set(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE$routeScope);
  32.         $this->innerService->resolve($request);
  33.     }
  34. }