public function add($httpMethod, $uri, $handler, $middlewares = []) { $route = new Route($httpMethod, $uri, $handler, $this->strategy); $route->setMiddlewares($middlewares); $route->setGroup($this); $this->routes[] = $route; return $route; }
/** * @param $httpMethod * @param $routes * @param $options * @param $handler * @return Route */ public function addRoute($httpMethod, $routes, $options, $handler) { if (!is_array($httpMethod)) { $httpMethod = array($httpMethod); } $this->last_group = []; $this->setPrefixs($this->getPrefix($options)); $this->setHosts($options); $options = array_merge($options, ['base_uri' => $this->base_uri]); $group_routes = !is_array($routes) ? [$routes] : $routes; $is_group = count($group_routes) > 1; foreach ($group_routes as $route) { $_route = new Route($route, $options, $handler); if ($is_group) { $_route->setGroup(); } $this->last_group[] = $_route; foreach ($httpMethod as $method) { $this->routes[$method][] = $_route; } } return $this; }