1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace KMLaravel\ApiGenerator\Helpers; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\File; |
8
|
|
|
|
9
|
|
|
class KMFile |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param $fileName |
14
|
|
|
* @return string |
15
|
|
|
*/ |
16
|
|
|
public static function getFilesFromStubs($fileName) |
17
|
|
|
{ |
18
|
|
|
return __DIR__ . "/../Stubs/$fileName.stub"; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param $fileName |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public static function getFilesFromStubsAsStream($fileName) |
26
|
|
|
{ |
27
|
|
|
return File::get(__DIR__ . "/../Stubs/$fileName.stub"); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param $fileName |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public static function getRequestFile($fileName) |
35
|
|
|
{ |
36
|
|
|
return app_path("Http/Requests/$fileName"); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param $fileName |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public static function getResourceFile($fileName) |
44
|
|
|
{ |
45
|
|
|
return app_path("Http/Resources/".static::correctPath($fileName)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $fileName |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public static function getModelFile($fileName) |
53
|
|
|
{ |
54
|
|
|
return app_path(static::correctPath($fileName)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $fileName |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public static function getRequestFileAsStream($fileName) |
62
|
|
|
{ |
63
|
|
|
return File::get(app_path("Http/Requests/".static::correctPath($fileName))); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $fileName |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public static function getModelFileAsStream($fileName) |
71
|
|
|
{ |
72
|
|
|
return File::get(app_path(static::correctPath($fileName))); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param $type |
77
|
|
|
* @param $className |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public static function getClassNameSpace($type, $className) |
81
|
|
|
{ |
82
|
|
|
if ($type == "model") { |
83
|
|
|
return "App\\$className"; |
84
|
|
|
} |
85
|
|
|
return "App\\Http\\$type\\$className"; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public static function getCredentialJsonFilePath() |
92
|
|
|
{ |
93
|
|
|
if (File::exists(resource_path("Views/ApisGenerator/credential.json"))) { |
94
|
|
|
return resource_path("Views/ApisGenerator/credential.json"); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return mixed |
100
|
|
|
*/ |
101
|
|
|
public static function getCredentialJsonFileAsJson() |
102
|
|
|
{ |
103
|
|
|
if (File::exists(resource_path("Views/ApisGenerator/credential.json"))) { |
104
|
|
|
return json_decode(File::get(self::getCredentialJsonFilePath())); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param $newData |
110
|
|
|
*/ |
111
|
|
|
public static function setDataToCredentialJsonFile($newData) |
112
|
|
|
{ |
113
|
|
|
$data = self::getCredentialJsonFileAsJson(); |
114
|
|
|
array_unshift($data, $newData); |
|
|
|
|
115
|
|
|
File::put(self::getCredentialJsonFilePath(), json_encode($data)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public static function baseControllerExists() |
122
|
|
|
{ |
123
|
|
|
return File::exists(static::baseControllerPath()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public static function baseControllerPath() |
130
|
|
|
{ |
131
|
|
|
return app_path("Http/Controllers/BaseController.php"); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string $path |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
private static function correctPath($path){ |
139
|
|
|
return str_replace('\\' , ' /' , $path); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|