Get routes from the collection by method.

@param  string|null  $method
@return array
343589
public function get($method = null)
    {
        return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
    }
982434
public function getRoute($route = null)
    {
        $routes = $this->getConsole()->getRoutes($route);
        $l1 = 10; $l2 = 10; $l3 = 10;
        $list = "";
        foreach($routes as $route) {
            if($l1 < strlen($route[1])) {
                $l1 = strlen($route[1]);
            }
            if($l2 < strlen($route[0])) {
                $l2 = strlen($route[0]);
            }
            if($l3 < strlen($route[2])) {
                $l3 = strlen($route[2]);
            }
        }
        foreach($routes as $route) {
            $list .= 
"| $route[1]".str_repeat(' ',$l1-strlen($route[1]))." | $route[0]".str_repeat(' ',$l2-strlen($route[0]))." | $route[2]".str_repeat(' ',$l3-strlen($route[2]))." |
+".str_repeat('-',$l1+2)."+".str_repeat('-',$l2+2)."+".str_repeat('-',$l3+2)."+
";
        }
        $list = "
+".str_repeat('-',$l1+2)."+".str_repeat('-',$l2+2)."+".str_repeat('-',$l3+2)."+
| ".Colors::GREEN.Colors::BG_BLACK."URI".Colors::WHITE.Colors::BG_BLACK.str_repeat(' ',$l1-strlen('URI'))." | ".Colors::GREEN.Colors::BG_BLACK."Method".Colors::WHITE.Colors::BG_BLACK.str_repeat(' ',$l2-strlen('Method'))." | ".Colors::GREEN.Colors::BG_BLACK."Action".Colors::WHITE.Colors::BG_BLACK.str_repeat(' ',$l3-strlen('Action'))." |
+".str_repeat('-',$l1+2)."+".str_repeat('-',$l2+2)."+".str_repeat('-',$l3+2)."+
".$list;
        return $list;
    }
787082
protected function findRoute(UriInterface $url, $method = null)
    {
        $urlPath = $this->cleanUrl($url->getPath());
        $ret = null;
        
        foreach ($this as $pattern => $route) {
            list($path, $inc, $excl) = $this->splitRoutePattern($pattern);
            if ($path !== '/') $path = rtrim($path, '/');
            
            if ($this->fnmatch($path, $urlPath)) {
                if (!$method || ((empty($inc) || in_array($method, $inc)) && !in_array($method, $excl))) {
                    $ret = $route;
                    break;
                }
            }
        }

        return $ret;
    }
1348992
static public function getRoute($uri = null)
    {
        $routes = self::$instance->routes;
        if($uri === null) {
            foreach($routes as $i => $route) {
                $routes[$i] = \array_diff_key($routes[$i], [3 => "xy", 4 => "xy", 5 => "xy", 6 => "xy", 7 => "xy", 8 => "xy"]);
                if( !is_string($routes[$i][2]) && is_object($routes[$i][2]) && is_callable($routes[$i][2]) && $routes[$i][2] instanceof \Closure) {
                    $routes[$i][2] = "Closure";
                }
            }
            return $routes;
        }
        else {
            foreach($routes as $i => $route) {
                if($route[1] === "/".ltrim($uri,"/")) {
                    return $route;
                }
            }
        }
    }
1177136
protected function getCallParams($controller, $method, $params)
		{
			// variables
			$values     = is_array($params) ? $params : explode('/', $params);
			$ref        = new ReflectionMethod($controller, $method);
			$params     = $ref->getParameters();
			$args       = [];
	
			// map route segments to the method's parameters
			foreach ($params as /** @var \ReflectionParameter */ $param)
			{
				// parse signature [match, optional, type, name, default]
				preg_match('/<(required|optional)> (?:([\\\\a-z\d_]+) )?(?:\\$(\w+))(?: = (\S+))?/i', (string)$param, $matches);
	
				// assign untyped segments
				if ($matches[2] == null)
				{
					$args[$matches[3]] = array_shift($values);
				}
			}
	
			// append any remaining values
			return array_merge($args, $values);
		}
611746
public function getRoutesByMethod($method)
	{
		return ($this->routesByMethod && isset($this->routesByMethod[$method])) ? $this->routesByMethod[$method] : array();
	}
877175
public function method($method = null, $path = '/')
    {
        $parameters = array();

        $parameters['path'] = $path;

        if($method)
            $parameters['method'] = $method;

        $route = $this->factory->createRoute($this, null, $parameters);

        $this->addRoute($route);

        return $route;
    }
