Find called route

@param \Psr\Http\Message\ServerRequestInterface $p_request

@return \FreeFW\Router\Route | false
355458
public function findRoute(\Psr\Http\Message\ServerRequestInterface &$p_request)
    {
        if ($this->routes instanceof \FreeFW\Router\RouteCollection) {
            $params     = $p_request->getServerParams();
            $currentDir = '/';
            $requestUrl = '';
            if (array_key_exists('_request', $_GET)) {
                $requestUrl = '/' . ltrim($_GET['_request'], '/');
            }
            if (($pos = strpos($requestUrl, '?')) !== false) {
                if (array_key_exists('_url', $_GET)) {
                    $requestUrl = $_GET['_url'];
                } else {
                    $requestUrl = substr($requestUrl, 0, $pos);
                }
            }
            $currentDir = rtrim($this->base_path, '/');
            $this->logger->debug('router.findRoute.request : ' . $requestUrl);
            foreach ($this->routes->getRoutes() as $idx => $oneRoute) {
                $this->logger->debug('router.findRoute.test : ' . $oneRoute->getUrl());
                if (strtoupper($p_request->getMethod()) == strtoupper($oneRoute->getMethod())) {
                    if ($currentDir != '/') {
                        $requestUrl = str_replace($currentDir, '', $requestUrl);
                    }
                    $params = array();
                    if ($oneRoute->getUrl() == $requestUrl) {
                        // Ok, pas besoin de compliquer....
                    } else {
                        // @todo : ajouter la notion obligatoire pour les paramètres
                        if (!preg_match("#^" . $oneRoute->getRegex() . "$#", $requestUrl, $matches)) {
                            continue;
                        }
                        // Ok
                        // On a trouvé une route, on récupère les paramètres.
                        // On va en profiter pour les injecter dans la requête
                        $matchedText = array_shift($matches);
                        if (preg_match_all("/:([\w-\._@%]+)/", $oneRoute->getUrl(), $argument_keys)) {
                            $argument_keys = $argument_keys[1];
                            if (count($argument_keys) != count($matches)) {
                                continue;
                            }
                            foreach ($argument_keys as $key => $name) {
                                if (isset($matches[$key]) && $matches[$key] !== null
                                    && $matches[$key] != '' && $matches[$key] != '/'
                                ) {
                                    $params[$name] = ltrim($matches[$key], '/'); // Pour les paramètres optionnel
                                } else {
                                    $params[$name] = '';
                                }
                            }
                        }
                        foreach ($params as $name => $value) {
                            $p_request = $p_request->withAttribute($name, $value);
                        }
                    }
                    $this->logger->debug('router.findRoute.match : ' . $oneRoute->getUrl());
                    return $oneRoute;
                }
            }
        }
        return false;
    }
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;
    }
540383
public function locateApacheServer() : bool
    {
        if ($this->getApacheCtl()) {
            $this->getApacheInfo();
            $this->getApacheInstancesPath();
            $this->getPHPModule();
        }

        return $this->apachectl !== false && $this->apache_config_path !== false;
    }
1188917
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllAddresses(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllAddresses();
        }
    }
908289
public function find(Request $request, array $routes)
    {
        foreach ($routes as $route) {

            if(!$this->matchMethod($request, $route)){
                continue;
            }

            if(!$this->matchContentType($request, $route)){
                continue;
            }

            if(!$this->matchFilters($route)){
                continue;
            }

            $routeMatches = $this->matchPattern($request, $route);
            if ($routeMatches) {
                $route->setMatches($routeMatches);
                return $route;
            }
        }
        throw new RouteException(
            sprintf('No route found for uri "%s"', $request->getRequestUri()),
            $request,
            $routes
        );
    }
