matches the user defined routes

@return mixed $handler see get_handler_type()
341139
private function find_custom_handler() {
	// get user defined routes
	$routes = $this->get_custom_routes();
	if (empty($routes) || empty($routes[$this->method])) {
		return false;
	}
	
	// catch the non-regex routes first
	if (isset($routes[$this->method][$this->url])) {
		return $routes[$this->method][$this->url];
	}
	
	// find a matching regex
	$handler = false;
	foreach ($routes[$this->method] as $url_regex => $possible_handler) {
		if (preg_match('{^'.$url_regex.'$}', $this->url, $matches)) {
			$handler = $possible_handler;
			
			// save named subpatterns from the regex, to send them through to the handler
			if (strpos($url_regex, '?<') && count($matches) > 1) {
				$this->arguments = $matches;
			}
			break;
		}
	}
	
	return $handler;
}
999268
private function parsePath()
    {
        $components = array();
        $uri = $this->getUri();

        if ($uri !== false) {
            Logger::get()->debug('Parsing URI: ' . $uri);
            // Add the URL parameters.
            $components = $this->getHttpParameters();

            $matched = false;
            foreach (self::getRoutes() as $route) {
                if (preg_match("#^{$route['uri']}$#", $uri, $matches)) {
                    Logger::get()->debug('Found a matching route: ' . $route['uri']);
                    foreach ($route as $name => $value) {
                        switch ($name) {
                            case 'uri':
                                // Ignore.
                                break;
                            default:
                                if (is_numeric($value)) {
                                    // If the value is a number, it refers to a
                                    // regex block in the route.
                                    if (isset($matches[$value])) {
                                        $components[$name] = $matches[$value];
                                    }
                                } else {
                                    // Otherwise it's the parameter's value.
                                    $components[$name] = $value;
                                }
                                break;
                        }
                    }

                    $matched = true;
                    break;
                }
            }

            // If no matching routes have been found, the request is not
            // considered valid.
            if (!$matched) {
                throw new Exception("No routes match URI '{$uri}'.", 404);
            }
        }

        return $components;
    }
1222044
public function match(Request $request)
	{
		foreach ($this->routes->filterByMethod($request->getMethod()) as $route)
		{
			if ($route->isMatch($request->getPathInfo()))
			{
				return $route;
			}
		}

		return null;
	}
1176554
public function matchesRequest()
    {
        return Collection::make($this->config->get('matchingData'))->diffAssoc($this->event)->isEmpty();
    }
261861
public function to($handler): RegexRouter
    {
        if (! \is_string($handler) && ! \is_object($handler) && ! \is_callable($handler)) {
            throw new Exception\InvalidArgumentException(\sprintf(
                'Invalid handler provided. Expected type is string, object or callable but type of %s given.',
                \gettype($handler)
            ));
        }

        if (null === $this->tmpPattern) {
            throw new Exception\RuntimeException(\sprintf(
                'Cannot map handler %s to a pattern. Please use method route before calling method to',
                \is_object($handler)
                    ? \get_class($handler)
                    : (\is_string($handler) ? $handler : \gettype($handler))
            ));
        }

        $this->patternMap[] = [$this->tmpPattern => $handler];

        $this->tmpPattern = null;

        return $this;
    }
1085804
protected function matchDirect()
    {
        // Create variable used to keep track on progress
        $endpoint = false;

        // check without a trailing slash
        if (isset($this->routes[$this->requestUri])) {
            $endpoint = $this->routes[$this->requestUri];
        } else {
            // no match return false
            return false;
        }

        // check if endpoint class exists
        if (!$this->endpointExists($endpoint)) {
            throw new NotFound();
        } elseif (!$this->endpointMethodExists($endpoint, $this->requestMethod)) {
            // route found but method can't be found
            throw new MethodNotAllowed();
        }

        // found a direct match, set needed properties
        $this->matchedRoute = $this->requestUri;
        $this->matchedEndpoint = $endpoint;
        $this->matchedMethod = $this->requestMethod;

        // we found our match, stop looking for more
        return true;
    }
621536
protected function getRoutes()
    {
        $c = parent::ROUTE_PATTERN_CONTROLLER;
        $a = parent::ROUTE_PATTERN_ACTION;
        $v1 = self::ROUTE_PATTERN_VERSION_ONE;
        $v2 = self::ROUTE_PATTERN_VERSION_TWO;
        $v3 = self::ROUTE_PATTERN_VERSION_THREE;
        $o = self::ROUTE_PATTERN_OBJECT_ID;
        return array(
            "/$v1/$c" => self::MATCHES_CONTROLLER,
            "/$v1/$c/" => self::MATCHES_CONTROLLER,
            "/$v2/$c" => self::MATCHES_CONTROLLER,
            "/$v2/$c/" => self::MATCHES_CONTROLLER,
            "/$v3/$c" => self::MATCHES_CONTROLLER,
            "/$v3/$c/" => self::MATCHES_CONTROLLER,
            "/$v1/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v1/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v2/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v2/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v3/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v3/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v1/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v1/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v2/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v2/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v3/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v3/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v1/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
        );
    }