379249
protected function typeRoutes(?string $method): array
    {
        $routes = Arr::getArray($this->routes, $method);

        if ($method) {
            $routes = array_merge(Arr::getArray($this->routes, ''), $routes);
        }

        return $routes;
    }
423704
public function match($uri = null, $method = null)
    {
        $context = $this->_context;

        $uri = $uri ?: $this->getRewriteUri();

        if ($method === null) {
            $method = $this->request->getServer('REQUEST_METHOD');
        }

        $context->controller = null;
        $context->action = null;
        $context->params = [];

        $context->matched = false;

        if ($this->_prefix) {
            if (strpos($uri, $this->_prefix) === 0) {
                $handledUri = substr($uri, strlen($this->_prefix)) ?: '/';
            } else {
                $handledUri = false;
            }
        } else {
            $handledUri = $uri;
        }

        $area = null;
        $routes = $this->_simple_routes;
        if ($handledUri === false) {
            $parts = false;
        } elseif (isset($routes[$method][$handledUri])) {
            $parts = $routes[$method][$handledUri]->match($handledUri, $method);
        } elseif (isset($routes[''][$handledUri])) {
            $parts = $routes[''][$handledUri]->match($handledUri, $method);
        } else {
            $parts = false;
            $routes = $this->_regex_routes;
            for ($i = count($routes) - 1; $i >= 0; $i--) {
                $route = $routes[$i];
                if (($parts = $route->match($handledUri, $method)) !== false) {
                    if ($handledUri !== '/' && $this->_areas) {
                        if (($pos = strpos($handledUri, '/', 1)) === false) {
                            $area = Text::camelize(substr($handledUri, 1));
                        } else {
                            $area = Text::camelize(substr($handledUri, 1, $pos - 1));
                        }

                        if (!in_array($area, $this->_areas, true)) {
                            $area = null;
                        }
                    }
                    break;
                }
            }

            if ($parts === false) {
                if ($handledUri !== '/' && $this->_areas) {
                    if (($pos = strpos($handledUri, '/', 1)) !== false) {
                        $area = Text::camelize(substr($handledUri, 1, $pos - 1));
                        if (in_array($area, $this->_areas, true)) {
                            $handledUri = substr($handledUri, $pos);
                        } else {
                            $area = null;
                        }
                    } else {
                        $area = Text::camelize(substr($handledUri, 1));
                        if (in_array($area, $this->_areas, true)) {
                            $handledUri = '/';
                        } else {
                            $area = null;
                        }
                    }
                }

                $handledUri = $handledUri === '/' ? '/' : rtrim($handledUri, '/');
                $parts = $this->_default_route->match($handledUri, $method);
            }
        }

        if ($parts === false) {
            return false;
        }

        $context->matched = true;

        if ($area) {
            $context->area = $area;
        } elseif (isset($parts['area'])) {
            $context->area = $parts['area'];
        }

        $context->controller = $parts['controller'];
        $context->action = $parts['action'];
        $context->params = isset($parts['params']) ? $parts['params'] : [];

        return $context;
    }
1259863
public function dispatch($method = null, $path = null)
    {
        $match = $this->getMatch($method, $path);

        foreach ($match->before as $filter) {
            if (empty($filter)) {
                continue;
            }
            $response = $this->executeCallback($this->getFilterCallback($filter), $match->args, true);
            if (!is_null($response)) {
                return $response;
            }
        }

        $routeResponse = $this->executeCallback($match->callback, $match->args);

        foreach ($match->after as $filter) {
            if (empty($filter)) {
                continue;
            }
            array_unshift($match->args, $routeResponse);
            $response = $this->executeCallback($this->getFilterCallback($filter), $match->args, true);
            if (!is_null($response)) {
                return $response;
            }
        }

        return $routeResponse;
    }
586894
protected function matchRoute(array $routes, $method, IUrl $url) {
        foreach ($routes as $route) {
            if ($this->compareRouteToMethod($route, $method) &&
                $this->getUrlMatcher()->match($route->getPath(), $url->getPath()) &&
                $this->getRestrictionsMatcher()->match($url)
            ) {
                $parameters = $this->getUrlMatcher()
                    ->parse($route->getPath(), $url->getPath());

                $route->setParameters($parameters->toArray());

                return $route;
            }
        }

        return null;
    }
