/** * 添加路由对象 * * @param string|array $methods 支持的 HTTP 方法 * @param string $pattern * @param handler $handler * @return \Lime\Route */ public function map($methods, $pattern, $handler) { if (!is_string($pattern)) { throw new \Exception('Route pattern must be a string'); } if (is_string($methods)) { $methods = [$methods]; } // HTTP 方法统一为大写 $methods = array_map('strtoupper', $methods); // 处理分组, 相当于添加 pattern 的前缀 $groupPattern = $this->processGroups(); $pattern = '/' . ltrim($pattern, '/'); /* 新建一个路由表象 */ $route = new Route($methods, $groupPattern . $pattern, $handler); if ($this->inGroup) { $this->routeIdGroups[$this->groupLevel][] = $route->getRouteId(); } return $this->routes[$route->getRouteId()] = $route; }