getRouteScope example

private function isRequestScoped(Request $request, string $scopeClass): bool
    {
        /** @var list<string> $scopes */
        $scopes = $request->attributes->get(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE, []);

        if ($scopes === []) {
            return false;
        }

        foreach ($scopes as $scopeId) {
            $scope = $this->getScopeRegistry()->getRouteScope($scopeId);

            if ($scope instanceof $scopeClass) {
                return true;
            }
        }

        return false;
    }
}

    public function checkScope(ControllerEvent $event): void
    {
        if ($this->isWhitelistedController($event)) {
            return;
        }

        $scopes = $this->extractCurrentScopeAnnotation($event);
        $masterRequest = $this->getMainRequest();

        foreach ($scopes as $routeScopeName) {
            $routeScope = $this->routeScopeRegistry->getRouteScope($routeScopeName);

            $pathAllowed = $routeScope->isAllowedPath($masterRequest->getPathInfo());
            $requestAllowed = $routeScope->isAllowed($masterRequest);

            if ($pathAllowed && $requestAllowed) {
                return;
            }
        }

        throw new InvalidRouteScopeException($masterRequest->attributes->get('_route'));
    }

    
Home | Imprint | This part of the site doesn't use cookies.