Get an array of allowed methods and their routes.

@param ServerRequestInterface $request
@return array
978505
private function getAllowedMethods(ServerRequestInterface $request): array
    {
        $allowed = [];

        $requestPath = $request->getUri()->getPath();

        foreach (Method::all() as $method) {
            $matchThis = "$requestPath{}$method";

            if (preg_match($this->pattern, $matchThis, $matches) === 1) {
                $allowed[$method] = $this->getRoute($matches);
            }
        }

        return $allowed;
    }
130582
public function dispatch(ServerRequestInterface $request): ResponseInterface
    {
        if ($this->currentRoute === null) {
            return $this->generate404($request);
        }

        foreach ($this->hostParameters as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        foreach ($this->currentRoute->getHostParameters() as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        foreach ($this->routeParameters as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        $this->pushMiddlewaresToApplyInPipe();

        return $this->handle($request);
    }
935276
protected function getFromPath(ServerRequestInterface $request)
    {
        $uri   = $request->getUri();
        $regex = '~^\/?' . $this->getRegEx() . '\b~';
        $path = rtrim( $uri->getPath(), '/\\' ) . '/';

        if ( preg_match($regex, $path, $matches) ) {
            if (isset($matches['language'])) {
                return $matches['language'];
            } else {
                throw new RuntimeException('The regular expression pattern is missing a named subpattern "language".');
            }
        }
    }
627513
protected function getMiddlewareHandlers(\Owl\Http\Request $request)
    {
        if (!$this->middleware_handlers) {
            return [];
        }

        $request_path = $this->getRequestPath($request);

        $result = [];
        foreach ($this->middleware_handlers as $path => $handlers) {
            if (strpos($request_path, $path) === 0) {
                $result = array_merge($result, $handlers);
            }
        }

        return $result;
    }
691850
public function index(ServerRequestInterface $request)
    {
        if ($this->shouldCheckPermissions()) {
            $authenticated_user = $this->getAuthenticatedUser($request);

            if (!$this->canList($authenticated_user)) {
                return new ForbiddenStatusResponse();
            }
        }

        $collection_class = $this->getCollectionClassName();

        /** @var CollectionInterface $collection */
        $collection = $this->$collection_class;

        if ($collection instanceof CollectionInterface) {
            if ($collection->isPaginated()) {
                return $collection->currentPage($this->getPageFromQueryParams($request->getQueryParams()));
            } else {
                return $collection;
            }
        } else {
            throw new CollectionNotFoundException(get_class($this), __FUNCTION__, $collection_class);
        }
    }
845434
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return $this->dispatchRoute($this->resolve($request), $request);
    }
444807
public final function match(ServerRequestInterface &$request): RouteInterface
   {
       foreach ($this->route as $value) {
           if ($this->matcher->match($request, $value)) {
               return $value;
           }
       }
       throw new RouterException(
           "Can't match "
         . $request->getMethod() . " "
         . $request->getUri()->getPath());
   }
408495
protected function getFromQuery(ServerRequestInterface $request)
    {
        $params = array_intersect_key($request->getQueryParams(), array_flip($this->getQueryKeys()));
        $regex  = '~^\/?' . $this->getRegEx() . '\b~';

        foreach ($params as $key => $value) {
            if ( preg_match($regex, $value, $matches) ) {
                if (isset($matches['language'])) {
                    return $matches['language'];
                } else {
                    throw new RuntimeException('The regular expression pattern is missing a named subpattern "language".');
                }
            }
        }
    }
1252957
protected function isPossibleToGetFromRequest(ServerRequestInterface $request)
    {
        if ($this->allowOverride instanceof OverridePolicyInterface) {
            $allowOverride = $this->allowOverride->isAllowToOverride($request);
        } else {
            $allowOverride = $this->allowOverride;
        }

        return $allowOverride === true && $request->hasHeader($this->requestHeader);
    }
73240
protected function _getData(ServerRequestInterface $request)
    {
        $fields = $this->_config['fields'];
        $body = $request->getParsedBody();

        $data = [];
        foreach ($fields as $key => $field) {
            if (!isset($body[$field])) {
                return null;
            }

            $value = $body[$field];
            if (!is_string($value) || !strlen($value)) {
                return null;
            }

            $data[$key] = $value;
        }

        return $data;
    }
697177
private function scanIps(ServerRequestInterface $request)
    {
        $server = $request->getServerParams();
        $ips = [];

        if ($this->remote) {
            $ips[] = file_get_contents('http://ipecho.net/plain');
        }

        foreach ($this->headers as $name) {
            $header = $request->getHeaderLine($name);

            if (!empty($header)) {
                foreach (array_map('trim', explode(',', $header)) as $ip) {
                    if ((array_search($ip, $ips) === false) && filter_var($ip, FILTER_VALIDATE_IP)) {
                        $ips[] = $ip;
                    }
                }
            }
        }

        if (!empty($server['REMOTE_ADDR']) && filter_var($server['REMOTE_ADDR'], FILTER_VALIDATE_IP)) {
            $ips[] = $server['REMOTE_ADDR'];
        }

        return $ips;
    }
679658
private function getOverrideMethod(ServerRequestInterface $request): string
    {
        if ($request->getMethod() === 'POST' && $this->parsedBodyParameter !== null) {
            $params = $request->getParsedBody();

            if (isset($params[$this->parsedBodyParameter])) {
                return strtoupper($params[$this->parsedBodyParameter]);
            }
        } elseif ($request->getMethod() === 'GET' && $this->queryParameter !== null) {
            $params = $request->getQueryParams();

            if (isset($params[$this->queryParameter])) {
                return strtoupper($params[$this->queryParameter]);
            }
        }

        return strtoupper($request->getHeaderLine(self::HEADER));
    }
569623
public static function getRequestLine(ServerRequestInterface $request): string
    {
        return sprintf(
            '%s %s%s %s',
            self::getMethod($request),
            self::getPath($request),
            self::getQuery($request),
            self::getProtocol($request)
        );
    }
716799
protected function findActiveLayersWithoutHttpMethodCheck(ServerRequestInterface $request): array
    {
        return $this->resolver->findActiveLayers($this->store->getLayers(), $request, false);
    }
702872
protected function dispatch(Request $request): array
    {
        $route = $this->router->match($request);
        $status = array_shift($route);

        if (Router::FOUND === $status) {
            return $route;
        }

        if (Router::METHOD_NOT_ALLOWED === $status) {
            throw ProtocolException::methodNotAllowed(
                $request->getMethod(),
                $request->getRequestTarget(),
                $request->getProtocol()
            );
        }

        unset($status, $route);

        throw ProtocolException::notFound($request->getRequestTarget());
    }
1065021
protected function matchRoute(ServerRequestInterface $request): ?RouteInterface
    {
        foreach ($this->routes as $route) {
            // Matched route will return new route instance with matched parameters
            $matched = $route->match($request);

            if (!empty($matched)) {
                return $matched;
            }
        }

        if (!empty($this->default)) {
            return $this->default->match($request);
        }

        // unable to match any route
        return null;
    }
201021
public function getRoute(RequestInterface $request)
    {
        $route = $request->getUri()->__toString();
        if ($request->getMethod() === 'DELETE' && strpos($request->getUri(), 'messages') !== false) {
            $route = 'DELETE-'.$request->getUri();
        }

        return $route;
    }