Returns matching area or null if not found

@param RequestInterface $request

@return AreaInterface|null
189622
protected function findMatchingArea(RequestInterface $request)
    {
        foreach ($this->areas as $area) {
            if (!$area->match($request)) {
                continue;
            }

            return $area;
        }

        return null;
    }
599875
public static function fromRequest(RequestInterface $request)
    {
        if ($request->hasHeader('X-Endpoint')) {
            $name = $request->getHeaderLine('X-Endpoint');
            
            if (! isset(BaseApi::$endpointDefinitions[$name])) {
                throw new \InvalidArgumentException('Could not resolve Endpoint from the request: \n'.$request->getRequestTarget());
            }
            
            /** @var BaseEndpoint $endpointClass */
            $endpointClass = BaseApi::$endpointDefinitions[$name]['class'];

            return new $endpointClass(Region::create($request->getHeaderLine('X-Region')));
        }
        
        $matchingScore = -1;
        /** @var Endpoint $endpointInstance */
        $endpointInstance = null;

        foreach (BaseApi::$endpointDefinitions as $urlTemplate => $definition) {
            $score = levenshtein($request->getRequestTarget(), $urlTemplate);
            if ($score > $matchingScore) {
                $matchingScore = $score;
                $endpointInstance = $definition['instance'];
            }
        }
        
        return $endpointInstance;
    }
696639
public function refresh($request)
    {
        $area = $request->param('Area');

        // Kind of a hack for making sure it goes back to its old ways if an allowed action is set
        if ($area != __FUNCTION__ && in_array(str_replace('-', '_', $area), $this->allowedActions())) {
            return RequestHandler::handleAction($request, str_replace('-', '_', $area));
        }

        // Only available via AJAX
        if (!$request->isAjax()) {
            return $this->httpError(404);
        }

        Requirements::clear();

        // If no area specified, do nothing
        if (!$area) {
            return [];
        }

        // Add additional messages via an extension (if you want to call an API etc.)
        $this->extend('onRefresh', $area, $request);

        Requirements::clear();

        $response = $this->getResponse();
        $response->addHeader('Content-type', 'application/json');
        $response->setBody(json_encode(singleton('message')->$area()->get()));
        return $response;
    }
55721
public function execute(RequestInterface $request)
    {
        $httpRequest = $this->httpRequestBuilder->build($request);

        $httpResponse = $this->transport->execute($httpRequest);

        return $this->resultBuilderEngine->build($request, $httpResponse);
    }
1316945
private function query(RequestInterface $request)
    {
        return $this->client->send($request, array_merge(
            [RequestOptions::HTTP_ERRORS => false],
            $this->clientOptions
        ));
    }
1194104
protected function getCached(RequestInterface $request)
    {
        if (!$this->isSupportedMethod($request)) {
            return null;
        }

        $cacheKey = self::getKey($request);
        if (is_null($cachedContent = $this->cache->get($cacheKey))) {
            return null;
        }

        $cached = unserialize($cachedContent);
        foreach ($cached as $value) {
            if (is_null($value)) {
                return null;
            }
        }

        // rebuild response with cache entry : status, headers, body, protocol version, reason
        $response = new Response($cached[0], $cached[1], $cached[2], $cached[3], $cached[4]);

        $response->cached = true;

        // set ttl information only on debug mode
        if ($this->debug) {
            $response->cacheTtl = $this->cache->ttl($cacheKey);
        }

        return $response;
    }
430297
public function request(RequestInterface $request)
    {
        $response = $this->httpClient->sendRequest($request);
        $data = $this->decodeResponse($response);
        $this->detectError($data);

        return $data;
    }
977926
private function normalizeRequest(RequestInterface $request): RequestInterface
    {
        $uri = $request->getUri();
        $updated = false;

        $normalizedPath = preg_replace('~/{2,}~', '/', $uri->getPath());

        $normalizedPath = preg_replace('~/\.(/|$)~', '/', $normalizedPath);
        do {
            $normalizedPath = preg_replace('~/[^/]+(?<!\.\.)/+\.\.(/|$)~', '/', $normalizedPath, 1, $count);
        } while ($count);

        $normalizedPath = $this->decodePercentEncoding($normalizedPath);

        if ($uri->getPath() !== $normalizedPath) {
            $uri = $uri->withPath($normalizedPath);
            $updated = true;
        }

        $normalizedQuery = $this->decodePercentEncoding($uri->getQuery());

        if ($uri->getQuery() !== $normalizedQuery) {
            $uri = $uri->withQuery($normalizedQuery);
            $updated = true;
        }

        if ($updated) {
            return $request->withUri($uri);
        }

        return $request;
    }
106025
public function applyToRequest(RequestInterface $request)
    {
        $body = $this->streamFactory->createStream((string) $this->queryHelper);

        return $request
            ->withBody($body)
            ->withHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
565476
public static function nonce(RequestInterface $request = null)
    {
        $url = $request ? $request->getUrl() : null;

        return sha1(uniqid('', true) . $url);
    }
823632
protected function getHostFromRequest(RequestInterface $request): string
    {
        $host = trim($request->getUri()->getHost(), '/');

        if (array_key_exists($host, $this->domainAliases)) {
            return $this->domainAliases[$host];
        }

        return $host;
    }
27221
public function findMenuPointForRequest(Request $request)
    {
        $items = $this->menuRepository->findByComponentAndView('com_symfony', 'wrap');

        foreach ($items as $item) {
            $link = $item->getLink();

            $params = self::parseParameters($link);

            if (!isset($params['pattern'])) {
                continue;
            }

            $pattern = $params['pattern'];

            if (preg_match('#' . $pattern . '#i', $request->getPathInfo())) {
                return $item;
            }
        }

        return null;
    }
1110493
public function findByRequest(Request $request)
    {
        $qb = $this->createQueryBuilder('s');

        if ($request->get('attribute')) {
            $qb->join('s.allowedInAttributes', 'a')
                ->andWhere('a.id = :attributeId')
                ->setParameter('attributeId', $request->get('attribute'));
        }

        return $qb->getQuery()->getArrayResult();
    }
213393
public function findByRequest(Request $request): ?PageInterface
    {
        if (null !== $route = $request->attributes->get('_route', null)) {
            return $this->findByRoute($route);
        }

        return null;
    }
1325125
public function postVerify($area, Request $request)
    {
        $area = app(AreaManager::class)->getById($area);
        return $this->processor->verifyCredentials($this, $area, $request->input());
    }
3493
private function getCutoffrequencyLimit(RequestInterface $request)
    {
        $indexStatsResponse = $this->client->indexStats($request->getIndex());
        $indexStats         = current($indexStatsResponse['indices']);
        $totalIndexedDocs = $indexStats['total']['docs']['count'];

        return $request->getCutoffFrequency() * $totalIndexedDocs;
    }
1267870
private function getHttpResponse(RequestInterface $request): ?ResponseInterface
    {
        try {
            return $this->httpClient->send($request);
        } catch (TooManyRedirectsException $tooManyRedirectsException) {
            return $this->httpHistoryContainer->getLastResponse();
        } catch (BadResponseException $badResponseException) {
            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $badResponseException->getResponse();
            }

            return $this->getHttpResponse($request);
        } catch (HttpConnectException $connectException) {
            throw $connectException;
        } catch (RequestException $requestException) {
            if ($this->isCurlException($requestException)) {
                throw new HttpConnectException(
                    $requestException->getMessage(),
                    $requestException->getRequest(),
                    $requestException->getPrevious()
                );
            }

            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $requestException->getResponse();
            }

            return $this->getHttpResponse($request);
        }
    }