選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LuDocBusiness.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 10/22/15
  6. * Time: 8:24 PM
  7. */
  8. namespace Luticate\Doc\Business;
  9. use Luticate\Utils\LuRoute;
  10. use Luticate\Utils\LuRouteDbo;
  11. use ReflectionMethod;
  12. class LuDocBusiness
  13. {
  14. private static function getBusinesses()
  15. {
  16. $route = LuRoute::getInstance();
  17. $businesses = [];
  18. foreach ($route->getRoutes() as $r) {
  19. if (!isset($businesses[$r->getBusinessClass()])) {
  20. $businesses[$r->getBusinessClass()] = [];
  21. }
  22. $businesses[$r->getBusinessClass()][] = $r;
  23. }
  24. return $businesses;
  25. }
  26. /**
  27. * @param $business string
  28. * @return string
  29. */
  30. private static function getBusinessName($business)
  31. {
  32. $tab = explode("\\", $business);
  33. return array_pop($tab);
  34. }
  35. /**
  36. * @param $business string
  37. * @return string
  38. */
  39. private static function getBusinessHyphen($business)
  40. {
  41. return str_replace("\\", "-", $business);
  42. }
  43. /**
  44. * @param $business string
  45. * @return string
  46. */
  47. private static function getBusinessFromHyphen($business)
  48. {
  49. return str_replace("-", "\\", $business);
  50. }
  51. /**
  52. * Print the help page
  53. */
  54. public static function index()
  55. {
  56. $businesses_ = self::getBusinesses();
  57. /**
  58. * @var $businesses LuRouteDbo[]
  59. */
  60. foreach ($businesses_ as $businesses) {
  61. $businessHyphen = self::getBusinessHyphen($businesses[0]->getBusinessClass());
  62. $businessName = self::getBusinessName($businesses[0]->getBusinessClass());
  63. echo '<a href="doc/' . $businessHyphen . '"><h1>' . $businessName . "</h1></a>";
  64. foreach ($businesses as $business) {
  65. echo '<a href="doc/' . $businessHyphen . '/' . $business->getBusinessMethod()
  66. . '">' . $business->getMethod() . " " . $business->getUrl() . "</a><br />";
  67. }
  68. }
  69. exit;
  70. }
  71. /**
  72. * Print the help page for the selected business.
  73. * The business must have the full namespace, hyphen separated
  74. * eg: App-Http-Business-MyBusinessClass
  75. * @param $businessHyphen string The business to print help
  76. */
  77. public static function business($businessHyphen)
  78. {
  79. $businesses_ = self::getBusinesses();
  80. /**
  81. * @var $businesses LuRouteDbo[]
  82. */
  83. $businesses = $businesses_[self::getBusinessFromHyphen($businessHyphen)];
  84. $businessName = self::getBusinessName($businesses[0]->getBusinessClass());
  85. echo '<a href="' . $businessHyphen . '"><h1>' . $businessName . "</h1></a>";
  86. foreach ($businesses as $business) {
  87. echo '<a href="' . $businessHyphen . '/' . $business->getBusinessMethod()
  88. . '">' . $business->getMethod() . " " . $business->getUrl() . "</a><br />";
  89. }
  90. exit;
  91. }
  92. /**
  93. * Print the help page for the selected business method.
  94. * The business must have the full namespace, hyphen separated
  95. * eg: App-Http-Business-MyBusinessClass
  96. * @param $businessHyphen string The business to print help
  97. * @param $method string The method to print help
  98. */
  99. public static function method($businessHyphen, $method)
  100. {
  101. $businesses_ = self::getBusinesses();
  102. $businessName = self::getBusinessFromHyphen($businessHyphen);
  103. /**
  104. * @var $businesses LuRouteDbo[]
  105. */
  106. $businesses = $businesses_[$businessName];
  107. $business = null;
  108. foreach ($businesses as $b) {
  109. if ($b->getBusinessMethod() == $method) {
  110. $business = $b;
  111. }
  112. }
  113. echo "<h1>" . $business->getMethod() . " " . $business->getUrl() . "</h1>";
  114. $reflection = new ReflectionMethod($businessName, $method);
  115. echo str_replace("\n", "<br />", $reflection->getDocComment());
  116. exit;
  117. }
  118. }