/** * Alternative implementation to the generation of htaccess rules. Try to resolve the given path by our patterns. * * @internal * * @param $path * * @return bool */ public static function resolve($path) { preg_match_all('#([a-z]+):([0-9a-z]+)#iU', $path, $optionals, PREG_SET_ORDER); foreach ($optionals as $optional) { $path = str_replace($optional[0], '', $path); $_GET[$optional[1]] = $optional[2]; } $path = trim($path, '/'); $routes = self::getRoutes(); $unfolded = self::expandAndSort($routes); foreach ($unfolded as $route) { $route_pattern = $route['pattern']; $route_pattern = '%^' . preg_replace('#<[^>/]+?>#', '(.*)', $route_pattern) . '$%siU'; if (preg_match($route_pattern, $path, $matches)) { preg_match('%^' . preg_replace('#<[^>/]+?>#', '<(.*)>', $route['pattern']) . '$%siU', $route['pattern'], $params); foreach ($route['static'] as $key => $value) { $_GET[$key] = $value; } for ($i = 1; $i < count($params); $i++) { $_GET[$params[$i]] = $matches[$i]; } return true; } } Cache::delete('unfolded_routes'); Logger::getInstance()->error('Could not find route with pattern "' . $path . '"'); return false; }