1024972
public function findRoute($pUri, $pMethod = '_all_')
    {
        if (isset($this->routes[$pUri][$pMethod]) && $method = $this->routes[$pUri][$pMethod]) {
            return array($method, array(), $pMethod, $pUri);
        } elseif ($pMethod != '_all_' && isset($this->routes[$pUri]['_all_']) && $method = $this->routes[$pUri]['_all_']) {
            return array($method, array(), $pMethod, $pUri);
        } else {
            //maybe we have a regex uri
            foreach ($this->routes as $routeUri => $routeMethods) {

                if (preg_match('|^'.$routeUri.'$|', $pUri, $matches)) {

                    if (!isset($routeMethods[$pMethod])) {
                        if (isset($routeMethods['_all_']))
                            $pMethod = '_all_';
                        else
                            continue;
                    }

                    array_shift($matches);
                    foreach ($matches as $match) {
                        $arguments[] = $match;
                    }

                    return array($routeMethods[$pMethod], $arguments, $pMethod, $routeUri);
                }

            }
        }

        return false;
    }
538084
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllStripeGateways(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllStripeGateways();
        }
    }
696988
public function route(Request &$request)
	{
		$routeInfo = $this->dispatcher->dispatch(
			$request->getMethod(),
			$request->getUri()->getPath()
		);

		if ($routeInfo[0] !== \FastRoute\Dispatcher::FOUND) {
			return false;
		}

		foreach ($routeInfo[2] as $key => $val) {
			$request = $request->withAttribute($key, $val);
		}
		return $routeInfo[1];
	}
1328714
public static function getRoute(string $route_name) {
		// return the route of false
		return self::hasRoute($route_name) ? self::$_routes[$route_name] : false;
	}
697799
private function route(Request $request) : RouteMatch
    {
        foreach ($this->routes as $route) {
            try {
                $match = $route->match($request);
            }
            catch (RoutingException $e) {
                throw new HttpNotFoundException($e->getMessage(), $e);
            }

            if ($match !== null) {
                if ($match instanceof RouteMatch) {
                    return $match;
                }

                throw $this->invalidReturnValue('route', Route::class . ' or NULL', $match);
            }
        }

        throw new HttpNotFoundException('No route matches the request.');
    }
