Map the route to the correct key in the index.

@param string $route current route used to access page.

@return string as key or false if no match.
962882
private function mapRoute2IndexKey($route)
    {
        $route = rtrim($route, "/");

        if (key_exists($route, $this->index)) {
            return $route;
        } elseif (empty($route) && key_exists("index", $this->index)) {
            return "index";
        } elseif (key_exists($route . "/index", $this->index)) {
            return "$route/index";
        }

        return false;
    }
390651
protected function addWhereClausesToRoute($route)
    {
        $route->where(array_merge(
            $this->patterns, $route->getAction()['where'] ?? []
        ));

        return $route;
    }
579604
protected function getRouteScheme( $route )
	{
		if ( $route->httpOnly() )
		{
			return $this->getScheme( false );
		}
		elseif ( $route->httpsOnly() )
		{
			return $this->getScheme( true );
		}

		return $this->getScheme( null );
	}
871601
private function mapRoute2Index($route)
    {
        $routeIndex = $this->mapRoute2IndexKey($route);

        if ($routeIndex) {
            return [$routeIndex, $this->index[$routeIndex]];
        }

        $msg = t("The route '!ROUTE' does not exists in the index.", [
            "!ROUTE" => $route
        ]);
        throw new \Anax\Exception\NotFoundException($msg);
    }
970717
protected static function dynamic($route)
    {
        $parms = [];
        $param = '';
        $open = false;
        //
        for ($i = 0; $i < Strings::length($route); $i++) {
            if ($open && $route[$i] != '}') {
                $param .= $route[$i];
            }
            //
            if ($route[$i] == '{' && !$open) {
                $open = true;
            } //
            elseif ($route[$i] == '}' && $open) {
                $open = !true;
                $parms[] = $param;
                $param = '';
            }
        }
        //
        return $parms;
    }
456331
private function searchRouter($routes) 
    {
        foreach ($routes as $route) {
            if (!preg_match_all('#^' . $route['request'] . '$#', $this->request, $matches, PREG_OFFSET_CAPTURE))
                continue;
            // Rework matches to only contain the matches, not the orig string
            $matches = array_slice($matches, 1);

            // Extract the matched URL parameters (and only the parameters)
            $params = array_map(function ($match, $index) use ($matches) {

                // We have a following parameter: take the substring from the current param position until the next one's position (thank you PREG_OFFSET_CAPTURE)
                if (isset($matches[$index + 1]) && isset($matches[$index + 1][0]) && is_array($matches[$index + 1][0])) {
                    return trim(substr($match[0][0], 0, $matches[$index + 1][0][1] - $match[0][1]), '/');
                } // We have no following parameters: return the whole lot
                else {
                    return (isset($match[0][0]) ? trim($match[0][0], '/') : null);
                }
            }, $matches, array_keys($matches));

            $route['params'] = $params;
            return $route;
        }
        //not exists ...
        return false;
    }
676963
public function setRoute($route)
        {
            if (null !== $route && (!is_string($route) || strlen($route) < 1)) {
                throw new Exception(
                    'Invalid argument: $route must be a non-empty string or null'
                );
            }

            $this->_route     = $route;
            $this->_hrefCache = null;

            return $this;
        }
912242
private function getRouteName($route = null)
    {
        return null === $route ? $this->request->attributes->get('_route') : $route;
    }
1148296
public function parseRoute (Route $route) {

		if (preg_match_all('#^' . $route->getRoute () . '$#', $this->getUrl (), $matches, PREG_OFFSET_CAPTURE)) {

			// Rework matches to only contain the matches, not the orig string
			$matches = array_slice($matches, 1);

			// Extract the matched URL parameters (and only the parameters)
			$params = array_map(function($match, $index) use ($matches) {

				// We have a following parameter: take the substring from the current param position until the next one's position (thank you PREG_OFFSET_CAPTURE)
				if (isset($matches[$index+1]) && isset($matches[$index+1][0]) && is_array($matches[$index+1][0])) {
					return trim(substr($match[0][0], 0, $matches[$index+1][0][1] - $match[0][1]), '/');
				}

				// We have no following paramete: return the whole lot
				else {
					return (isset($match[0][0]) ? trim($match[0][0], '/') : null);
				}

			}, $matches, array_keys($matches));

			if (empty ($params)) {
				return true;
			}
			else {
				return $params;
			}
		}

		return false;
	}
