/** * @param array $config * @return Router * @throws \Exception */ public static function parseConfig(array $config) { $collection = new RouteCollection(); foreach ($config as $name => $routeConfig) { if (empty($name)) { throw new \Exception('Check your config file! route name is missing'); } //优先考虑routeName if (empty($routeConfig['parameters']['routeName'])) { $routeConfig['parameters']['routeName'] = $name; } $collection->attachRoute(new Route($routeConfig['pattern'], $routeConfig['parameters'])); } return new Router($collection); }