/** * Generate a list of route details from the route details file. The route * builder implements inheritance among route detail specifications. Since * all route details from the file share the same namespace the are all * added to the route map. This allows alias routes to be found by the * framework. * * @param string $key * @return MvcRouteHandlerInterface */ public static function buildRouteDetails($key) { $reader = self::$reader; if (!$reader) { $finder = new FileFinder(AF_LIB_PATH, false); $reader = new FileReader($finder); self::$reader = $reader; } $namespace = self::getNamespace($key); /* * 404 is used as the error code because the fault handler will * catch this and use a 404 http reponse for any thing that is not * commandline and exit with 404 for commandline */ if (false === $namespace) { $err = "could not resolve namespace for route key -({$key})"; throw new RunTimeException($err, 404); } /* * grap the route detail file form disk and use the route * build to create a list of routes from its specifications */ $path = NamespaceParser::parseNs($namespace); $file = self::getRouteDetailFilename(); $path = "{$path}/{$file}"; $data = $reader->import($path, true); $routes = RouteBuilder::buildRoutes($data); if (empty($routes)) { return false; } /* * Make alias routes visible to the framework */ $routeKeys = array_keys($routes); foreach ($routeKeys as $routeKey) { if (!self::isRoute($routeKey)) { self::addRoute($routeKey, $namespace); } } return $routes; }
/** * @dataProvider provideNamespaces * @return null */ public function testParseNs($input, $expected) { $result = $this->parser->parseNs($input); $this->assertEquals($expected, $result); }