get("$prefix/doc", "${ns}LuDocBusiness", "index"); $route->get("$prefix/doc/{businessHyphen}", "${ns}LuDocBusiness", "business"); $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[] */ foreach ($businesses_ as $businesses) { $businessHyphen = self::getBusinessHyphen($businesses[0]->getBusinessClass()); $businessName = self::getBusinessName($businesses[0]->getBusinessClass()); echo '

' . $businessName . "

"; foreach ($businesses as $business) { echo '' . $business->getMethod() . " " . $business->getUrl() . "
"; } } exit; } /** * Print the help page for the selected business. * The business must have the full namespace, hyphen separated * eg: App-Http-Business-MyBusinessClass * @param $businessHyphen string The business to print help */ public static function business($businessHyphen) { $businesses_ = self::getBusinesses(); /** * @var $businesses LuRouteDbo[] */ $businesses = $businesses_[self::getBusinessFromHyphen($businessHyphen)]; $businessName = self::getBusinessName($businesses[0]->getBusinessClass()); echo '

' . $businessName . "

"; foreach ($businesses as $business) { echo '' . $business->getMethod() . " " . $business->getUrl() . "
"; } 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; } }