Adds an optional "_fos_rest_zone" request attribute to be checked for existence by other listeners.

@param GetResponseEvent $event
161034
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        foreach ($this->requestMatchers as $requestMatcher) {
            if ($requestMatcher->matches($request)) {
                $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, true);

                return;
            }
        }

        $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, false);
    }
306679
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (! $event->isMasterRequest()) {
            return;
        }

        $currentClient = Hub::getCurrent()->getClient();
        if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
            return;
        }

        $token = null;

        if ($this->tokenStorage instanceof TokenStorageInterface) {
            $token = $this->tokenStorage->getToken();
        }

        if (
            null !== $token
            && null !== $this->authorizationChecker
            && $token->isAuthenticated()
            && $this->authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
        ) {
            $userData = $this->getUserData($token->getUser());
        }

        $userData['ip_address'] = $event->getRequest()->getClientIp();

        Hub::getCurrent()
            ->configureScope(function (Scope $scope) use ($userData): void {
                $scope->setUser($userData);
            });
    }
1350675
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        $method = $request->getMethod();

        if (
            'DELETE' === $method
            || $request->isMethodSafe(false)
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
            || (
                    '' === ($requestContent = $request->getContent())
                    && ('POST' === $method || 'PUT' === $method)
               )
        ) {
            return;
        }

        $context = $this->serializerContextBuilder->createFromRequest($request, false, $attributes);
        if (isset($context['input']) && \array_key_exists('class', $context['input']) && null === $context['input']['class']) {
            return;
        }

        // BC check to be removed in 3.0
        if (null !== $this->formatsProvider) {
            $this->formats = $this->formatsProvider->getFormatsFromAttributes($attributes);
        }
        $this->formatMatcher = new FormatMatcher($this->formats);
        $format = $this->getFormat($request);

        $data = $request->attributes->get('data');
        if (null !== $data) {
            $context[AbstractNormalizer::OBJECT_TO_POPULATE] = $data;
        }

        $request->attributes->set(
            'data',
            $this->serializer->deserialize(
                $requestContent, $context['resource_class'], $format, $context
            )
        );
    }
831636
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($this->tokenStorage->getToken() && $this->authorizationChecker->isGranted('ROLE_VICTOIRE')) {
            $this->eventDispatcher->dispatch('victoire_core.build_menu', $event);
        }
    }
1047499
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();

        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || !$this->isAdminSiteAccess($request)) {
            return;
        }

        $additionalTranslations = $this->configResolver->getParameter('user_preferences.additional_translations');
        $preferableLocales = $this->userLanguagePreferenceProvider->getPreferredLocales($request);
        $locale = null;

        foreach ($preferableLocales as $preferableLocale) {
            if (\in_array($preferableLocale, $this->availableTranslations, true)
                || \in_array($preferableLocale, $additionalTranslations, true)
            ) {
                $locale = $preferableLocale;
                break;
            }
        }
        $locale = $locale ?? reset($preferableLocales);
        $request->setLocale($locale);
        $request->attributes->set('_locale', $locale);
        // Set of the current locale on the translator service is needed because RequestLocaleListener has lower
        // priority than LocaleListener and messages are not translated on login, forgot and reset password pages.
        $this->translator->setLocale($locale);
    }
1322387
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }
        $request = $event->getRequest();

        if ($request::getTrustedProxies()) {
            $request->getClientIps();
        }

        $request->getHost();
    }
583457
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (!($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false) || $request->attributes->getBoolean('_graphql', false))) {
            return;
        }
        // BC check to be removed in 3.0
        if (null !== $this->formatsProvider) {
            $this->formats = $this->formatsProvider->getFormatsFromAttributes(RequestAttributesExtractor::extractAttributes($request));
        }
        $this->formatMatcher = new FormatMatcher($this->formats);

        $this->populateMimeTypes();
        $this->addRequestFormats($request, $this->formats);

        // Empty strings must be converted to null because the Symfony router doesn't support parameter typing before 3.2 (_format)
        if (null === $routeFormat = $request->attributes->get('_format') ?: null) {
            $mimeTypes = array_keys($this->mimeTypes);
        } elseif (!isset($this->formats[$routeFormat])) {
            throw new NotFoundHttpException(sprintf('Format "%s" is not supported', $routeFormat));
        } else {
            $mimeTypes = Request::getMimeTypes($routeFormat);
        }

        // First, try to guess the format from the Accept header
        /** @var string|null $accept */
        $accept = $request->headers->get('Accept');
        if (null !== $accept) {
            if (null === $mediaType = $this->negotiator->getBest($accept, $mimeTypes)) {
                throw $this->getNotAcceptableHttpException($accept, $mimeTypes);
            }

            $request->setRequestFormat($this->formatMatcher->getFormat($mediaType->getType()));

            return;
        }

        // Then use the Symfony request format if available and applicable
        $requestFormat = $request->getRequestFormat('') ?: null;
        if (null !== $requestFormat) {
            $mimeType = $request->getMimeType($requestFormat);

            if (isset($this->mimeTypes[$mimeType])) {
                return;
            }

            throw $this->getNotAcceptableHttpException($mimeType);
        }

        // Finally, if no Accept header nor Symfony request format is set, return the default format
        foreach ($this->formats as $format => $mimeType) {
            $request->setRequestFormat($format);

            return;
        }
    }
931543
public function onKernelRequestIndex(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $semanticPathinfo = $request->attributes->get('semanticPathinfo') ?: '/';
        if (
            $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST
            && $semanticPathinfo === '/'
        ) {
            $indexPage = $this->configResolver->getParameter('index_page');
            if ($indexPage !== null) {
                $indexPage = '/' . ltrim($indexPage, '/');
                $request->attributes->set('semanticPathinfo', $indexPage);
                $request->attributes->set('needsForward', true);
            }
        }
    }
