123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 10/22/15
- * Time: 8:24 PM
- */
-
- namespace Luticate\Doc\Business;
-
- use Luticate\Utils\LuRoute;
- use Luticate\Utils\LuRouteDbo;
- use ReflectionMethod;
-
- class LuDocBusiness
- {
- /**
- * @param $prefix string
- */
- public static function setupRoutes($prefix = "/luticate")
- {
- $ns = 'Luticate\Doc\Business\\';
-
- $route = LuRoute::getInstance();
- $route->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 '<a href="doc/' . $businessHyphen . '"><h1>' . $businessName . "</h1></a>";
-
- foreach ($businesses as $business) {
- echo '<a href="doc/' . $businessHyphen . '/' . $business->getBusinessMethod()
- . '">' . $business->getMethod() . " " . $business->getUrl() . "</a><br />";
- }
- }
- 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 '<a href="' . $businessHyphen . '"><h1>' . $businessName . "</h1></a>";
-
- foreach ($businesses as $business) {
- echo '<a href="' . $businessHyphen . '/' . $business->getBusinessMethod()
- . '">' . $business->getMethod() . " " . $business->getUrl() . "</a><br />";
- }
- 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 "<h1>" . $business->getMethod() . " " . $business->getUrl() . "</h1>";
-
- $reflection = new ReflectionMethod($businessName, $method);
- echo str_replace("\n", "<br />", $reflection->getDocComment());
- exit;
- }
- }
|