|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Documentation\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class DocsGeneratorTrait |
|
9
|
|
|
* |
|
10
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
trait DocsGeneratorTrait |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @return mixed |
|
17
|
|
|
*/ |
|
18
|
|
|
private function getFullApiUrl($type) |
|
19
|
|
|
{ |
|
20
|
|
|
return '> ' . $this->getApiDomain() . '/' . $this->getUrl($type); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return mixed |
|
25
|
|
|
*/ |
|
26
|
|
|
private function getApiDomain() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->config->get('api.domain'); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
private function getHtmlPath() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->config->get("{$this->getConfigFile()}.html_files"); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Where to generate the new documentation. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
private function getDocumentationPath($type) |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getHtmlPath() . $this->getUrl($type); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
private function getJsonFilePath($type) |
|
53
|
|
|
{ |
|
54
|
|
|
return "app/Containers/Documentation/ApiDocJs/{$type}"; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
private function getConfigFile() |
|
61
|
|
|
{ |
|
62
|
|
|
return 'apidoc'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return mixed |
|
67
|
|
|
*/ |
|
68
|
|
|
private function getTypeConfig() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->config->get($this->getConfigFile() . '.types'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
private function getExecutable() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->config->get($this->getConfigFile() . '.executable'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param $type |
|
83
|
|
|
* |
|
84
|
|
|
* @return mixed |
|
85
|
|
|
*/ |
|
86
|
|
|
private function getUrl($type) |
|
87
|
|
|
{ |
|
88
|
|
|
$configs = $this->getTypeConfig(); |
|
89
|
|
|
|
|
90
|
|
|
return $configs[$type]['url']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param $type |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
private function getEndpointFiles($type) |
|
99
|
|
|
{ |
|
100
|
|
|
$configs = $this->getTypeConfig(); |
|
101
|
|
|
|
|
102
|
|
|
// what files types needs to be included |
|
103
|
|
|
$routeFilesCommand = ''; |
|
104
|
|
|
$routes = $configs[$type]['routes']; |
|
105
|
|
|
|
|
106
|
|
|
foreach ($routes as $route) { |
|
107
|
|
|
$routeFilesCommand .= '-f ' . $route . '.php '; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $routeFilesCommand; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param $templateKey |
|
116
|
|
|
* @param $value |
|
117
|
|
|
*/ |
|
118
|
|
|
private function replace($templateKey, $value) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->headerMarkdownContent = str_replace($templateKey, $value, $this->headerMarkdownContent); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param $minutes |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
|
|
private function minutesToTimeDisplay($minutes) |
|
129
|
|
|
{ |
|
130
|
|
|
$seconds = $minutes * 60; |
|
131
|
|
|
|
|
132
|
|
|
$dtF = new DateTime('@0'); |
|
133
|
|
|
$dtT = new DateTime("@$seconds"); |
|
134
|
|
|
|
|
135
|
|
|
return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: