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