Match routes against incoming URI
@return mixed
347604
function run() {
		if ($this->blacklisted($this->hive['IP']))
			// Spammer detected
			$this->error(403);
		if (!$this->hive['ROUTES'])
			// No routes defined
			user_error(self::E_Routes,E_USER_ERROR);
		// Match specific routes first
		$paths=array();
		foreach ($keys=array_keys($this->hive['ROUTES']) as $key)
			$paths[]=str_replace('@','*@',$key);
		$vals=array_values($this->hive['ROUTES']);
		array_multisort($paths,SORT_DESC,$keys,$vals);
		$this->hive['ROUTES']=array_combine($keys,$vals);
		// Convert to BASE-relative URL
		$req=$this->rel($this->hive['URI']);
		if ($cors=(isset($this->hive['HEADERS']['Origin']) &&
			$this->hive['CORS']['origin'])) {
			$cors=$this->hive['CORS'];
			header('Access-Control-Allow-Origin: '.$cors['origin']);
			header('Access-Control-Allow-Credentials: '.
				($cors['credentials']?'true':'false'));
		}
		$allowed=array();
		foreach ($this->hive['ROUTES'] as $pattern=>$routes) {
			if (!$args=$this->mask($pattern,$req))
				continue;
			ksort($args);
			$route=NULL;
			if (isset(
				$routes[$ptr=$this->hive['AJAX']+1][$this->hive['VERB']]))
				$route=$routes[$ptr];
			elseif (isset($routes[self::REQ_SYNC|self::REQ_AJAX]))
				$route=$routes[self::REQ_SYNC|self::REQ_AJAX];
			if (!$route)
				continue;
			if ($this->hive['VERB']!='OPTIONS' &&
				isset($route[$this->hive['VERB']])) {
				$parts=parse_url($req);
				if ($this->hive['VERB']=='GET' &&
					preg_match('/.+\/$/',$parts['path']))
					$this->reroute(substr($parts['path'],0,-1).
						(isset($parts['query'])?('?'.$parts['query']):''));
				list($handler,$ttl,$kbps,$alias)=$route[$this->hive['VERB']];
				if (is_bool(strpos($pattern,'/*')))
					foreach (array_keys($args) as $key)
						if (is_numeric($key) && $key)
							unset($args[$key]);
				// Capture values of route pattern tokens
				$this->hive['PARAMS']=$args=array_map('urldecode',$args);
				// Save matching route
				$this->hive['ALIAS']=$alias;
				$this->hive['PATTERN']=$pattern;
				if ($cors && $cors['expose'])
					header('Access-Control-Expose-Headers: '.(is_array($cors['expose'])?
						implode(',',$cors['expose']):$cors['expose']));
				if (is_string($handler)) {
					// Replace route pattern tokens in handler if any
					$handler=preg_replace_callback('/@(\w+\b)/',
						function($id) use($args) {
							return isset($args[$id[1]])?$args[$id[1]]:$id[0];
						},
						$handler
					);
					if (preg_match('/(.+)\h*(?:->|::)/',$handler,$match) &&
						!class_exists($match[1]))
						$this->error(404);
				}
				// Process request
				$result=NULL;
				$body='';
				$now=microtime(TRUE);
				if (preg_match('/GET|HEAD/',$this->hive['VERB']) && $ttl) {
					// Only GET and HEAD requests are cacheable
					$headers=$this->hive['HEADERS'];
					$cache=Cache::instance();
					$cached=$cache->exists(
						$hash=$this->hash($this->hive['VERB'].' '.
							$this->hive['URI']).'.url',$data);
					if ($cached && $cached[0]+$ttl>$now) {
						if (isset($headers['If-Modified-Since']) &&
							strtotime($headers['If-Modified-Since'])+
								$ttl>$now) {
							$this->status(304);
							die;
						}
						// Retrieve from cache backend
						list($headers,$body,$result)=$data;
						if (PHP_SAPI!='cli')
							array_walk($headers,'header');
						$this->expire($cached[0]+$ttl-$now);
					}
					else
						// Expire HTTP client-cached page
						$this->expire($ttl);
				}
				else
					$this->expire(0);
				if (!strlen($body)) {
					if (!$this->hive['RAW'] && !$this->hive['BODY'])
						$this->hive['BODY']=file_get_contents('php://input');
					ob_start();
					// Call route handler
					$result=$this->call($handler,array($this, $args),
						'beforeroute,afterroute');
					$body=ob_get_clean();
					// Template Parsing
					if ($this->hive['TEMPLATE']) {
						$this->hive['RESPONSE'] = $body;
						$body = $this->send($this->hive['TEMPLATE'], true);
					}
					if (isset($cache) && !error_get_last()) {
						// Save to cache backend
						$cache->set($hash,array(
							// Remove cookies
							preg_grep('/Set-Cookie\:/',headers_list(),
								PREG_GREP_INVERT),$body,$result),$ttl);
					}
				}
				$this->hive['RESPONSE']=$body;
				if (!$this->hive['QUIET']) {
					if ($kbps) {
						$ctr=0;
						foreach (str_split($body,1024) as $part) {
							// Throttle output
							$ctr++;
							if ($ctr/$kbps>($elapsed=microtime(TRUE)-$now) &&
								!connection_aborted())
								usleep(1e6*($ctr/$kbps-$elapsed));
							echo $part;
						}
					}
					else
						echo $body;
				}
				return $result;
			}
			$allowed=array_merge($allowed,array_keys($route));
		}
		if (!$allowed)
			// URL doesn't match any route
			$this->error(404);
		elseif (PHP_SAPI!='cli') {
			// Unhandled HTTP method
			header('Allow: '.implode(',',array_unique($allowed)));
			if ($cors) {
				header('Access-Control-Allow-Methods: OPTIONS,'.implode(',',$allowed));
				if ($cors['headers'])
					header('Access-Control-Allow-Headers: '.(is_array($cors['headers'])?
						implode(',',$cors['headers']):$cors['headers']));
				if ($cors['ttl']>0)
					header('Access-Control-Max-Age: '.$cors['ttl']);
			}
			if ($this->hive['VERB']!='OPTIONS')
				$this->error(405);
		}
		return FALSE;
	}
