/** * 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; }
/** * @param string * @return false when file is not found * true when class file is found and loaded */ public function loadClass($class) { if (class_exists($class, false) || interface_exists($class, false)) { return true; } $path = NamespaceParser::parse($class); if (false === $path) { return false; } foreach ($this->pathList as $root) { $file = $root . DIRECTORY_SEPARATOR . $path; if (is_file($file)) { require $file; return true; } } if ($this->isIncludePathEnabled() && ($file = stream_resolve_include_path($path))) { require $file; return true; } return false; }
/** * @dataProvider provideParseStringsWithExtensions * @return null */ public function testParseWithExtension($input, $expected) { $result = $this->parser->parse($input); $this->assertEquals($expected, $result); }