public static function compile($routes) { $compiled = []; foreach ($routes as $path => $params) { if (count($params) < 2) { ranch_utils::halt("Route params count should be >= 3"); } $path = cowboy_utils::addTrailingSlash($path); $route['handler'] = $params[0]; $route['opts'] = $params[1]; $route['path'] = $path; $pattern = preg_replace("/(\\:[^\\/]+)\\//", "([^\\/]+)\\/", str_replace('/', '\\/', $path)); $route['pattern'] = '/^' . $pattern . '$/'; preg_match_all("/(\\:[^\\/]+)/", "{$path}", $m); $route['bindings'] = array_map(function ($x) { return ltrim($x, ":"); }, array_filter($m[0])); $route['match'] = (bool) $route['bindings']; self::$compiled[$path] = $route; } }