1082104
protected function getUri(){
        if (method_exists($this->route, 'getPath')){
            // Laravel <5.4
            return $this->route->getPath();
        }

        // Laravel 5.4+
        return $this->route->uri();
    }
803763
public function routing()
    {
        // has dispatch.
        $route = null;
        if ($action = $this->getDispatchAction()) {
            $route = new Rule\MatchRule(array('action' => $action));
        }

        // root rule.
        $path = $this->request->getPath();
        if (! $route && $this->_root && $this->_root->match($path)) {
            $route = $this->_root;
        }

        // match rule.
        if (! $route) {
            foreach ($this->_rules as $rule) {
                if ($rule->match($path)) {
                    $route = $rule;
                    break;
                }
            }
        }

        // default rule.
        if (! $route && $this->_default && $this->_default->match($path)) {
            $route = $this->_default;
        }

        // not found
        if (! $route || ! $this->isActionExists($route)) {
            $route = new Rule\NotFoundRule();
        }
        return $route;
    }
461169
public function matchRequest(Request $request)
    {
        try {
            $parameters = parent::matchRequest($request);
            $this->matchedRouteRequest = $request;
            return $parameters;
        } catch (\Exception $e) {
            throw $e;
        }


    }
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;
    }
387195
public function uris()
    {
        $uri = (string) $this->uri;

        $exists = isset($this->data['permalink']);

        $exists && $uri = $this->data['permalink'];

        $items = explode('/', (string) $uri);

        $items = array_filter((array) $items);

        return (array) array_values($items);
    }
799728
private function match($request)
    {
        $route = $this->router->match(
            $request->getUri()->getPath(),
            $request->getMethod()
        );
        if (!$route) {
            // not matched. dispatch the next middleware.
            return $this->next ? $this->next->__invoke($request) : null;
        }
        return $this->dispatch($request, $route);
    }
1079104
protected function getRoutes()
    {
        $c = self::ROUTE_PATTERN_CONTROLLER;
        $a = self::ROUTE_PATTERN_ACTION;
        $p = self::ROUTE_PATTERN_PARAMS;
        return array(
            "/" => self::MATCHES_NOTHING,
            "/$c" => self::MATCHES_CONTROLLER,
            "/$c/" => self::MATCHES_CONTROLLER,
            "/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$c/$a/$p" => self::MATCHES_CONTROLLER_ACTION_AND_PARAMS
        );
    }
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;
    }
1337626
public function match($pathinfo)
    {
        $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext());
        $result = $urlMatcher->match($pathinfo);

        return $result;
    }
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;
    }
606532
public function getCurrentRouteMatch() {
    if (empty($this->currentRouteMatch)) {
      $this->currentRouteMatch = \Drupal::service('current_route_match');
    }
    return $this->currentRouteMatch;
  }
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);
    }
474518
protected function match($method, $uri)
    {
        $result = null;

        foreach ((array) $this->router->routes() as $route)
        {
            $matched = preg_match($route->regex(), $uri, $matches);

            if ($matched && $route->method() === $method)
            {
                return array($matches, $route);
            }
        }

        return $result;
    }
708482
private static function route($uri) {
		$result = $uri;
		$routes = \Application::get('routes');
		if (empty($routes)) $routes = [];
		$extra_routes = \Object\ACL\Resources::getStatic('routes');
		if (!empty($extra_routes)) {
			$routes = array_merge($routes, $extra_routes);
		}
		if (!empty($routes)) {
			foreach ($routes as $v) {
				$regex = '#^' . $v['regex'] . '#i';
				if (preg_match($regex, $result, $values)) {
					$result = str_replace($v['regex'], $v['new'], $result);
				}
			}
		}
		return $result;
	}
1222044
public function match(Request $request)
	{
		foreach ($this->routes->filterByMethod($request->getMethod()) as $route)
		{
			if ($route->isMatch($request->getPathInfo()))
			{
				return $route;
			}
		}

		return null;
	}
32644
public function getInitialMatcher()
    {
        if (null !== $this->initialMatcher) {
            return $this->initialMatcher;
        }

        $route = sprintf('%s/{_modular_path}', $this->routePrefix['path']);

        $collection = new RouteCollection;
        $collection->add('modular', new Route(
            $route,
            $this->routePrefix['defaults'],
            array_merge(
                $this->routePrefix['requirements'],
                ['_modular_path' => '.+']
            )
        ));

        return $this->initialMatcher = new UrlMatcher($collection, $this->context);
    }