1198959
protected function handle($handler) {
	$handler_type = $this->get_handler_type($handler);
	
	// unmatched requests
	if (empty($handler) || empty($handler_type)) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('no route found', response::STATUS_NOT_FOUND);
	}
	
	// default flow: matched requests
	$this->{'load_handler_as_'.$handler_type}($handler);
}
644654
public function routing()
    {
        // has dispatch.
        if ($action = $this->getDispatchAction()) {
            return new Rule\MatchRule(array('action' => $action));
        }

        // default rule.
        $path = '/';
        if ($this->_default && $this->_default->matching($path)) {
            return $this->_default;
        }
    }
595544
protected function matchCache()
    {
        // check if we can find a match in cache
        // check if a cache exists
        if ($this->cache instanceof Cache) {
            // check if we have any routes saved in cache
            if ($cachedRoutes = $this->cache->get('routeMiddlewareRoutes')) {
                // check if the requested uri can be found in the cache
                if (isset($cachedRoutes[$this->requestUri])) {

                    // check if endpoint class exists
                    if (!$this->endpointExists($cachedRoutes[$this->requestUri]['matchedEndpoint'])) {
                        throw new NotFound();
                    }

                    if (!$this->endpointMethodExists(
                        $cachedRoutes[$this->requestUri]['matchedEndpoint'],
                        $this->requestMethod
                    )) {
                        // route found but method can't be found
                        throw new MethodNotAllowed();
                    }

                    // match found, set info
                    $this->matchedRoute = $cachedRoutes[$this->requestUri]['matchedRoute'];
                    $this->matchedEndpoint = $cachedRoutes[$this->requestUri]['matchedEndpoint'];
                    $this->matchedMethod  = $this->requestMethod;
                    $this->params  = (isset($cachedRoutes[$this->requestUri]['params'])) ?
                        $cachedRoutes[$this->requestUri]['params'] : [];

                    // no need to look for more
                    return true;
                }
            }
        }

        return false;
    }
451253
public function match(Request $request)
    {
        $routes = $this->get($request->getMethod());

        // First, we will see if we can find a matching route for this current request
        // method. If we can, great, we can just return it so that it can be called
        // by the consumer. Otherwise we will check for routes with another verb.

        if (! is_null($route = $this->fastCheck($routes, $request))) {
            // A route was found in the fast way.
        } else {
            $route = $this->check($routes, $request);
        }

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

        // If no route was found, we will check if a matching route is specified on
        // another HTTP verb. If it is we will need to throw a MethodNotAllowed and
        // inform the user agent of which HTTP verb it should use for this route.

        $others = $this->checkForAlternateVerbs($request);

        if (! empty($others)) {
            return $this->getOtherMethodsRoute($request, $others);
        }

        throw new NotFoundHttpException;
    }