1342529
public function setPjaxRequestLocale(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$event->isMasterRequest() || !$this->requestMatcher->matches($request)) {
            return;
        }

        $request->setLocale($request->getPreferredLanguage());
        $request->attributes->set('_locale', $request->getPreferredLanguage());
    }
600229
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // don't do anything if it's not the master request
            return;
        }

        $request = $event->getRequest();

        $session = $this->getContainer()->get('session');

        $utm_params = [
            'utm_source',
            'utm_campaign',
            'utm_medium',
            'utm_term',
        ];

        foreach ($utm_params as $param) {
            if ($request->get($param)) {
                $session->set($param, $request->get($param));
            }
        }
    }
1158571
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        // Ignore sub-requests, including fragments.
        if (!$this->isMasterRequest($request, $event->getRequestType())) {
            return;
        }

        $siteAccess = $request->attributes->get('siteaccess');
        if (!$siteAccess instanceof SiteAccess) {
            return;
        }

        $token = $this->tokenStorage->getToken();
        if ($token === null) {
            return;
        }

        if (
            // Leave access to login route, so that user can attempt re-authentication.
            $request->attributes->get('_route') !== 'login'
            && !$this->hasAccess($siteAccess, $token->getUsername())
        ) {
            throw new UnauthorizedSiteAccessException($siteAccess, $token->getUsername());
        }
    }
305698
public function onKernelRequestSetup(GetResponseEvent $event)
    {
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            if ($this->defaultSiteAccess !== 'setup') {
                return;
            }

            $request = $event->getRequest();
            $requestContext = $this->router->getContext();
            $requestContext->fromRequest($request);
            $this->router->setContext($requestContext);
            $setupURI = $this->router->generate('ezpublishSetup');

            if (($requestContext->getBaseUrl() . $request->getPathInfo()) === $setupURI) {
                return;
            }

            $event->setResponse(new RedirectResponse($setupURI));
        }
    }
1012761
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request) {
            return;
        }

        if (!$request->hasSession()) {
            return;
        }

        if($request->isXmlHttpRequest()){
            return;
        }

        $adminCode = $request->get('_sonata_admin');

        if (!is_null($adminCode)) {
            $this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
            $this->admin->setRequest($request);
            if (!$this->admin) {
                throw new \RuntimeException(sprintf(
                    'Unable to find the admin class related to the current controller (%s)',
                    get_class($this)
                ));
            }

            foreach ($this->admin->getExtensions() as $extension) {
                $this->setTrackedAction($extension);
            }
            $this->setTrackedAction($this->admin);
        }
    }
1063724
public function onKernelRequest(GetResponseEvent $event): void
    {
        $event->getRequest()->attributes->set(
            'csrf_enabled',
            $this->csrfTokenManager instanceof CsrfTokenManager
        );
    }
454770
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $theme = $this->activeTheme->getName();
        $controllers = $request->attributes->get(static::ATTRIBUTE_KEY);
        if (isset($controllers[$theme])) {
            $request->attributes->set('_controller', $controllers[$theme]);
        }

        // Get rid of the attribute in the request to avoid it showing up in generated URLs
        $request->attributes->remove(static::ATTRIBUTE_KEY);
        $routeParams = $request->attributes->get('_route_params');
        if (null !== $routeParams) {
            unset($routeParams[static::ATTRIBUTE_KEY]);
            $request->attributes->set('_route_params', $routeParams);
        }
    }
827225
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
        ) {
            return;
        }

        if (null === $filters = $request->attributes->get('_api_filters')) {
            $queryString = RequestParser::getQueryString($request);
            $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
        }

        $context = null === $filters ? [] : ['filters' => $filters];
        if ($this->serializerContextBuilder) {
            // Builtin data providers are able to use the serialization context to automatically add join clauses
            $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
            $request->attributes->set('_api_normalization_context', $normalizationContext);
        }

        if (isset($attributes['collection_operation_name'])) {
            $request->attributes->set('data', $request->isMethod('POST') ? null : $this->getCollectionData($attributes, $context));

            return;
        }

        $data = [];

        if ($this->identifierConverter) {
            $context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] = true;
        }

        try {
            $identifiers = $this->extractIdentifiers($request->attributes->all(), $attributes);

            if (isset($attributes['item_operation_name'])) {
                $data = $this->getItemData($identifiers, $attributes, $context);
            } elseif (isset($attributes['subresource_operation_name'])) {
                // Legacy
                if (null === $this->subresourceDataProvider) {
                    throw new RuntimeException('No subresource data provider.');
                }

                $data = $this->getSubresourceData($identifiers, $attributes, $context);
            }
        } catch (InvalidIdentifierException $e) {
            throw new NotFoundHttpException('Not found, because of an invalid identifier configuration', $e);
        }

        if (null === $data) {
            throw new NotFoundHttpException('Not Found');
        }

        $request->attributes->set('data', $data);
    }
45777
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
            return;
        }

        if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            foreach ($this->mimeTypes as $format => $mimeTypes) {
                if (method_exists(Request::class, 'getMimeTypes')) {
                    $mimeTypes = array_merge($mimeTypes, Request::getMimeTypes($format));
                } elseif (null !== $request->getMimeType($format)) {
                    $class = new \ReflectionClass(Request::class);
                    $properties = $class->getStaticProperties();
                    if (isset($properties['formats'][$format])) {
                        $mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
                    }
                }

                $request->setFormat($format, $mimeTypes);
            }
        }
    }