/** * Build a new route and add it to the Map. * * @param array $methods Array containing http methods. * The supported methods are defined by Request::METHOD_* constants * @param string $routeStr A string that may contain parameters * that will be passed to the controller. * For example: * - /home * - /product/{productId} * - /tag/{slug} * @param array $info An array containing the following indexes: * - controller: Name of a controller class * - action: Method of the defined controller (Default: index) * - alias: Short name of the route, for easy referencing */ public static function create(array $methods, string $routeStr, array $info) { $middlewareList = isset($info['middleware']) ? (array) $info['middleware'] : []; array_walk_recursive(self::$middlewareGroupStack, function ($middleware) use(&$middlewareList) { $middlewareList[] = $middleware; }); $route = new self(); $route->setMethods($methods); $route->setAction(isset($info['action']) ? $info['action'] : 'index'); $route->setAlias(isset($info['alias']) ? $info['alias'] : ''); $route->setMiddlewareList($middlewareList); $route->setControllerName($info['controller']); $route->setMethods($methods); $route->setRouteStr($routeStr); Map::addRoute($route); }