@@ -7,255 +7,255 @@ |
||
7 | 7 | |
8 | 8 | class GenerateDoc extends Command |
9 | 9 | { |
10 | - /** |
|
11 | - * The name and signature of the console command. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $signature = 'doc:generate'; |
|
10 | + /** |
|
11 | + * The name and signature of the console command. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $signature = 'doc:generate'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * The console command description. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $description = 'Generate api documentation'; |
|
17 | + /** |
|
18 | + * The console command description. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $description = 'Generate api documentation'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Init new object. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct(); |
|
32 | - } |
|
24 | + /** |
|
25 | + * Init new object. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Execute the console command. |
|
36 | - * |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function handle() |
|
40 | - { |
|
41 | - $docData = []; |
|
42 | - $docData['models'] = []; |
|
43 | - $routes = $this->getRoutes(); |
|
44 | - foreach ($routes as $route) { |
|
45 | - if ($route) { |
|
46 | - $actoinArray = explode('@', $route['action']); |
|
47 | - if (Arr::get($actoinArray, 1, false)) { |
|
48 | - $controller = $actoinArray[0]; |
|
49 | - $method = $actoinArray[1]; |
|
50 | - $route['name'] = $method !== 'index' ? $method : 'list'; |
|
34 | + /** |
|
35 | + * Execute the console command. |
|
36 | + * |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function handle() |
|
40 | + { |
|
41 | + $docData = []; |
|
42 | + $docData['models'] = []; |
|
43 | + $routes = $this->getRoutes(); |
|
44 | + foreach ($routes as $route) { |
|
45 | + if ($route) { |
|
46 | + $actoinArray = explode('@', $route['action']); |
|
47 | + if (Arr::get($actoinArray, 1, false)) { |
|
48 | + $controller = $actoinArray[0]; |
|
49 | + $method = $actoinArray[1]; |
|
50 | + $route['name'] = $method !== 'index' ? $method : 'list'; |
|
51 | 51 | |
52 | - $reflectionClass = new \ReflectionClass($controller); |
|
53 | - $reflectionMethod = $reflectionClass->getMethod($method); |
|
54 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
55 | - $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
56 | - $validationRules = Arr::get($classProperties, 'validationRules', false); |
|
52 | + $reflectionClass = new \ReflectionClass($controller); |
|
53 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
54 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
55 | + $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
56 | + $validationRules = Arr::get($classProperties, 'validationRules', false); |
|
57 | 57 | |
58 | - dd($classProperties); |
|
59 | - $this->processDocBlock($route, $reflectionMethod); |
|
60 | - $this->getHeaders($route, $method, $skipLoginCheck); |
|
61 | - $this->getPostData($route, $reflectionMethod, $validationRules); |
|
58 | + dd($classProperties); |
|
59 | + $this->processDocBlock($route, $reflectionMethod); |
|
60 | + $this->getHeaders($route, $method, $skipLoginCheck); |
|
61 | + $this->getPostData($route, $reflectionMethod, $validationRules); |
|
62 | 62 | |
63 | - $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']); |
|
63 | + $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']); |
|
64 | 64 | |
65 | - preg_match('/api\/([^#]+)\//iU', $route['uri'], $module); |
|
66 | - $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/'.$module[1].'/') - 1)][] = $route; |
|
65 | + preg_match('/api\/([^#]+)\//iU', $route['uri'], $module); |
|
66 | + $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/'.$module[1].'/') - 1)][] = $route; |
|
67 | 67 | |
68 | - $this->getModels($classProperties['model'], $docData); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
68 | + $this->getModels($classProperties['model'], $docData); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - $docData['errors'] = $this->getErrors(); |
|
74 | - $docData['reports'] = \Core::reports()->all(); |
|
75 | - \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
76 | - } |
|
73 | + $docData['errors'] = $this->getErrors(); |
|
74 | + $docData['reports'] = \Core::reports()->all(); |
|
75 | + \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get list of all registered routes. |
|
80 | - * |
|
81 | - * @return collection |
|
82 | - */ |
|
83 | - protected function getRoutes() |
|
84 | - { |
|
85 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
86 | - if (strpos($route->uri(), 'api/') !== false) { |
|
87 | - return [ |
|
88 | - 'method' => $route->methods()[0], |
|
89 | - 'uri' => $route->uri(), |
|
90 | - 'action' => $route->getActionName(), |
|
91 | - 'prefix' => $route->getPrefix() |
|
92 | - ]; |
|
93 | - } |
|
94 | - return false; |
|
95 | - })->all(); |
|
96 | - } |
|
78 | + /** |
|
79 | + * Get list of all registered routes. |
|
80 | + * |
|
81 | + * @return collection |
|
82 | + */ |
|
83 | + protected function getRoutes() |
|
84 | + { |
|
85 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
86 | + if (strpos($route->uri(), 'api/') !== false) { |
|
87 | + return [ |
|
88 | + 'method' => $route->methods()[0], |
|
89 | + 'uri' => $route->uri(), |
|
90 | + 'action' => $route->getActionName(), |
|
91 | + 'prefix' => $route->getPrefix() |
|
92 | + ]; |
|
93 | + } |
|
94 | + return false; |
|
95 | + })->all(); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Generate headers for the given route. |
|
100 | - * |
|
101 | - * @param array &$route |
|
102 | - * @param string $method |
|
103 | - * @param array $skipLoginCheck |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
107 | - { |
|
108 | - $route['headers'] = [ |
|
109 | - 'Accept' => 'application/json', |
|
110 | - 'Content-Type' => 'application/json', |
|
111 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
112 | - 'time-zone' => 'Your locale time zone', |
|
113 | - ]; |
|
98 | + /** |
|
99 | + * Generate headers for the given route. |
|
100 | + * |
|
101 | + * @param array &$route |
|
102 | + * @param string $method |
|
103 | + * @param array $skipLoginCheck |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
107 | + { |
|
108 | + $route['headers'] = [ |
|
109 | + 'Accept' => 'application/json', |
|
110 | + 'Content-Type' => 'application/json', |
|
111 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
112 | + 'time-zone' => 'Your locale time zone', |
|
113 | + ]; |
|
114 | 114 | |
115 | 115 | |
116 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
117 | - $route['headers']['Authorization'] = 'Bearer {token}'; |
|
118 | - } |
|
119 | - } |
|
116 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
117 | + $route['headers']['Authorization'] = 'Bearer {token}'; |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Generate description and params for the given route |
|
123 | - * based on the docblock. |
|
124 | - * |
|
125 | - * @param array &$route |
|
126 | - * @param \ReflectionMethod $reflectionMethod |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
130 | - { |
|
131 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
132 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
133 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
134 | - $params = $docblock->getTagsByName('param'); |
|
135 | - $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
136 | - foreach ($params as $param) { |
|
137 | - $name = $param->getVariableName(); |
|
138 | - if ($name !== 'request') { |
|
139 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
121 | + /** |
|
122 | + * Generate description and params for the given route |
|
123 | + * based on the docblock. |
|
124 | + * |
|
125 | + * @param array &$route |
|
126 | + * @param \ReflectionMethod $reflectionMethod |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
130 | + { |
|
131 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
132 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
133 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
134 | + $params = $docblock->getTagsByName('param'); |
|
135 | + $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
136 | + foreach ($params as $param) { |
|
137 | + $name = $param->getVariableName(); |
|
138 | + if ($name !== 'request') { |
|
139 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Generate post body for the given route. |
|
146 | - * |
|
147 | - * @param array &$route |
|
148 | - * @param \ReflectionMethod $reflectionMethod |
|
149 | - * @param array $validationRules |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - protected function getPostData(&$route, $reflectionMethod, $validationRules) |
|
153 | - { |
|
154 | - if ($route['method'] == 'POST') { |
|
155 | - $body = $this->getMethodBody($reflectionMethod); |
|
144 | + /** |
|
145 | + * Generate post body for the given route. |
|
146 | + * |
|
147 | + * @param array &$route |
|
148 | + * @param \ReflectionMethod $reflectionMethod |
|
149 | + * @param array $validationRules |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + protected function getPostData(&$route, $reflectionMethod, $validationRules) |
|
153 | + { |
|
154 | + if ($route['method'] == 'POST') { |
|
155 | + $body = $this->getMethodBody($reflectionMethod); |
|
156 | 156 | |
157 | - preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match); |
|
158 | - if (count($match)) { |
|
159 | - if ($match[1] == '$this->validationRules') { |
|
160 | - $route['body'] = $validationRules; |
|
161 | - } else { |
|
162 | - $route['body'] = eval('return '.str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]).';'); |
|
163 | - } |
|
157 | + preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match); |
|
158 | + if (count($match)) { |
|
159 | + if ($match[1] == '$this->validationRules') { |
|
160 | + $route['body'] = $validationRules; |
|
161 | + } else { |
|
162 | + $route['body'] = eval('return '.str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]).';'); |
|
163 | + } |
|
164 | 164 | |
165 | - foreach ($route['body'] as &$rule) { |
|
166 | - if (strpos($rule, 'unique')) { |
|
167 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
168 | - } elseif (strpos($rule, 'exists')) { |
|
169 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
170 | - } |
|
171 | - } |
|
172 | - } else { |
|
173 | - $route['body'] = 'conditions'; |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
165 | + foreach ($route['body'] as &$rule) { |
|
166 | + if (strpos($rule, 'unique')) { |
|
167 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
168 | + } elseif (strpos($rule, 'exists')) { |
|
169 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
170 | + } |
|
171 | + } |
|
172 | + } else { |
|
173 | + $route['body'] = 'conditions'; |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Generate application errors. |
|
180 | - * |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - protected function getErrors() |
|
184 | - { |
|
185 | - $errors = []; |
|
186 | - $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
187 | - foreach ($reflectionClass->getMethods() as $method) { |
|
188 | - $methodName = $method->name; |
|
189 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
190 | - $body = $this->getMethodBody($reflectionMethod); |
|
178 | + /** |
|
179 | + * Generate application errors. |
|
180 | + * |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + protected function getErrors() |
|
184 | + { |
|
185 | + $errors = []; |
|
186 | + $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
187 | + foreach ($reflectionClass->getMethods() as $method) { |
|
188 | + $methodName = $method->name; |
|
189 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
190 | + $body = $this->getMethodBody($reflectionMethod); |
|
191 | 191 | |
192 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
192 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
193 | 193 | |
194 | - if (count($match)) { |
|
195 | - $errors[$match[1]][] = $methodName; |
|
196 | - } |
|
197 | - } |
|
194 | + if (count($match)) { |
|
195 | + $errors[$match[1]][] = $methodName; |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - return $errors; |
|
200 | - } |
|
199 | + return $errors; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Get the given method body code. |
|
204 | - * |
|
205 | - * @param object $reflectionMethod |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function getMethodBody($reflectionMethod) |
|
209 | - { |
|
210 | - $filename = $reflectionMethod->getFileName(); |
|
211 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
212 | - $end_line = $reflectionMethod->getEndLine(); |
|
213 | - $length = $end_line - $start_line; |
|
214 | - $source = file($filename); |
|
215 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
216 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
202 | + /** |
|
203 | + * Get the given method body code. |
|
204 | + * |
|
205 | + * @param object $reflectionMethod |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function getMethodBody($reflectionMethod) |
|
209 | + { |
|
210 | + $filename = $reflectionMethod->getFileName(); |
|
211 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
212 | + $end_line = $reflectionMethod->getEndLine(); |
|
213 | + $length = $end_line - $start_line; |
|
214 | + $source = file($filename); |
|
215 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
216 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
217 | 217 | |
218 | - return $body; |
|
219 | - } |
|
218 | + return $body; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Get example object of all availble models. |
|
223 | - * |
|
224 | - * @param string $modelName |
|
225 | - * @param array $docData |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - protected function getModels($modelName, &$docData) |
|
229 | - { |
|
230 | - if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
231 | - $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass; |
|
232 | - $model = factory($modelClass)->make(); |
|
233 | - $modelArr = $model->toArray(); |
|
221 | + /** |
|
222 | + * Get example object of all availble models. |
|
223 | + * |
|
224 | + * @param string $modelName |
|
225 | + * @param array $docData |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + protected function getModels($modelName, &$docData) |
|
229 | + { |
|
230 | + if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
231 | + $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass; |
|
232 | + $model = factory($modelClass)->make(); |
|
233 | + $modelArr = $model->toArray(); |
|
234 | 234 | |
235 | - if ($model->trans && ! $model->trans->count()) { |
|
236 | - $modelArr['trans'] = [ |
|
237 | - 'en' => factory($modelClass.'Translation')->make()->toArray() |
|
238 | - ]; |
|
239 | - } |
|
235 | + if ($model->trans && ! $model->trans->count()) { |
|
236 | + $modelArr['trans'] = [ |
|
237 | + 'en' => factory($modelClass.'Translation')->make()->toArray() |
|
238 | + ]; |
|
239 | + } |
|
240 | 240 | |
241 | - $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
242 | - } |
|
243 | - } |
|
241 | + $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Get the route response object type. |
|
247 | - * |
|
248 | - * @param string $modelName |
|
249 | - * @param string $method |
|
250 | - * @param string $returnDocBlock |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
254 | - { |
|
255 | - $config = \CoreConfig::getConfig(); |
|
256 | - $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
257 | - $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
245 | + /** |
|
246 | + * Get the route response object type. |
|
247 | + * |
|
248 | + * @param string $modelName |
|
249 | + * @param string $method |
|
250 | + * @param string $returnDocBlock |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
254 | + { |
|
255 | + $config = \CoreConfig::getConfig(); |
|
256 | + $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
257 | + $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
258 | 258 | |
259 | - return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
260 | - } |
|
259 | + return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
260 | + } |
|
261 | 261 | } |
@@ -13,11 +13,11 @@ |
||
13 | 13 | |
14 | 14 | Route::group(['prefix' => 'settings'], function () { |
15 | 15 | |
16 | - Route::get('/', 'SettingController@index'); |
|
17 | - Route::get('/{id}', 'SettingController@find'); |
|
18 | - Route::put('/', 'SettingController@update'); |
|
19 | - Route::delete('/{id}', 'SettingController@delete'); |
|
20 | - Route::get('list/deleted', 'SettingController@deleted'); |
|
21 | - Route::patch('restore/{id}', 'SettingController@restore'); |
|
22 | - Route::post('save/many', 'SettingController@saveMany'); |
|
16 | + Route::get('/', 'SettingController@index'); |
|
17 | + Route::get('/{id}', 'SettingController@find'); |
|
18 | + Route::put('/', 'SettingController@update'); |
|
19 | + Route::delete('/{id}', 'SettingController@delete'); |
|
20 | + Route::get('list/deleted', 'SettingController@deleted'); |
|
21 | + Route::patch('restore/{id}', 'SettingController@restore'); |
|
22 | + Route::post('save/many', 'SettingController@saveMany'); |
|
23 | 23 | }); |
24 | 24 | \ No newline at end of file |
@@ -6,53 +6,53 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | - |
|
19 | - $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - //Bind Core Facade to the Service Container |
|
31 | - $this->app->singleton('Core', function () { |
|
32 | - return new \App\Modules\Core\Core; |
|
33 | - }); |
|
34 | - |
|
35 | - //Bind ErrorHandler Facade to the Service Container |
|
36 | - $this->app->singleton('ErrorHandler', function () { |
|
37 | - return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | - }); |
|
39 | - |
|
40 | - //Bind CoreConfig Facade to the Service Container |
|
41 | - $this->app->singleton('CoreConfig', function () { |
|
42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | - }); |
|
44 | - |
|
45 | - //Bind Media Facade to the Service Container |
|
46 | - $this->app->singleton('Media', function () { |
|
47 | - return new \App\Modules\Core\Utl\Media; |
|
48 | - }); |
|
49 | - |
|
50 | - //Bind ApiConsumer Facade to the Service Container |
|
51 | - $this->app->singleton('ApiConsumer', function () { |
|
52 | - $app = app(); |
|
53 | - return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | - }); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | + |
|
19 | + $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + //Bind Core Facade to the Service Container |
|
31 | + $this->app->singleton('Core', function () { |
|
32 | + return new \App\Modules\Core\Core; |
|
33 | + }); |
|
34 | + |
|
35 | + //Bind ErrorHandler Facade to the Service Container |
|
36 | + $this->app->singleton('ErrorHandler', function () { |
|
37 | + return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | + }); |
|
39 | + |
|
40 | + //Bind CoreConfig Facade to the Service Container |
|
41 | + $this->app->singleton('CoreConfig', function () { |
|
42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | + }); |
|
44 | + |
|
45 | + //Bind Media Facade to the Service Container |
|
46 | + $this->app->singleton('Media', function () { |
|
47 | + return new \App\Modules\Core\Utl\Media; |
|
48 | + }); |
|
49 | + |
|
50 | + //Bind ApiConsumer Facade to the Service Container |
|
51 | + $this->app->singleton('ApiConsumer', function () { |
|
52 | + $app = app(); |
|
53 | + return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | + }); |
|
55 | 55 | |
56 | - $this->app->register(RouteServiceProvider::class); |
|
57 | - } |
|
56 | + $this->app->register(RouteServiceProvider::class); |
|
57 | + } |
|
58 | 58 | } |
@@ -5,116 +5,116 @@ |
||
5 | 5 | |
6 | 6 | class CachingDecorator |
7 | 7 | { |
8 | - /** |
|
9 | - * The repo implementation. |
|
10 | - * |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - public $repo; |
|
8 | + /** |
|
9 | + * The repo implementation. |
|
10 | + * |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + public $repo; |
|
14 | 14 | |
15 | - /** |
|
16 | - * The cache implementation. |
|
17 | - * |
|
18 | - * @var object |
|
19 | - */ |
|
20 | - protected $cache; |
|
15 | + /** |
|
16 | + * The cache implementation. |
|
17 | + * |
|
18 | + * @var object |
|
19 | + */ |
|
20 | + protected $cache; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The modelKey implementation. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $modelKey; |
|
22 | + /** |
|
23 | + * The modelKey implementation. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $modelKey; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The model implementation. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - public $model; |
|
29 | + /** |
|
30 | + * The model implementation. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + public $model; |
|
35 | 35 | |
36 | - /** |
|
37 | - * The modelClass implementation. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $modelClass; |
|
36 | + /** |
|
37 | + * The modelClass implementation. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $modelClass; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The cacheConfig implementation. |
|
45 | - * |
|
46 | - * @var mixed |
|
47 | - */ |
|
48 | - public $cacheConfig; |
|
43 | + /** |
|
44 | + * The cacheConfig implementation. |
|
45 | + * |
|
46 | + * @var mixed |
|
47 | + */ |
|
48 | + public $cacheConfig; |
|
49 | 49 | |
50 | - /** |
|
51 | - * The cacheTag implementation. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $cacheTag; |
|
50 | + /** |
|
51 | + * The cacheTag implementation. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $cacheTag; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Init new object. |
|
59 | - * |
|
60 | - * @param string $repo |
|
61 | - * @param Cache $cache |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function __construct($repo, Cache $cache) |
|
66 | - { |
|
67 | - $this->repo = $repo; |
|
68 | - $this->cache = $cache; |
|
69 | - $this->model = $this->repo->model; |
|
70 | - $this->modelClass = get_class($this->model); |
|
71 | - $repoClass = explode('\\', get_class($this->repo)); |
|
72 | - $repoName = end($repoClass); |
|
73 | - $this->cacheTag = lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))); |
|
74 | - } |
|
57 | + /** |
|
58 | + * Init new object. |
|
59 | + * |
|
60 | + * @param string $repo |
|
61 | + * @param Cache $cache |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function __construct($repo, Cache $cache) |
|
66 | + { |
|
67 | + $this->repo = $repo; |
|
68 | + $this->cache = $cache; |
|
69 | + $this->model = $this->repo->model; |
|
70 | + $this->modelClass = get_class($this->model); |
|
71 | + $repoClass = explode('\\', get_class($this->repo)); |
|
72 | + $repoName = end($repoClass); |
|
73 | + $this->cacheTag = lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Handle the cache mechanism for the called method |
|
78 | - * based the configurations. |
|
79 | - * |
|
80 | - * @param string $name the called method name |
|
81 | - * @param array $arguments the method arguments |
|
82 | - * @return object |
|
83 | - */ |
|
84 | - public function __call($name, $arguments) |
|
85 | - { |
|
86 | - $this->setCacheConfig($name); |
|
76 | + /** |
|
77 | + * Handle the cache mechanism for the called method |
|
78 | + * based the configurations. |
|
79 | + * |
|
80 | + * @param string $name the called method name |
|
81 | + * @param array $arguments the method arguments |
|
82 | + * @return object |
|
83 | + */ |
|
84 | + public function __call($name, $arguments) |
|
85 | + { |
|
86 | + $this->setCacheConfig($name); |
|
87 | 87 | |
88 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
89 | - $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
90 | - $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
91 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
92 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
93 | - }); |
|
94 | - } elseif ($this->cacheConfig) { |
|
95 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
96 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | - } |
|
88 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
89 | + $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
90 | + $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
91 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
92 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
93 | + }); |
|
94 | + } elseif ($this->cacheConfig) { |
|
95 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
96 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | + } |
|
98 | 98 | |
99 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
100 | - } |
|
99 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set cache config based on the called method. |
|
104 | - * |
|
105 | - * @param string $name |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - private function setCacheConfig($name) |
|
109 | - { |
|
110 | - $config = \CoreConfig::getConfig(); |
|
111 | - $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
112 | - $this->cacheConfig = false; |
|
102 | + /** |
|
103 | + * Set cache config based on the called method. |
|
104 | + * |
|
105 | + * @param string $name |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + private function setCacheConfig($name) |
|
109 | + { |
|
110 | + $config = \CoreConfig::getConfig(); |
|
111 | + $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
112 | + $this->cacheConfig = false; |
|
113 | 113 | |
114 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
115 | - $this->cacheConfig = 'cache'; |
|
116 | - } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
117 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
118 | - } |
|
119 | - } |
|
114 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
115 | + $this->cacheConfig = 'cache'; |
|
116 | + } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
117 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
118 | + } |
|
119 | + } |
|
120 | 120 | } |
@@ -10,204 +10,204 @@ |
||
10 | 10 | |
11 | 11 | class BaseApiController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * The config implementation. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $config; |
|
19 | - |
|
20 | - /** |
|
21 | - * The relations implementation. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $relations; |
|
26 | - |
|
27 | - /** |
|
28 | - * The repo implementation. |
|
29 | - * |
|
30 | - * @var object |
|
31 | - */ |
|
32 | - protected $repo; |
|
33 | - |
|
34 | - /** |
|
35 | - * Init new object. |
|
36 | - * |
|
37 | - * @param mixed $repo |
|
38 | - * @param CoreConfig $config |
|
39 | - * @param string $modelResource |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function __construct($repo, $config, $modelResource) |
|
43 | - { |
|
44 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | - $this->modelResource = $modelResource; |
|
46 | - $this->config = $config->getConfig(); |
|
47 | - $this->modelName = explode('\\', get_called_class()); |
|
48 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | - |
|
54 | - $this->setSessions(); |
|
55 | - $this->checkPermission($route); |
|
56 | - $this->setRelations($route); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fetch all records with relations from storage. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index(Request $request) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Fetch the single object with relations from storage. |
|
72 | - * |
|
73 | - * @param integer $id Id of the requested model. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function find($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Delete by the given id from storage. |
|
83 | - * |
|
84 | - * @param integer $id Id of the deleted model. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function delete($id) |
|
88 | - { |
|
89 | - return new GeneralResource($this->repo->delete($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Return the deleted models in pages based on the given conditions. |
|
94 | - * |
|
95 | - * @param Request $request |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function deleted(Request $request) |
|
99 | - { |
|
100 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Restore the deleted model. |
|
105 | - * |
|
106 | - * @param integer $id Id of the restored model. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function restore($id) |
|
110 | - { |
|
111 | - return new GeneralResource($this->repo->restore($id)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Check if the logged in user can do the given permission. |
|
116 | - * |
|
117 | - * @param string $permission |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - private function checkPermission($permission) |
|
121 | - { |
|
122 | - \Auth::shouldUse('api'); |
|
123 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
13 | + /** |
|
14 | + * The config implementation. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $config; |
|
19 | + |
|
20 | + /** |
|
21 | + * The relations implementation. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $relations; |
|
26 | + |
|
27 | + /** |
|
28 | + * The repo implementation. |
|
29 | + * |
|
30 | + * @var object |
|
31 | + */ |
|
32 | + protected $repo; |
|
33 | + |
|
34 | + /** |
|
35 | + * Init new object. |
|
36 | + * |
|
37 | + * @param mixed $repo |
|
38 | + * @param CoreConfig $config |
|
39 | + * @param string $modelResource |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function __construct($repo, $config, $modelResource) |
|
43 | + { |
|
44 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | + $this->modelResource = $modelResource; |
|
46 | + $this->config = $config->getConfig(); |
|
47 | + $this->modelName = explode('\\', get_called_class()); |
|
48 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | + |
|
54 | + $this->setSessions(); |
|
55 | + $this->checkPermission($route); |
|
56 | + $this->setRelations($route); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fetch all records with relations from storage. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index(Request $request) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Fetch the single object with relations from storage. |
|
72 | + * |
|
73 | + * @param integer $id Id of the requested model. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function find($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Delete by the given id from storage. |
|
83 | + * |
|
84 | + * @param integer $id Id of the deleted model. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function delete($id) |
|
88 | + { |
|
89 | + return new GeneralResource($this->repo->delete($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Return the deleted models in pages based on the given conditions. |
|
94 | + * |
|
95 | + * @param Request $request |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function deleted(Request $request) |
|
99 | + { |
|
100 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Restore the deleted model. |
|
105 | + * |
|
106 | + * @param integer $id Id of the restored model. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function restore($id) |
|
110 | + { |
|
111 | + return new GeneralResource($this->repo->restore($id)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Check if the logged in user can do the given permission. |
|
116 | + * |
|
117 | + * @param string $permission |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + private function checkPermission($permission) |
|
121 | + { |
|
122 | + \Auth::shouldUse('api'); |
|
123 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | - $user = \Auth::user(); |
|
127 | - $isPasswordClient = $user->token()->client->password_client; |
|
128 | - $this->updateLocaleAndTimezone($user); |
|
129 | - |
|
130 | - if ($user->blocked) { |
|
131 | - \ErrorHandler::userIsBlocked(); |
|
132 | - } |
|
133 | - |
|
134 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | - } else { |
|
137 | - \ErrorHandler::noPermissions(); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Set sessions based on the given headers in the request. |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - private function setSessions() |
|
148 | - { |
|
149 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | - |
|
151 | - $locale = \Request::header('locale'); |
|
152 | - switch ($locale) { |
|
153 | - case 'en': |
|
154 | - \App::setLocale('en'); |
|
155 | - \Session::put('locale', 'en'); |
|
156 | - break; |
|
157 | - |
|
158 | - case 'ar': |
|
159 | - \App::setLocale('ar'); |
|
160 | - \Session::put('locale', 'ar'); |
|
161 | - break; |
|
162 | - |
|
163 | - case 'all': |
|
164 | - \App::setLocale('en'); |
|
165 | - \Session::put('locale', 'all'); |
|
166 | - break; |
|
167 | - |
|
168 | - default: |
|
169 | - \App::setLocale('en'); |
|
170 | - \Session::put('locale', 'en'); |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Set relation based on the called api. |
|
177 | - * |
|
178 | - * @param string $route |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function setRelations($route) |
|
182 | - { |
|
183 | - $route = $route !== 'index' ? $route : 'list'; |
|
184 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Update the logged in user locale and time zone. |
|
190 | - * |
|
191 | - * @param object $user |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - private function updateLocaleAndTimezone($user) |
|
195 | - { |
|
196 | - $update = false; |
|
197 | - $locale = \Session::get('locale'); |
|
198 | - $timezone = \Session::get('time-zone'); |
|
199 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | - $user->locale = $locale; |
|
201 | - $update = true; |
|
202 | - } |
|
203 | - |
|
204 | - if ($timezone && $timezone !== $user->timezone) { |
|
205 | - $user->timezone = $timezone; |
|
206 | - $update = true; |
|
207 | - } |
|
208 | - |
|
209 | - if ($update) { |
|
210 | - $user->save(); |
|
211 | - } |
|
212 | - } |
|
125 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | + $user = \Auth::user(); |
|
127 | + $isPasswordClient = $user->token()->client->password_client; |
|
128 | + $this->updateLocaleAndTimezone($user); |
|
129 | + |
|
130 | + if ($user->blocked) { |
|
131 | + \ErrorHandler::userIsBlocked(); |
|
132 | + } |
|
133 | + |
|
134 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | + } else { |
|
137 | + \ErrorHandler::noPermissions(); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Set sessions based on the given headers in the request. |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + private function setSessions() |
|
148 | + { |
|
149 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | + |
|
151 | + $locale = \Request::header('locale'); |
|
152 | + switch ($locale) { |
|
153 | + case 'en': |
|
154 | + \App::setLocale('en'); |
|
155 | + \Session::put('locale', 'en'); |
|
156 | + break; |
|
157 | + |
|
158 | + case 'ar': |
|
159 | + \App::setLocale('ar'); |
|
160 | + \Session::put('locale', 'ar'); |
|
161 | + break; |
|
162 | + |
|
163 | + case 'all': |
|
164 | + \App::setLocale('en'); |
|
165 | + \Session::put('locale', 'all'); |
|
166 | + break; |
|
167 | + |
|
168 | + default: |
|
169 | + \App::setLocale('en'); |
|
170 | + \Session::put('locale', 'en'); |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Set relation based on the called api. |
|
177 | + * |
|
178 | + * @param string $route |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function setRelations($route) |
|
182 | + { |
|
183 | + $route = $route !== 'index' ? $route : 'list'; |
|
184 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Update the logged in user locale and time zone. |
|
190 | + * |
|
191 | + * @param object $user |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + private function updateLocaleAndTimezone($user) |
|
195 | + { |
|
196 | + $update = false; |
|
197 | + $locale = \Session::get('locale'); |
|
198 | + $timezone = \Session::get('time-zone'); |
|
199 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | + $user->locale = $locale; |
|
201 | + $update = true; |
|
202 | + } |
|
203 | + |
|
204 | + if ($timezone && $timezone !== $user->timezone) { |
|
205 | + $user->timezone = $timezone; |
|
206 | + $update = true; |
|
207 | + } |
|
208 | + |
|
209 | + if ($update) { |
|
210 | + $user->save(); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -6,32 +6,32 @@ |
||
6 | 6 | |
7 | 7 | class Setting extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Indicates if the resource's collection keys should be preserved. |
|
11 | - * |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - public $preserveKeys = true; |
|
9 | + /** |
|
10 | + * Indicates if the resource's collection keys should be preserved. |
|
11 | + * |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + public $preserveKeys = true; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Transform the resource into an array. |
|
18 | - * |
|
19 | - * @param Request $request |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function toArray($request) |
|
23 | - { |
|
24 | - if (! $this->resource) { |
|
25 | - return []; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Transform the resource into an array. |
|
18 | + * |
|
19 | + * @param Request $request |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function toArray($request) |
|
23 | + { |
|
24 | + if (! $this->resource) { |
|
25 | + return []; |
|
26 | + } |
|
27 | 27 | |
28 | - return [ |
|
29 | - 'id' => $this->id, |
|
30 | - 'name' => $this->name, |
|
31 | - 'value' => $this->value, |
|
32 | - 'key' => $this->key, |
|
33 | - 'created_at' => $this->created_at, |
|
34 | - 'updated_at' => $this->updated_at, |
|
35 | - ]; |
|
36 | - } |
|
28 | + return [ |
|
29 | + 'id' => $this->id, |
|
30 | + 'name' => $this->name, |
|
31 | + 'value' => $this->value, |
|
32 | + 'key' => $this->key, |
|
33 | + 'created_at' => $this->created_at, |
|
34 | + 'updated_at' => $this->updated_at, |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | } |
@@ -13,12 +13,12 @@ |
||
13 | 13 | |
14 | 14 | Route::group(['prefix' => 'reports'], function () { |
15 | 15 | |
16 | - Route::get('/', 'ReportController@index'); |
|
17 | - Route::get('/{id}', 'ReportController@find'); |
|
18 | - Route::post('/', 'ReportController@insert'); |
|
19 | - Route::put('/', 'ReportController@update'); |
|
20 | - Route::delete('/{id}', 'ReportController@delete'); |
|
21 | - Route::get('list/deleted', 'ReportController@deleted'); |
|
22 | - Route::patch('restore/{id}', 'ReportController@restore'); |
|
23 | - Route::post('get/{reportName}', 'ReportController@getReport'); |
|
16 | + Route::get('/', 'ReportController@index'); |
|
17 | + Route::get('/{id}', 'ReportController@find'); |
|
18 | + Route::post('/', 'ReportController@insert'); |
|
19 | + Route::put('/', 'ReportController@update'); |
|
20 | + Route::delete('/{id}', 'ReportController@delete'); |
|
21 | + Route::get('list/deleted', 'ReportController@deleted'); |
|
22 | + Route::patch('restore/{id}', 'ReportController@restore'); |
|
23 | + Route::post('get/{reportName}', 'ReportController@getReport'); |
|
24 | 24 | }); |
25 | 25 | \ No newline at end of file |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
18 | 18 | |
19 | - $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | - } |
|
19 | + $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - $this->app->register(RouteServiceProvider::class); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + $this->app->register(RouteServiceProvider::class); |
|
31 | + } |
|
32 | 32 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class Report extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - if (! $this->resource) { |
|
18 | - return []; |
|
19 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + if (! $this->resource) { |
|
18 | + return []; |
|
19 | + } |
|
20 | 20 | |
21 | - return [ |
|
22 | - 'id' => $this->id, |
|
23 | - 'report_name' => $this->report_name, |
|
24 | - 'view_name' => $this->view_name, |
|
25 | - 'created_at' => $this->created_at, |
|
26 | - 'updated_at' => $this->updated_at, |
|
27 | - ]; |
|
28 | - } |
|
21 | + return [ |
|
22 | + 'id' => $this->id, |
|
23 | + 'report_name' => $this->report_name, |
|
24 | + 'view_name' => $this->view_name, |
|
25 | + 'created_at' => $this->created_at, |
|
26 | + 'updated_at' => $this->updated_at, |
|
27 | + ]; |
|
28 | + } |
|
29 | 29 | } |