1082114
private function dispatch()
    {

        // Handle possible posted data
        $this->managePost();

        // Send 404 error when no app name is defined in router
        if (empty($this->router['target']['app'])) {
            return $this->send404('No appname to call.');
        }

        // We need this toll for some following string conversions
        $string = new CamelCase($this->router['target']['app']);

        // The apps classname is camelcased so the name from router match need to be converted.
        $app_name = $string->camelize();

        // Get app instance from app handler
        $app = $this->getAppInstance($app_name);

        // Send 404 error when there is no app instance
        if (empty($app)) {
            return $this->send404('app.object');
        }

        // Call app event: Run()
        $event_result = $this->callAppEvent($app, 'Run');

        // Redirect from event?
        if (!empty($event_result) && $event_result != $app_name) {
            $this->router->setParam('app', $event_result);
            $this->router->match();
            $this->dispatch();
            return;
        }

        // Load controller object
        $string->setString($this->router['target']['controller'] ?? 'Index');
        $controller_name = $string->camelize();

        $controller = $app->getController($controller_name);

        // Send 404 when controller could not be loaded
        if ($controller == false) {
            return $this->send404('Controller::' . $controller_name);
        }

        // Handle controller action
        $string->setString($this->router['target']['action'] ?? 'Index');
        $action = $string->camelize();

        if (!method_exists($controller, $action)) {
            return $this->send404('Action::' . $action);
        }

        // Prepare controller object
        $controller->setAction($action);
        $controller->setParams($this->router->getParams());
        $controller->setRoute($this->router->getCurrentRoute());

        if ($this->router->isAjax()) {

            // Controller needs to know the output format
            $this->router->setFormat('json');

            $this->http->header->contentType('application/json', 'utf-8');
            $this->http->header->noCache();

            // Result will be processed as ajax command list
            $controller->ajax();

            /* @var $ajax \Core\Ajax\Ajax */
            $ajax = $this->di->get('core.ajax');

            // Handle messages
            $messages = $this->di->get('core.message.default')->getAll();

            if (!empty($messages)) {

                /* @var $msg \Core\Message\Message */
                foreach ($messages as $msg) {

                    // Each message gets its own alert

                    /* @var $alert \Core\Html\Bootstrap\Alert\Alert */
                    $alert = $this->di->get('core.html.factory')->create('Bootstrap\Alert\Alert');
                    $alert->setContext($msg->getType());
                    $alert->setDismissable($msg->getDismissable());

                    // Fadeout message?
                    if ($this->config->get('Core', 'js.style.fadeout_time') > 0 && $msg->getFadeout()) {
                        $alert->html->addCss('fadeout');
                    }

                    // Has this message an id which we can use as id for the alerts html element?
                    if (!empty($msg->getId())) {
                        $alert->html->setId($msg->getId());
                    }

                    // At least append the message content
                    $alert->setContent($msg->getMessage());

                    $ajax->addCommand(new \Core\Ajax\Commands\Dom\DomCommand($msg->getTarget(), $msg->getDisplayFunction(), $alert->build()));
                }
            }

            // @TODO Process possible asset js files to load!
            $js_objects = $this->di->get('core.asset')
                ->getAssetHandler('js')
                ->getObjects();

            if (!empty($js_objects)) {
                foreach ($js_objects as $js) {
                    if ($js->getType() == 'file') {
                        $ajax->addCommand(new \Core\Ajax\Commands\Act\JQueryGetScriptCommand($js->getContent()));
                    }
                }
            }

            // Run ajax processor
            $result = $ajax->process();
        }
        else {

            $result = $controller->run();
            $this->router->setFormat($controller->getFormat());
        }

        return $result;
    }
393744
protected function findAvailableRoutes()
    {
        $routes = [];
        $rules = Director::config()->get('rules');

        foreach ($rules as $pattern => $controllerInfo) {
            $routeClass = (is_string($controllerInfo)) ? $controllerInfo : $controllerInfo['Controller'];

            try {
                $routeController = Injector::inst()->get($routeClass);
                if ($routeController instanceof Controller) {
                    $routes[] = $pattern;
                }
            } catch (InjectorNotFoundException $ex) {
            }

        }
        return $routes;
    }
320796
public function getUserFromRoute() {
    $route_match = $this->currentRouteMatch;

    // See if the route has a user parameter and try to retrieve it.
    if (($account = $route_match->getParameter('user'))) {
      if ($account instanceof UserInterface) {
        return $account;
      }
      elseif (is_numeric($account)) {
        $account = $this->userStorage->load($account);

        if ($account instanceof UserInterface) {
          return $account;
        }
      }
    }
  }
606532
public function getCurrentRouteMatch() {
    if (empty($this->currentRouteMatch)) {
      $this->currentRouteMatch = \Drupal::service('current_route_match');
    }
    return $this->currentRouteMatch;
  }
550614
public function match($request, $partial = null)
    {
        $path        = trim($request->getPathInfo(), self::URI_DELIMITER);
        $subPath     = $path;
        $values      = array();
        $numRoutes   = count($this->_routes);
        $matchedPath = null;

        foreach ($this->_routes as $key => $route) {
            if ($key > 0
                && $matchedPath !== null
                && $subPath !== ''
                && $subPath !== false
            ) {
                $separator = substr($subPath, 0, strlen($this->_separators[$key]));

                if ($separator !== $this->_separators[$key]) {
                    return false;
                }

                $subPath = substr($subPath, strlen($separator));
            }

            // TODO: Should be an interface method. Hack for 1.0 BC
            if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
                $match = $subPath;
            } else {
                $request->setPathInfo($subPath);
                $match = $request;
            }

            $res = $route->match($match, true, ($key == $numRoutes - 1));
            if ($res === false) {
//BEGIN FIX
                $request->setPathInfo($path);
//END FIX
                return false;
            }

            $matchedPath = $route->getMatchedPath();

            if ($matchedPath !== null) {
                $subPath     = substr($subPath, strlen($matchedPath));
                $separator   = substr($subPath, 0, strlen($this->_separators[$key]));
            }

            $values = $res + $values;
        }

        $request->setPathInfo($path);

        if ($subPath !== '' && $subPath !== false) {
            return false;
        }

        return $values;
    }
830266
function matchRoutes(routes, path, query) {
  query = query === undefined ? {} : isString(query) ? qs.parse(query) : query;
  return matchRoutesImpl(routes, path, query);
}