53043
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        try {
            $route = $this->matchRoute($request);
        } catch (RouteException $e) {
            throw new RouterException("Invalid route definition", $e->getCode(), $e);
        }

        if (empty($route)) {
            throw new RouteNotFoundException($request->getUri());
        }

        return $this->container->get(ScopeInterface::class)->runScope(
            [RouteInterface::class => $route],
            function () use ($route, $request) {
                return $route->handle($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());
   }
37003
function match(RequestInterface $request)
    {
        if ($preReq = $this->getPreparator()) {
            $request = $preReq->withRequestOnMatch($request);

            if (! $request instanceof RequestInterface )
                throw new \RuntimeException(sprintf(
                    'Missing RequestInterface While Preparing Request Object Through (%s).'
                    , \Poirot\Std\flatten($preReq)
                ));
        }


        ## match against connected routers if exists
        if (empty($this->routesAdd))
            return false;

        # build queue list for routers to match:

        # match routes:
        $routeMatch = false;
        foreach($this->_priorityQueue() as $route) {
            /** @var iRoute $r */
            $r = $route;
            if ($routeMatch = $r->match($request)) break;
        }

        ## if route match merge stack default params with match route
        /** @var iRoute $routeMatch */
        if ($routeMatch) {
            # $routeMatch = clone $routeMatch; // this can be skipped because use of match on each route
            \Poirot\Router\mergeParamsIntoRouter($routeMatch, $this->params());
        }

        return $routeMatch;
    }
165824
public function match(Request $request)
    {
        try {
            return parent::match($request);
        } catch (NotFoundHttpException $e) {
            $route = $this->findMatchingWordpressPost();

            if ( ! is_null($route)) {
                return $route->bind($request);
            }

            throw $e;
        }
    }
522681
public function getRoute(Request $request)
    {
        /*
         * This method allows CPanel to hook into our API calls that require Cpanel specific functionality.
         * Be VERY careful editing it, make sure you're code only fires for the specific API call you need to interact with.
         */

        //Load up our routes and replace their placeholders (i.e. :id changes to [0-9a-z]{32})
        foreach ($this->routes as $routeKey => $route_details_array) {
            //Replace placeholders in route
            $regex = str_replace(
                array_keys(static::$API_ROUTING_PLACEHOLDERS),
                array_values(static::$API_ROUTING_PLACEHOLDERS),
                $routeKey
            );

            //Check to see if this is our route
            if (preg_match('#^'.$regex.'/?$#', $request->getUrl())) {
                if (in_array($request->getMethod(), $route_details_array['methods']) || array_key_exists(
                    $request->getMethod(),
                    $route_details_array['methods']
                )
                ) {
                    $this->logger->debug('Route matched for '.$request->getMethod().$request->getUrl().' now using '.$route_details_array['methods'][$request->getMethod()]['function']);

                    return array(
                        'class' => $route_details_array['class'],
                        'function' => $route_details_array['methods'][$request->getMethod()]['function'],
                    );
                }
            }
        }

        //if no route was found call our API normally
        return false;
    }
1202366
public function match(ServerRequestInterface $request)
    {
        $method = strtoupper($request->getMethod());
        if (! empty($this->methods) && ! in_array($method, $this->methods)) {
            return false;
        }
        $uri    = $request->getUri();
        $scheme = $uri->getScheme();
        if (! empty($this->schemes) && ! in_array($scheme, $this->schemes)) {
            return false;
        }
        $path = rtrim($uri->getPath(), '/');

        $regex  = $this->compiled;
        $result = preg_match($regex, $path, $matches);

        if (! $result) {
            return false;
        }

        $params = $this->defaults;
        foreach ($matches as $key => &$value) {
            if (is_int($key)) {
                continue;
            }
            if ($value === '') {
                continue;
            }
            $params[$key] = $value;
        }
        $params['request_method'] = $method;
        $params['request_scheme'] = $scheme;

        return new RouteMatch($params);
    }
981880
public function match($path, RouteRequest $request = null)
    {
        $requestMethod = null;

        if ($request) {

            $requestMethod = self::convertRequestMethodConstant($request->getRequestMethod());

        } else if (isset($_SERVER['REQUEST_METHOD'])) {

            $requestMethod = self::convertRequestMethodConstant($_SERVER['REQUEST_METHOD']);

        }

        foreach ($this->routes as $route) {
            // If the route is using pcre pattern marching...
            if ($route[0]) {
                if (!preg_match($route[1], $path, $matches)) {
                    continue;
                }
                $route[3]['vars'] = $matches;

                // validate request method
                if (isset($route[3]['method']) && $route[3]['method'] != $requestMethod) {
                    continue;
                }
                if (isset($route[3]['domain']) && $route[3]['domain'] != $_SERVER['HTTP_HOST']) {
                    continue;
                }
                if (isset($route[3]['secure']) && $route[3]['secure'] && $_SERVER['HTTPS']) {
                    continue;
                }

                return $route;
            } else {
                // prefix match is used when expanding is not enabled.
                if ((
                        (is_int($route[2]) || $route[2] instanceof self || $route[2] instanceof \PHPSGI\App)
                        && strncmp($route[1], $path, strlen($route[1])) === 0
                    ) || $route[1] == $path) {
                    // validate request method
                    if (isset($route[3]['method']) && $route[3]['method'] != $requestMethod) {
                        continue;
                    }
                    if (isset($route[3]['domain']) && $route[3]['domain'] != $_SERVER['HTTP_HOST']) {
                        continue;
                    }
                    if (isset($route[3]['secure']) && $route[3]['secure'] && $_SERVER['HTTPS']) {
                        continue;
                    }

                    return $route;
                }
                continue;
            }
        }
    }