590417
private function methodMatches(array $route)
    {
        $methods = explode('|', $route['method']);
        if (in_array($this->method, $methods)) {
            return true;
        }

        return false;
    }
415727
private function getRouteParam($route, $param)
    {
        $route = (array) $route;
        $prefix = chr(0).'*'.chr(0);
        
        return $this->arrayGet(
            $route, 
            $prefix.$param, 
            $this->arrayGet($route, $param)
        );
    }
1016944
public function add(Route $route)
    {
        $this->routes[] = $route;

        $this->addLookups($route);

        return $route;
    }
459989
protected function _parse($route) {
		if (is_string($route)) {
			$this->_ensureHere();

			$url = parse_url($route);
			$_path = rtrim($url['path'], '/');
			if ($_path . '?' . Hash::get($url, 'query') === $this->_hereQuery) {
				return true;
			}

			if ($_path === $this->_here) {
				return true;
			}

			return false;
		}

		$count = count($route);
		if ($count == 0) {
			return false;
		}

		foreach ($route as $key => $value) {
			if (array_key_exists($key, $this->request->params)) {
				$values = (array)$value;
				$check = (array)$this->request->params[$key];

				$hasNullValues = (count($values) != count(array_filter($values)) || count($values) == 0);
				$currentValueIsNullish = (in_array(null, $check) || in_array('', $check) || count($check) == 0);
				if ($hasNullValues && $currentValueIsNullish) {
					$count--;
					continue;
				}

				if (in_array($key, array('controller', 'plugin'))) {
					foreach ($check as $k => $_check) {
						$check[$k] = Inflector::underscore(strtolower($_check));
					}
				} else {
					foreach ($check as $k => $_check) {
						$check[$k] = strtolower($_check);
					}
				}

				if (count($values) > 0) {
					foreach ($values as $k => $v) {
						if (in_array(strtolower($v), $check)) {
							$count--;
							break;
						}
					}
				} elseif (count($check) === 0) {
					$count--;
				}
			} elseif (is_numeric($key) && isset($this->request->params['pass'])) {
				if (is_array($this->request->params['pass'])) {
					if (Hash::contains($this->request->params['pass'], $value)) {
						$count--;
					}
				}
			}
		}

		return ($count == 0);
	}
353386
protected function getRegExpRoute($route)
    {
        return preg_replace_callback(
            '#(/?)\{(\S+?)(:(\S+?))?\}#',
            function (array $matches) {
                $startMod = $matches[1];
                $name = $matches[2];
                $type = isset($matches[4]) ? $matches[4] : 'string';

                $type = $this->getTypeRegexp($type);

                $regexp = $startMod . "(?P<$name>$type)";
                if (!$this->isRequiredParam($name)) {
                    $regexp = "({$regexp})?";
                }

                return $regexp;
            },
            $route
        );
    }
125514
protected function addLookups($route)
    {
        // If the route has a name, we will add it to the name look-up table so that we
        // will quickly be able to find any route associate with a name and not have
        // to iterate through every route every time we need to perform a look-up.
        if ($name = $route->getName()) {
            $this->nameList[$name] = $route;
        }

        // When the route is routing to a controller we will also store the action that
        // is used by the route. This will let us reverse route to controllers while
        // processing a request and easily generate URLs to the given controllers.
        $action = $route->getAction();

        if (isset($action['controller'])) {
            $this->addToActionList($action, $route);
        }
    }
82454
public function match($route, $method = 'GET', $options = [])
    {
        $route = RouteHelper::normalise($route);

        $this->count = 0;

        $this->buildRouteMaps();

        $keys = array_keys($this->routeMaps);

        $left = 0;
        $right = count($this->routeMaps) - 1;

        while ($left <= $right) {
            $middle = round(($left + $right) / 2);
            $key = $keys[$middle];
            $routeItem = $this->routes[$this->routeMaps[$key]];

            $this->count++;

            if ($this->matchOptions($routeItem, $method, $options) && $this->matchRoute($route, $routeItem)) {
                return $routeItem;
            }

            if (strcmp($route, $key) < 0) {
                $right = $middle - 1;
            } else {
                $left = $middle + 1;
            }
        }

        return false;
    }
861046
private function getMethods(Route $route)
    {
        $methods = $route->getMethods();
        sort($methods);

        return implode('|', $methods) ?: 'ANY';
    }