1293498
public function findRoute($method, $uri)
	{
		$this->method = $method;
		if ($this->routesTree === null) {
			$this->routesTree = $this->parseRoutes($this->rawRoutes);
		}

		$search = $this->normalize($uri);

		$node   = $this->routesTree;
		$params = [];

		//loop every segment in request url, compare it, collect parameters names and values
		foreach ($search as $key => $v) {

			if (isset($node[$v["use"]])) {
				$node = $node[$v["use"]];
			} else if (isset($node["*"])) {

				$subnode = $node["*"];
				if (($definitions = $this->rawRoutes[$subnode["routeName"]]["definitions"]) !== null) {
					if (isset($definitions[$subnode["name"]])) {
						$definition = $definitions[$subnode["name"]];
						$regex = ($definition[0] === "(") ? $definition : $this->getMatchType($definition, "(.*)");

						if ($regex === "(.*)") {
							break;
						} else {
							if (!preg_match($regex, $v['name'])) {
								throw new RouteNotFoundException("Route for uri: {$uri} was not found");
							}
						}
					}
				}
				// This sets node to continue
				$node = $subnode;
				$params[$subnode["name"]] = $v["name"];

			} else if (isset($node["?"])) {
				$node = $node["?"];

				if (($definitions = $this->rawRoutes[$method][$node["routeName"]]["definitions"]) !== null) {
					if (isset($definitions[$node["name"]])) {
						$definition = $definitions[$node["name"]];
						$regex = ($definition[0] === "(") ? $definition : $this->getMatchType($definition, "any");

						if ($regex === "(.*)") {
							$c = count($search);
							for ($i=$key; $i < $c; $i++) {
								$b[] = $search[$i]["use"];
							}
							$params[$node["name"]] = $b;
							break;
						} else {
							if (!preg_match($regex, $v['name'])) {
								continue;
							}
							$node = $node["?"];
							$params[$node["name"]] = $v["name"];
						}
					}
				}

				$params[$node["name"]] = $v["name"];
			} else {
				throw new RouteNotFoundException("Route for uri: {$uri} was not found");
			}

		}

		// Check for route with optional parameters that are not in request url until valid action is found
		// This make tree to go to last key
		while (!isset($node["exec"]) && isset($node["?"])) {
			$node = $node["?"];
		}

		if (isset($node["exec"])) {
			if (!isset($node["exec"]["method"][$method])
				&& !isset($node["exec"]["method"]["any"])
			) {
				throw new MethodNotAllowedException("Method: {$method} is not allowed for this route");
			}

			$Route = $node["exec"]["method"][$method];
			$Route->params = $params;
			if ($a = is_array($Route->action) || is_string($Route->action)) {
				if ($a) {
					$Route->action = [$Route->namespace.$Route->action[0], $Route->action[1]];
				} else {
					$Route->action = $Route->namespace.$Route->action;
				}
			}
			return $Route;
		}
		throw new RouteNotFoundException("Route for uri: {$uri} was not found");
	}
1049065
public function getRoutes() : array {
        $request = get_request();
        $requestMethod = $request->method();
        $requestPathParts = $request->pathParts();
        $routesIndex = $this->routesIndex;
        $routes = [];
        $this->getRoutesFromIndex($routes,$routesIndex, $requestMethod, $requestPathParts);
        return $routes;
    }
22879
public function findMethod($method = null)
    {
        if ($method === null) {
            return $this->getConfig('findMethod');
        }

        return $this->setConfig('findMethod', $method);
    }
811828
private function getTraces(RequestDataCollector $request, string $method): array
    {
        $traceRequest = Request::create(
            $request->getPathInfo(),
            $request->getRequestServer(true)->get('REQUEST_METHOD'),
            [],
            $request->getRequestCookies(true)->all(),
            [],
            $request->getRequestServer(true)->all()
        );

        $context = $this->matcher->getContext();
        $context->setMethod($method);
        $matcher = new TraceableUrlMatcher($this->routes, $context);

        return $matcher->getTracesForRequest($traceRequest);
    }
366485
public function dispatch($uri = null, $method = null)
    {
        if (!$router_context = $this->match($uri, $method)) {
            throw new NotFoundRouteException(['router does not have matched route for `:uri`', 'uri' => $this->getRewriteUri()]);
        }

        return $this->dispatcher->dispatch($router_context);
    }
53445
private function getMethods($methods)
    {
        $methods = $methods ?? $this->methods;

        if (is_string($methods))
            $methods = (array) $methods;

        return is_array($methods) ? array_map('strtoupper', $methods) : [];
    }