get("$prefix/doc", "${ns}LuDocBusiness", "index"); $route->get("$prefix/doc/{businessHyphen}/{method}", "${ns}LuDocBusiness", "method"); } private static function getBusinesses() { $route = LuRoute::getInstance(); $businesses = []; foreach ($route->getRoutes() as $r) { if (!isset($businesses[$r->getBusinessClass()])) { $businesses[$r->getBusinessClass()] = []; } $businesses[$r->getBusinessClass()][] = $r; } return $businesses; } /** * @param $business string * @return string */ private static function getBusinessName($business) { $tab = explode("\\", $business); return array_pop($tab); } /** * @param $business string * @return string */ private static function getBusinessHyphen($business) { return str_replace("\\", "-", $business); } /** * @param $business string * @return string */ private static function getBusinessFromHyphen($business) { return str_replace("-", "\\", $business); } /** * Print the help page */ public static function index() { $businesses_ = self::getBusinesses(); /** * @var $businesses LuRouteDbo[] */ $businesses_tiwg = []; foreach ($businesses_ as $businesses) { $businessHyphen = self::getBusinessHyphen($businesses[0]->getBusinessClass()); $businessName = self::getBusinessName($businesses[0]->getBusinessClass()); $business_tiwg = []; $business_tiwg["name"] = $businessName; $business_tiwg["name_hyphen"] = $businessHyphen; $business_tiwg["routes"] = []; foreach ($businesses as $business) { $reflection = new ReflectionMethod($business->getBusinessClass(), $business->getBusinessMethod()); $description = $reflection->getDocComment(); if ($description === false) { $description = "No description available"; } $business_tiwg["routes"][] = [ "method" => $business->getMethod(), "url" => $business->getUrl(), "businessMethod" => $business->getBusinessMethod(), "description" => $description ]; } $businesses_tiwg[] = $business_tiwg; } $loader = new Twig_Loader_Filesystem(__DIR__ . "/../Templates"); $twig = new Twig_Environment($loader, array()); $template = $twig->loadTemplate("index.html.twig"); $content = $template->render(array("businesses" => $businesses_tiwg)); echo $content; exit; } /** * Print the help page for the selected business method. * The business must have the full namespace, hyphen separated * eg: App-Http-Business-MyBusinessClass * @param $businessHyphen string The business to print help * @param $method string The method to print help */ public static function method($businessHyphen, $method) { $businesses_ = self::getBusinesses(); $businessName = self::getBusinessFromHyphen($businessHyphen); /** * @var $businesses LuRouteDbo[] */ $businesses = $businesses_[$businessName]; $business = null; foreach ($businesses as $b) { if ($b->getBusinessMethod() == $method) { $business = $b; } } echo "

" . $business->getMethod() . " " . $business->getUrl() . "

"; $reflection = new ReflectionMethod($businessName, $method); echo str_replace("\n", "
", $reflection->getDocComment()); exit; } }