@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | /** |
| 208 | 208 | * Get the given method body code. |
| 209 | 209 | * |
| 210 | - * @param object $reflectionMethod |
|
| 210 | + * @param \ReflectionMethod $reflectionMethod |
|
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | 213 | protected function getMethodBody($reflectionMethod) |
@@ -228,6 +228,7 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @param string $modelName |
| 230 | 230 | * @param array $docData |
| 231 | + * @param \ReflectionClass $reflectionClass |
|
| 231 | 232 | * @return string |
| 232 | 233 | */ |
| 233 | 234 | protected function getModels($modelName, &$docData, $reflectionClass) |
@@ -7,265 +7,265 @@ |
||
| 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 | - $modelName = explode('\\', $controller); |
|
| 57 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 52 | + $reflectionClass = new \ReflectionClass($controller); |
|
| 53 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
| 54 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 55 | + $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
| 56 | + $modelName = explode('\\', $controller); |
|
| 57 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 58 | 58 | |
| 59 | - $this->processDocBlock($route, $reflectionMethod); |
|
| 60 | - $this->getHeaders($route, $method, $skipLoginCheck); |
|
| 61 | - $this->getPostData($route, $reflectionMethod); |
|
| 59 | + $this->processDocBlock($route, $reflectionMethod); |
|
| 60 | + $this->getHeaders($route, $method, $skipLoginCheck); |
|
| 61 | + $this->getPostData($route, $reflectionMethod); |
|
| 62 | 62 | |
| 63 | - $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
| 63 | + $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
| 64 | 64 | |
| 65 | - $module = $route['prefix']; |
|
| 66 | - $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
| 67 | - $docData['modules'][$module][] = $route; |
|
| 65 | + $module = $route['prefix']; |
|
| 66 | + $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
| 67 | + $docData['modules'][$module][] = $route; |
|
| 68 | 68 | |
| 69 | - $this->getModels($modelName, $docData, $reflectionClass); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 69 | + $this->getModels($modelName, $docData, $reflectionClass); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $docData['errors'] = $this->getErrors(); |
|
| 75 | - $docData['reports'] = \Core::reports()->all(); |
|
| 76 | - \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
| 77 | - } |
|
| 74 | + $docData['errors'] = $this->getErrors(); |
|
| 75 | + $docData['reports'] = \Core::reports()->all(); |
|
| 76 | + \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get list of all registered routes. |
|
| 81 | - * |
|
| 82 | - * @return collection |
|
| 83 | - */ |
|
| 84 | - protected function getRoutes() |
|
| 85 | - { |
|
| 86 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
| 87 | - if (strpos($route->uri(), 'api/') !== false) { |
|
| 88 | - return [ |
|
| 89 | - 'method' => $route->methods()[0], |
|
| 90 | - 'uri' => $route->uri(), |
|
| 91 | - 'action' => $route->getActionName(), |
|
| 92 | - 'prefix' => $route->getPrefix() |
|
| 93 | - ]; |
|
| 94 | - } |
|
| 95 | - return false; |
|
| 96 | - })->all(); |
|
| 97 | - } |
|
| 79 | + /** |
|
| 80 | + * Get list of all registered routes. |
|
| 81 | + * |
|
| 82 | + * @return collection |
|
| 83 | + */ |
|
| 84 | + protected function getRoutes() |
|
| 85 | + { |
|
| 86 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
| 87 | + if (strpos($route->uri(), 'api/') !== false) { |
|
| 88 | + return [ |
|
| 89 | + 'method' => $route->methods()[0], |
|
| 90 | + 'uri' => $route->uri(), |
|
| 91 | + 'action' => $route->getActionName(), |
|
| 92 | + 'prefix' => $route->getPrefix() |
|
| 93 | + ]; |
|
| 94 | + } |
|
| 95 | + return false; |
|
| 96 | + })->all(); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Generate headers for the given route. |
|
| 101 | - * |
|
| 102 | - * @param array &$route |
|
| 103 | - * @param string $method |
|
| 104 | - * @param array $skipLoginCheck |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
| 108 | - { |
|
| 109 | - $route['headers'] = [ |
|
| 110 | - 'Accept' => 'application/json', |
|
| 111 | - 'Content-Type' => 'application/json', |
|
| 112 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
| 113 | - 'time-zone' => 'Your locale time zone', |
|
| 114 | - ]; |
|
| 99 | + /** |
|
| 100 | + * Generate headers for the given route. |
|
| 101 | + * |
|
| 102 | + * @param array &$route |
|
| 103 | + * @param string $method |
|
| 104 | + * @param array $skipLoginCheck |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
| 108 | + { |
|
| 109 | + $route['headers'] = [ |
|
| 110 | + 'Accept' => 'application/json', |
|
| 111 | + 'Content-Type' => 'application/json', |
|
| 112 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
| 113 | + 'time-zone' => 'Your locale time zone', |
|
| 114 | + ]; |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 118 | - $route['headers']['Authorization'] = 'Bearer {token}'; |
|
| 119 | - } |
|
| 120 | - } |
|
| 117 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 118 | + $route['headers']['Authorization'] = 'Bearer {token}'; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Generate description and params for the given route |
|
| 124 | - * based on the docblock. |
|
| 125 | - * |
|
| 126 | - * @param array &$route |
|
| 127 | - * @param \ReflectionMethod $reflectionMethod |
|
| 128 | - * @return void |
|
| 129 | - */ |
|
| 130 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
| 131 | - { |
|
| 132 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
| 133 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
| 134 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
| 135 | - $params = $docblock->getTagsByName('param'); |
|
| 136 | - $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
| 122 | + /** |
|
| 123 | + * Generate description and params for the given route |
|
| 124 | + * based on the docblock. |
|
| 125 | + * |
|
| 126 | + * @param array &$route |
|
| 127 | + * @param \ReflectionMethod $reflectionMethod |
|
| 128 | + * @return void |
|
| 129 | + */ |
|
| 130 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
| 131 | + { |
|
| 132 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
| 133 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
| 134 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
| 135 | + $params = $docblock->getTagsByName('param'); |
|
| 136 | + $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
| 137 | 137 | |
| 138 | - foreach ($params as $param) { |
|
| 139 | - $name = $param->getVariableName(); |
|
| 140 | - if ($name !== 'request') { |
|
| 141 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
| 142 | - } |
|
| 143 | - } |
|
| 138 | + foreach ($params as $param) { |
|
| 139 | + $name = $param->getVariableName(); |
|
| 140 | + if ($name !== 'request') { |
|
| 141 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ($route['name'] === 'list') { |
|
| 146 | - $route['parametars']['perPage'] = 'perPage'; |
|
| 147 | - $route['parametars']['sortBy'] = 'sortBy'; |
|
| 148 | - $route['parametars']['desc'] = 'desc'; |
|
| 149 | - } |
|
| 150 | - } |
|
| 145 | + if ($route['name'] === 'list') { |
|
| 146 | + $route['parametars']['perPage'] = 'perPage'; |
|
| 147 | + $route['parametars']['sortBy'] = 'sortBy'; |
|
| 148 | + $route['parametars']['desc'] = 'desc'; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Generate post body for the given route. |
|
| 154 | - * |
|
| 155 | - * @param array &$route |
|
| 156 | - * @param \ReflectionMethod $reflectionMethod |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - protected function getPostData(&$route, $reflectionMethod) |
|
| 160 | - { |
|
| 161 | - $parameters = $reflectionMethod->getParameters(); |
|
| 162 | - if (count($parameters)) { |
|
| 163 | - $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
| 164 | - if ($className) { |
|
| 165 | - $reflectionClass = new \ReflectionClass($className); |
|
| 152 | + /** |
|
| 153 | + * Generate post body for the given route. |
|
| 154 | + * |
|
| 155 | + * @param array &$route |
|
| 156 | + * @param \ReflectionMethod $reflectionMethod |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + protected function getPostData(&$route, $reflectionMethod) |
|
| 160 | + { |
|
| 161 | + $parameters = $reflectionMethod->getParameters(); |
|
| 162 | + if (count($parameters)) { |
|
| 163 | + $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
| 164 | + if ($className) { |
|
| 165 | + $reflectionClass = new \ReflectionClass($className); |
|
| 166 | 166 | |
| 167 | - if ($reflectionClass->hasMethod('rules')) { |
|
| 168 | - $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
| 169 | - $route['body'] = $reflectionMethod->invoke(new $className); |
|
| 167 | + if ($reflectionClass->hasMethod('rules')) { |
|
| 168 | + $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
| 169 | + $route['body'] = $reflectionMethod->invoke(new $className); |
|
| 170 | 170 | |
| 171 | - foreach ($route['body'] as &$rule) { |
|
| 172 | - if (strpos($rule, 'unique')) { |
|
| 173 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
| 174 | - } elseif (strpos($rule, 'exists')) { |
|
| 175 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 171 | + foreach ($route['body'] as &$rule) { |
|
| 172 | + if (strpos($rule, 'unique')) { |
|
| 173 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
| 174 | + } elseif (strpos($rule, 'exists')) { |
|
| 175 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Generate application errors. |
|
| 185 | - * |
|
| 186 | - * @return array |
|
| 187 | - */ |
|
| 188 | - protected function getErrors() |
|
| 189 | - { |
|
| 190 | - $errors = []; |
|
| 191 | - $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
| 192 | - foreach ($reflectionClass->getMethods() as $method) { |
|
| 193 | - $methodName = $method->name; |
|
| 194 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
| 195 | - $body = $this->getMethodBody($reflectionMethod); |
|
| 183 | + /** |
|
| 184 | + * Generate application errors. |
|
| 185 | + * |
|
| 186 | + * @return array |
|
| 187 | + */ |
|
| 188 | + protected function getErrors() |
|
| 189 | + { |
|
| 190 | + $errors = []; |
|
| 191 | + $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
| 192 | + foreach ($reflectionClass->getMethods() as $method) { |
|
| 193 | + $methodName = $method->name; |
|
| 194 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
| 195 | + $body = $this->getMethodBody($reflectionMethod); |
|
| 196 | 196 | |
| 197 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
| 197 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
| 198 | 198 | |
| 199 | - if (count($match)) { |
|
| 200 | - $errors[$match[1]][] = $methodName; |
|
| 201 | - } |
|
| 202 | - } |
|
| 199 | + if (count($match)) { |
|
| 200 | + $errors[$match[1]][] = $methodName; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $errors; |
|
| 205 | - } |
|
| 204 | + return $errors; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Get the given method body code. |
|
| 209 | - * |
|
| 210 | - * @param object $reflectionMethod |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - protected function getMethodBody($reflectionMethod) |
|
| 214 | - { |
|
| 215 | - $filename = $reflectionMethod->getFileName(); |
|
| 216 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
| 217 | - $end_line = $reflectionMethod->getEndLine(); |
|
| 218 | - $length = $end_line - $start_line; |
|
| 219 | - $source = file($filename); |
|
| 220 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
| 221 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
| 207 | + /** |
|
| 208 | + * Get the given method body code. |
|
| 209 | + * |
|
| 210 | + * @param object $reflectionMethod |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + protected function getMethodBody($reflectionMethod) |
|
| 214 | + { |
|
| 215 | + $filename = $reflectionMethod->getFileName(); |
|
| 216 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
| 217 | + $end_line = $reflectionMethod->getEndLine(); |
|
| 218 | + $length = $end_line - $start_line; |
|
| 219 | + $source = file($filename); |
|
| 220 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
| 221 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
| 222 | 222 | |
| 223 | - return $body; |
|
| 224 | - } |
|
| 223 | + return $body; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Get example object of all availble models. |
|
| 228 | - * |
|
| 229 | - * @param string $modelName |
|
| 230 | - * @param array $docData |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - protected function getModels($modelName, &$docData, $reflectionClass) |
|
| 234 | - { |
|
| 235 | - if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
| 236 | - $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
| 237 | - $model = factory($modelClass)->make(); |
|
| 226 | + /** |
|
| 227 | + * Get example object of all availble models. |
|
| 228 | + * |
|
| 229 | + * @param string $modelName |
|
| 230 | + * @param array $docData |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + protected function getModels($modelName, &$docData, $reflectionClass) |
|
| 234 | + { |
|
| 235 | + if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
| 236 | + $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
| 237 | + $model = factory($modelClass)->make(); |
|
| 238 | 238 | |
| 239 | - $property = $reflectionClass->getProperty('modelResource'); |
|
| 240 | - $property->setAccessible(true); |
|
| 241 | - $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
| 242 | - $modelResource = new $modelResource($model); |
|
| 243 | - $modelArr = $modelResource->toArray([]); |
|
| 239 | + $property = $reflectionClass->getProperty('modelResource'); |
|
| 240 | + $property->setAccessible(true); |
|
| 241 | + $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
| 242 | + $modelResource = new $modelResource($model); |
|
| 243 | + $modelArr = $modelResource->toArray([]); |
|
| 244 | 244 | |
| 245 | - foreach ($modelArr as $key => $attr) { |
|
| 246 | - if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
| 247 | - unset($modelArr[$key]); |
|
| 248 | - } |
|
| 249 | - } |
|
| 245 | + foreach ($modelArr as $key => $attr) { |
|
| 246 | + if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
| 247 | + unset($modelArr[$key]); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
| 252 | - } |
|
| 253 | - } |
|
| 251 | + $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Get the route response object type. |
|
| 257 | - * |
|
| 258 | - * @param string $modelName |
|
| 259 | - * @param string $method |
|
| 260 | - * @param string $returnDocBlock |
|
| 261 | - * @return array |
|
| 262 | - */ |
|
| 263 | - protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
| 264 | - { |
|
| 265 | - $config = \CoreConfig::getConfig(); |
|
| 266 | - $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
| 267 | - $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
| 255 | + /** |
|
| 256 | + * Get the route response object type. |
|
| 257 | + * |
|
| 258 | + * @param string $modelName |
|
| 259 | + * @param string $method |
|
| 260 | + * @param string $returnDocBlock |
|
| 261 | + * @return array |
|
| 262 | + */ |
|
| 263 | + protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
| 264 | + { |
|
| 265 | + $config = \CoreConfig::getConfig(); |
|
| 266 | + $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
| 267 | + $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
| 268 | 268 | |
| 269 | - return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
| 270 | - } |
|
| 269 | + return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
| 270 | + } |
|
| 271 | 271 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | protected function getRoutes() |
| 85 | 85 | { |
| 86 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
| 86 | + return collect(\Route::getRoutes())->map(function($route) { |
|
| 87 | 87 | if (strpos($route->uri(), 'api/') !== false) { |
| 88 | 88 | return [ |
| 89 | 89 | 'method' => $route->methods()[0], |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ]; |
| 115 | 115 | |
| 116 | 116 | |
| 117 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 117 | + if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 118 | 118 | $route['headers']['Authorization'] = 'Bearer {token}'; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | if (count($parameters)) { |
| 163 | 163 | $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
| 164 | 164 | if ($className) { |
| 165 | - $reflectionClass = new \ReflectionClass($className); |
|
| 165 | + $reflectionClass = new \ReflectionClass($className); |
|
| 166 | 166 | |
| 167 | 167 | if ($reflectionClass->hasMethod('rules')) { |
| 168 | 168 | $reflectionMethod = $reflectionClass->getMethod('rules'); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\Core\Setting::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 5 | - 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
|
| 6 | - 'value' => $faker->word(), |
|
| 7 | - 'key' => $faker->word(), |
|
| 8 | - 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
|
| 9 | - 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
|
| 10 | - ]; |
|
| 4 | + return [ |
|
| 5 | + 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
|
| 6 | + 'value' => $faker->word(), |
|
| 7 | + 'key' => $faker->word(), |
|
| 8 | + 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
|
| 9 | + 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
|
| 10 | + ]; |
|
| 11 | 11 | }); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$factory->define(App\Modules\Core\Setting::class, function (Faker\Generator $faker) { |
|
| 3 | +$factory->define(App\Modules\Core\Setting::class, function(Faker\Generator $faker) { |
|
| 4 | 4 | return [ |
| 5 | 5 | 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
| 6 | 6 | 'value' => $faker->word(), |
@@ -12,73 +12,73 @@ |
||
| 12 | 12 | |
| 13 | 13 | class CheckPermissions |
| 14 | 14 | { |
| 15 | - protected $route; |
|
| 16 | - protected $auth; |
|
| 17 | - protected $errorHandler; |
|
| 18 | - protected $authMiddleware; |
|
| 19 | - protected $core; |
|
| 20 | - protected $arr; |
|
| 15 | + protected $route; |
|
| 16 | + protected $auth; |
|
| 17 | + protected $errorHandler; |
|
| 18 | + protected $authMiddleware; |
|
| 19 | + protected $core; |
|
| 20 | + protected $arr; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Init new object. |
|
| 24 | - * |
|
| 25 | - * @param Route $route |
|
| 26 | - * @param Auth $auth |
|
| 27 | - * @param ErrorHandler $errorHandler |
|
| 28 | - * @param AuthMiddleware $authMiddleware |
|
| 29 | - * @param Core $core |
|
| 30 | - * @param Arr $arr |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public function __construct(Route $route, Auth $auth, ErrorHandler $errorHandler, AuthMiddleware $authMiddleware, Core $core, Arr $arr) |
|
| 35 | - { |
|
| 36 | - $this->route = $route; |
|
| 37 | - $this->auth = $auth; |
|
| 38 | - $this->errorHandler = $errorHandler; |
|
| 39 | - $this->authMiddleware = $authMiddleware; |
|
| 40 | - $this->core = $core; |
|
| 41 | - $this->arr = $arr; |
|
| 42 | - } |
|
| 22 | + /** |
|
| 23 | + * Init new object. |
|
| 24 | + * |
|
| 25 | + * @param Route $route |
|
| 26 | + * @param Auth $auth |
|
| 27 | + * @param ErrorHandler $errorHandler |
|
| 28 | + * @param AuthMiddleware $authMiddleware |
|
| 29 | + * @param Core $core |
|
| 30 | + * @param Arr $arr |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public function __construct(Route $route, Auth $auth, ErrorHandler $errorHandler, AuthMiddleware $authMiddleware, Core $core, Arr $arr) |
|
| 35 | + { |
|
| 36 | + $this->route = $route; |
|
| 37 | + $this->auth = $auth; |
|
| 38 | + $this->errorHandler = $errorHandler; |
|
| 39 | + $this->authMiddleware = $authMiddleware; |
|
| 40 | + $this->core = $core; |
|
| 41 | + $this->arr = $arr; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Handle an incoming request. |
|
| 46 | - * |
|
| 47 | - * @param \Illuminate\Http\Request $request |
|
| 48 | - * @param \Closure $next |
|
| 49 | - * @return mixed |
|
| 50 | - */ |
|
| 51 | - public function handle($request, Closure $next) |
|
| 52 | - { |
|
| 53 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 54 | - $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 55 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 56 | - $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 57 | - $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 58 | - $modelName = explode('\\', $routeActions[0]); |
|
| 59 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 60 | - $permission = $routeActions[1]; |
|
| 44 | + /** |
|
| 45 | + * Handle an incoming request. |
|
| 46 | + * |
|
| 47 | + * @param \Illuminate\Http\Request $request |
|
| 48 | + * @param \Closure $next |
|
| 49 | + * @return mixed |
|
| 50 | + */ |
|
| 51 | + public function handle($request, Closure $next) |
|
| 52 | + { |
|
| 53 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 54 | + $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 55 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 56 | + $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 57 | + $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 58 | + $modelName = explode('\\', $routeActions[0]); |
|
| 59 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 60 | + $permission = $routeActions[1]; |
|
| 61 | 61 | |
| 62 | - $this->auth->shouldUse('api'); |
|
| 63 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 64 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 65 | - $user = $this->auth->user(); |
|
| 66 | - $isPasswordClient = $user->token()->client->password_client; |
|
| 62 | + $this->auth->shouldUse('api'); |
|
| 63 | + if (! in_array($permission, $skipLoginCheck)) { |
|
| 64 | + $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 65 | + $user = $this->auth->user(); |
|
| 66 | + $isPasswordClient = $user->token()->client->password_client; |
|
| 67 | 67 | |
| 68 | - if ($user->blocked) { |
|
| 69 | - $this->errorHandler->userIsBlocked(); |
|
| 70 | - } |
|
| 68 | + if ($user->blocked) { |
|
| 69 | + $this->errorHandler->userIsBlocked(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->core->users()->can($permission, $modelName))) { |
|
| 73 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 74 | - } else { |
|
| 75 | - $this->errorHandler->noPermissions(); |
|
| 76 | - } |
|
| 77 | - }); |
|
| 78 | - } |
|
| 72 | + if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->core->users()->can($permission, $modelName))) { |
|
| 73 | + } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 74 | + } else { |
|
| 75 | + $this->errorHandler->noPermissions(); |
|
| 76 | + } |
|
| 77 | + }); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $next($request); |
|
| 80 | + return $next($request); |
|
| 81 | 81 | |
| 82 | - //$this->middleware('auth:api', ['except' => $skipLoginCheck]); |
|
| 83 | - } |
|
| 82 | + //$this->middleware('auth:api', ['except' => $skipLoginCheck]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $permission = $routeActions[1]; |
| 61 | 61 | |
| 62 | 62 | $this->auth->shouldUse('api'); |
| 63 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 64 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 63 | + if ( ! in_array($permission, $skipLoginCheck)) { |
|
| 64 | + $this->authMiddleware->handle($request, function($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 65 | 65 | $user = $this->auth->user(); |
| 66 | 66 | $isPasswordClient = $user->token()->client->password_client; |
| 67 | 67 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->core->users()->can($permission, $modelName))) { |
| 73 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 73 | + } elseif ( ! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 74 | 74 | } else { |
| 75 | 75 | $this->errorHandler->noPermissions(); |
| 76 | 76 | } |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | |
| 10 | 10 | class SetRelations |
| 11 | 11 | { |
| 12 | - protected $arr; |
|
| 13 | - protected $route; |
|
| 14 | - protected $config; |
|
| 12 | + protected $arr; |
|
| 13 | + protected $route; |
|
| 14 | + protected $config; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Init new object. |
|
| 18 | - * |
|
| 19 | - * @param Route $route |
|
| 20 | - * @param Arr $arr |
|
| 21 | - * @param Config $config |
|
| 22 | - * |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function __construct(Route $route, Arr $arr, Config $config) |
|
| 26 | - { |
|
| 27 | - $this->arr = $arr; |
|
| 28 | - $this->route = $route; |
|
| 29 | - $this->config = $config->getConfig(); |
|
| 30 | - } |
|
| 16 | + /** |
|
| 17 | + * Init new object. |
|
| 18 | + * |
|
| 19 | + * @param Route $route |
|
| 20 | + * @param Arr $arr |
|
| 21 | + * @param Config $config |
|
| 22 | + * |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function __construct(Route $route, Arr $arr, Config $config) |
|
| 26 | + { |
|
| 27 | + $this->arr = $arr; |
|
| 28 | + $this->route = $route; |
|
| 29 | + $this->config = $config->getConfig(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Handle an incoming request. |
|
| 34 | - * |
|
| 35 | - * @param \Illuminate\Http\Request $request |
|
| 36 | - * @param \Closure $next |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function handle($request, Closure $next) |
|
| 40 | - { |
|
| 41 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 42 | - $modelName = explode('\\', $routeActions[0]); |
|
| 43 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 44 | - $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 45 | - $route = $route !== 'index' ? $route : 'list'; |
|
| 46 | - $relations = $this->arr->get($this->config['relations'], $modelName, false); |
|
| 47 | - $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 32 | + /** |
|
| 33 | + * Handle an incoming request. |
|
| 34 | + * |
|
| 35 | + * @param \Illuminate\Http\Request $request |
|
| 36 | + * @param \Closure $next |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function handle($request, Closure $next) |
|
| 40 | + { |
|
| 41 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 42 | + $modelName = explode('\\', $routeActions[0]); |
|
| 43 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 44 | + $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 45 | + $route = $route !== 'index' ? $route : 'list'; |
|
| 46 | + $relations = $this->arr->get($this->config['relations'], $modelName, false); |
|
| 47 | + $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 48 | 48 | |
| 49 | - return $next($request); |
|
| 50 | - } |
|
| 49 | + return $next($request); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -5,81 +5,81 @@ |
||
| 5 | 5 | |
| 6 | 6 | class ApiDocumentController extends Controller |
| 7 | 7 | { |
| 8 | - public function index() |
|
| 9 | - { |
|
| 10 | - $jsonDoc = json_decode(file_get_contents(app_path('Modules/Core/Resources/api.json')), true); |
|
| 11 | - $modules = $jsonDoc['modules']; |
|
| 12 | - $reports = $jsonDoc['reports']; |
|
| 13 | - $errors = $jsonDoc['errors']; |
|
| 14 | - $models = $jsonDoc['models']; |
|
| 15 | - $conditions = [ |
|
| 16 | - [ |
|
| 17 | - 'title' => 'email equal [email protected]:', |
|
| 18 | - 'content' => ['email' => '[email protected]'] |
|
| 19 | - ], |
|
| 20 | - [ |
|
| 21 | - 'title' => 'email equal [email protected] and user is blocked:', |
|
| 22 | - 'content' => ['and' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 23 | - ], |
|
| 24 | - [ |
|
| 25 | - 'title' => 'email equal [email protected] or user is blocked:', |
|
| 26 | - 'content' => ['or' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 27 | - ], |
|
| 28 | - [ |
|
| 29 | - 'title' => 'email contain John:', |
|
| 30 | - 'content' => ['email' => ['op' => 'like', 'val' => '%John%']] |
|
| 31 | - ], |
|
| 32 | - [ |
|
| 33 | - 'title' => 'user created after 2016-10-25:', |
|
| 34 | - 'content' => ['created_at' => ['op' => '>', 'val' => '2016-10-25']] |
|
| 35 | - ], |
|
| 36 | - [ |
|
| 37 | - 'title' => 'user created between 2016-10-20 and 2016-10-25:', |
|
| 38 | - 'content' => ['created_at' => ['op' => 'between', 'val1' => '2016-10-20', 'val2' => '2016-10-25']] |
|
| 39 | - ], |
|
| 40 | - [ |
|
| 41 | - 'title' => 'user id in 1,2,3:', |
|
| 42 | - 'content' => ['id' => ['op' => 'in', 'val' => [1, 2, 3]]] |
|
| 43 | - ], |
|
| 44 | - [ |
|
| 45 | - 'title' => 'user name is null:', |
|
| 46 | - 'content' => ['name' => ['op' => 'null']] |
|
| 47 | - ], |
|
| 48 | - [ |
|
| 49 | - 'title' => 'user name is not null:', |
|
| 50 | - 'content' => ['name' => ['op' => 'not null']] |
|
| 51 | - ], |
|
| 52 | - [ |
|
| 53 | - 'title' => 'user has group admin:', |
|
| 54 | - 'content' => ['groups' => ['op' => 'has', 'val' => ['name' => 'Admin']]] |
|
| 55 | - ] |
|
| 56 | - ]; |
|
| 8 | + public function index() |
|
| 9 | + { |
|
| 10 | + $jsonDoc = json_decode(file_get_contents(app_path('Modules/Core/Resources/api.json')), true); |
|
| 11 | + $modules = $jsonDoc['modules']; |
|
| 12 | + $reports = $jsonDoc['reports']; |
|
| 13 | + $errors = $jsonDoc['errors']; |
|
| 14 | + $models = $jsonDoc['models']; |
|
| 15 | + $conditions = [ |
|
| 16 | + [ |
|
| 17 | + 'title' => 'email equal [email protected]:', |
|
| 18 | + 'content' => ['email' => '[email protected]'] |
|
| 19 | + ], |
|
| 20 | + [ |
|
| 21 | + 'title' => 'email equal [email protected] and user is blocked:', |
|
| 22 | + 'content' => ['and' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 23 | + ], |
|
| 24 | + [ |
|
| 25 | + 'title' => 'email equal [email protected] or user is blocked:', |
|
| 26 | + 'content' => ['or' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 27 | + ], |
|
| 28 | + [ |
|
| 29 | + 'title' => 'email contain John:', |
|
| 30 | + 'content' => ['email' => ['op' => 'like', 'val' => '%John%']] |
|
| 31 | + ], |
|
| 32 | + [ |
|
| 33 | + 'title' => 'user created after 2016-10-25:', |
|
| 34 | + 'content' => ['created_at' => ['op' => '>', 'val' => '2016-10-25']] |
|
| 35 | + ], |
|
| 36 | + [ |
|
| 37 | + 'title' => 'user created between 2016-10-20 and 2016-10-25:', |
|
| 38 | + 'content' => ['created_at' => ['op' => 'between', 'val1' => '2016-10-20', 'val2' => '2016-10-25']] |
|
| 39 | + ], |
|
| 40 | + [ |
|
| 41 | + 'title' => 'user id in 1,2,3:', |
|
| 42 | + 'content' => ['id' => ['op' => 'in', 'val' => [1, 2, 3]]] |
|
| 43 | + ], |
|
| 44 | + [ |
|
| 45 | + 'title' => 'user name is null:', |
|
| 46 | + 'content' => ['name' => ['op' => 'null']] |
|
| 47 | + ], |
|
| 48 | + [ |
|
| 49 | + 'title' => 'user name is not null:', |
|
| 50 | + 'content' => ['name' => ['op' => 'not null']] |
|
| 51 | + ], |
|
| 52 | + [ |
|
| 53 | + 'title' => 'user has group admin:', |
|
| 54 | + 'content' => ['groups' => ['op' => 'has', 'val' => ['name' => 'Admin']]] |
|
| 55 | + ] |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - $paginateObject = [ |
|
| 59 | - 'data' => ['Array of model objects'], |
|
| 60 | - "links" => [ |
|
| 61 | - "first" => "apiUrl?page=1", |
|
| 62 | - "last" => "apiUrl?page=3", |
|
| 63 | - "prev" => "apiUrl?page=2", |
|
| 64 | - "next" => "apiUrl?page=3" |
|
| 65 | - ], |
|
| 66 | - "meta" => [ |
|
| 67 | - "current_page" => 2, |
|
| 68 | - "from" => 6, |
|
| 69 | - "last_page" => 3, |
|
| 70 | - "path" => "apiUrl", |
|
| 71 | - "per_page" => 5, |
|
| 72 | - "to" => 10, |
|
| 73 | - "total" => 15 |
|
| 74 | - ] |
|
| 75 | - ]; |
|
| 58 | + $paginateObject = [ |
|
| 59 | + 'data' => ['Array of model objects'], |
|
| 60 | + "links" => [ |
|
| 61 | + "first" => "apiUrl?page=1", |
|
| 62 | + "last" => "apiUrl?page=3", |
|
| 63 | + "prev" => "apiUrl?page=2", |
|
| 64 | + "next" => "apiUrl?page=3" |
|
| 65 | + ], |
|
| 66 | + "meta" => [ |
|
| 67 | + "current_page" => 2, |
|
| 68 | + "from" => 6, |
|
| 69 | + "last_page" => 3, |
|
| 70 | + "path" => "apiUrl", |
|
| 71 | + "per_page" => 5, |
|
| 72 | + "to" => 10, |
|
| 73 | + "total" => 15 |
|
| 74 | + ] |
|
| 75 | + ]; |
|
| 76 | 76 | |
| 77 | - $responseObject = [ |
|
| 78 | - 'data' => ['The model object'] |
|
| 79 | - ]; |
|
| 77 | + $responseObject = [ |
|
| 78 | + 'data' => ['The model object'] |
|
| 79 | + ]; |
|
| 80 | 80 | |
| 81 | - $avaialableReports = \Core::reports()->all(); |
|
| 81 | + $avaialableReports = \Core::reports()->all(); |
|
| 82 | 82 | |
| 83 | - return view('core::doc', ['modules' => $modules, 'reports' => $reports, 'errors' => $errors, 'conditions' => $conditions, 'models' => $models, 'paginateObject' => json_encode($paginateObject, JSON_PRETTY_PRINT), 'responseObject' => json_encode($responseObject, JSON_PRETTY_PRINT), 'avaialableReports' => $avaialableReports]); |
|
| 84 | - } |
|
| 83 | + return view('core::doc', ['modules' => $modules, 'reports' => $reports, 'errors' => $errors, 'conditions' => $conditions, 'models' => $models, 'paginateObject' => json_encode($paginateObject, JSON_PRETTY_PRINT), 'responseObject' => json_encode($responseObject, JSON_PRETTY_PRINT), 'avaialableReports' => $avaialableReports]); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -9,93 +9,93 @@ |
||
| 9 | 9 | |
| 10 | 10 | class BaseApiController extends Controller |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * The relations implementation. |
|
| 14 | - * |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $relations; |
|
| 12 | + /** |
|
| 13 | + * The relations implementation. |
|
| 14 | + * |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $relations; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The repo implementation. |
|
| 21 | - * |
|
| 22 | - * @var object |
|
| 23 | - */ |
|
| 24 | - protected $repo; |
|
| 19 | + /** |
|
| 20 | + * The repo implementation. |
|
| 21 | + * |
|
| 22 | + * @var object |
|
| 23 | + */ |
|
| 24 | + protected $repo; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The modelResource implementation. |
|
| 28 | - * |
|
| 29 | - * @var object |
|
| 30 | - */ |
|
| 31 | - protected $modelResource; |
|
| 26 | + /** |
|
| 27 | + * The modelResource implementation. |
|
| 28 | + * |
|
| 29 | + * @var object |
|
| 30 | + */ |
|
| 31 | + protected $modelResource; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Init new object. |
|
| 35 | - * |
|
| 36 | - * @param mixed $repo |
|
| 37 | - * @param string $modelResource |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function __construct($repo, $modelResource) |
|
| 41 | - { |
|
| 42 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 43 | - $this->modelResource = $modelResource; |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Init new object. |
|
| 35 | + * |
|
| 36 | + * @param mixed $repo |
|
| 37 | + * @param string $modelResource |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function __construct($repo, $modelResource) |
|
| 41 | + { |
|
| 42 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 43 | + $this->modelResource = $modelResource; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Fetch all records with relations from storage. |
|
| 48 | - * |
|
| 49 | - * @param Request $request |
|
| 50 | - * @return \Illuminate\Http\Response |
|
| 51 | - */ |
|
| 52 | - public function index(Request $request) |
|
| 53 | - { |
|
| 54 | - return $this->modelResource::collection($this->repo->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Fetch all records with relations from storage. |
|
| 48 | + * |
|
| 49 | + * @param Request $request |
|
| 50 | + * @return \Illuminate\Http\Response |
|
| 51 | + */ |
|
| 52 | + public function index(Request $request) |
|
| 53 | + { |
|
| 54 | + return $this->modelResource::collection($this->repo->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Fetch the single object with relations from storage. |
|
| 59 | - * |
|
| 60 | - * @param Request $request |
|
| 61 | - * @param integer $id Id of the requested model. |
|
| 62 | - * @return \Illuminate\Http\Response |
|
| 63 | - */ |
|
| 64 | - public function find(Request $request, $id) |
|
| 65 | - { |
|
| 66 | - return new $this->modelResource($this->repo->find($id, $request->relations)); |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * Fetch the single object with relations from storage. |
|
| 59 | + * |
|
| 60 | + * @param Request $request |
|
| 61 | + * @param integer $id Id of the requested model. |
|
| 62 | + * @return \Illuminate\Http\Response |
|
| 63 | + */ |
|
| 64 | + public function find(Request $request, $id) |
|
| 65 | + { |
|
| 66 | + return new $this->modelResource($this->repo->find($id, $request->relations)); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Delete by the given id from storage. |
|
| 71 | - * |
|
| 72 | - * @param integer $id Id of the deleted model. |
|
| 73 | - * @return \Illuminate\Http\Response |
|
| 74 | - */ |
|
| 75 | - public function delete($id) |
|
| 76 | - { |
|
| 77 | - return new GeneralResource($this->repo->delete($id)); |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * Delete by the given id from storage. |
|
| 71 | + * |
|
| 72 | + * @param integer $id Id of the deleted model. |
|
| 73 | + * @return \Illuminate\Http\Response |
|
| 74 | + */ |
|
| 75 | + public function delete($id) |
|
| 76 | + { |
|
| 77 | + return new GeneralResource($this->repo->delete($id)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Return the deleted models in pages based on the given conditions. |
|
| 82 | - * |
|
| 83 | - * @param Request $request |
|
| 84 | - * @return \Illuminate\Http\Response |
|
| 85 | - */ |
|
| 86 | - public function deleted(Request $request) |
|
| 87 | - { |
|
| 88 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * Return the deleted models in pages based on the given conditions. |
|
| 82 | + * |
|
| 83 | + * @param Request $request |
|
| 84 | + * @return \Illuminate\Http\Response |
|
| 85 | + */ |
|
| 86 | + public function deleted(Request $request) |
|
| 87 | + { |
|
| 88 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Restore the deleted model. |
|
| 93 | - * |
|
| 94 | - * @param integer $id Id of the restored model. |
|
| 95 | - * @return \Illuminate\Http\Response |
|
| 96 | - */ |
|
| 97 | - public function restore($id) |
|
| 98 | - { |
|
| 99 | - return new GeneralResource($this->repo->restore($id)); |
|
| 100 | - } |
|
| 91 | + /** |
|
| 92 | + * Restore the deleted model. |
|
| 93 | + * |
|
| 94 | + * @param integer $id Id of the restored model. |
|
| 95 | + * @return \Illuminate\Http\Response |
|
| 96 | + */ |
|
| 97 | + public function restore($id) |
|
| 98 | + { |
|
| 99 | + return new GeneralResource($this->repo->restore($id)); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -13,7 +13,7 @@ |
||
| 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('get/{reportName}', 'ReportController@getReport'); |
|
| 16 | + Route::get('/', 'ReportController@index'); |
|
| 17 | + Route::get('/{id}', 'ReportController@find'); |
|
| 18 | + Route::post('get/{reportName}', 'ReportController@getReport'); |
|
| 19 | 19 | }); |