@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class UpdateDummy extends FormRequest |
8 | 8 | { |
9 | - /** |
|
10 | - * Determine if the user is authorized to make this request. |
|
11 | - * |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function authorize() |
|
15 | - { |
|
16 | - return true; |
|
17 | - } |
|
9 | + /** |
|
10 | + * Determine if the user is authorized to make this request. |
|
11 | + * |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function authorize() |
|
15 | + { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Get the validation rules that apply to the request. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function rules() |
|
25 | - { |
|
26 | - return [ |
|
27 | - // |
|
28 | - ]; |
|
29 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + // |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class InsertDummy extends FormRequest |
8 | 8 | { |
9 | - /** |
|
10 | - * Determine if the user is authorized to make this request. |
|
11 | - * |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function authorize() |
|
15 | - { |
|
16 | - return true; |
|
17 | - } |
|
9 | + /** |
|
10 | + * Determine if the user is authorized to make this request. |
|
11 | + * |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function authorize() |
|
15 | + { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Get the validation rules that apply to the request. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function rules() |
|
25 | - { |
|
26 | - return [ |
|
27 | - // |
|
28 | - ]; |
|
29 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + // |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | } |
@@ -5,14 +5,14 @@ |
||
5 | 5 | |
6 | 6 | class DummyRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param DummyModel $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(DummyModel $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param DummyModel $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(DummyModel $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | } |
@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class NotificationsDatabaseSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $this->call(ClearDataSeeder::class); |
|
17 | - $this->call(NotificationsTableSeeder::class); |
|
18 | - $this->call(AssignRelationsSeeder::class); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $this->call(ClearDataSeeder::class); |
|
17 | + $this->call(NotificationsTableSeeder::class); |
|
18 | + $this->call(AssignRelationsSeeder::class); |
|
19 | + } |
|
20 | 20 | } |
@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class RolesDatabaseSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $this->call(ClearDataSeeder::class); |
|
17 | - $this->call(RolesTableSeeder::class); |
|
18 | - $this->call(AssignRelationsSeeder::class); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $this->call(ClearDataSeeder::class); |
|
17 | + $this->call(RolesTableSeeder::class); |
|
18 | + $this->call(AssignRelationsSeeder::class); |
|
19 | + } |
|
20 | 20 | } |
@@ -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', 'roles'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'roles'); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'roles'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'roles'); |
|
18 | 18 | |
19 | - $this->loadMigrationsFrom(module_path('roles', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('roles', 'Database/Factories', 'app')); |
|
21 | - } |
|
19 | + $this->loadMigrationsFrom(module_path('roles', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('roles', '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 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | class RouteServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | - /** |
|
11 | - * This namespace is applied to your controller routes. |
|
12 | - * |
|
13 | - * In addition, it is set as the URL generator's root namespace. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $namespace = 'App\Modules\Roles\Http\Controllers'; |
|
10 | + /** |
|
11 | + * This namespace is applied to your controller routes. |
|
12 | + * |
|
13 | + * In addition, it is set as the URL generator's root namespace. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $namespace = 'App\Modules\Roles\Http\Controllers'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Define your route model bindings, pattern filters, etc. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - // |
|
19 | + /** |
|
20 | + * Define your route model bindings, pattern filters, etc. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + // |
|
27 | 27 | |
28 | - parent::boot(); |
|
29 | - } |
|
28 | + parent::boot(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Define the routes for the module. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function map() |
|
37 | - { |
|
38 | - $this->mapWebRoutes(); |
|
31 | + /** |
|
32 | + * Define the routes for the module. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function map() |
|
37 | + { |
|
38 | + $this->mapWebRoutes(); |
|
39 | 39 | |
40 | - $this->mapApiRoutes(); |
|
40 | + $this->mapApiRoutes(); |
|
41 | 41 | |
42 | - // |
|
43 | - } |
|
42 | + // |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Define the "web" routes for the module. |
|
47 | - * |
|
48 | - * These routes all receive session state, CSRF protection, etc. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function mapWebRoutes() |
|
53 | - { |
|
54 | - Route::group([ |
|
55 | - 'middleware' => 'web', |
|
56 | - 'namespace' => $this->namespace, |
|
57 | - ], function ($router) { |
|
58 | - require module_path('roles', 'Routes/web.php', 'app'); |
|
59 | - }); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Define the "web" routes for the module. |
|
47 | + * |
|
48 | + * These routes all receive session state, CSRF protection, etc. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function mapWebRoutes() |
|
53 | + { |
|
54 | + Route::group([ |
|
55 | + 'middleware' => 'web', |
|
56 | + 'namespace' => $this->namespace, |
|
57 | + ], function ($router) { |
|
58 | + require module_path('roles', 'Routes/web.php', 'app'); |
|
59 | + }); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the "api" routes for the module. |
|
64 | - * |
|
65 | - * These routes are typically stateless. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function mapApiRoutes() |
|
70 | - { |
|
71 | - Route::group([ |
|
72 | - 'middleware' => 'api', |
|
73 | - 'namespace' => $this->namespace, |
|
74 | - 'prefix' => 'api', |
|
75 | - ], function ($router) { |
|
76 | - require module_path('roles', 'Routes/api.php', 'app'); |
|
77 | - }); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Define the "api" routes for the module. |
|
64 | + * |
|
65 | + * These routes are typically stateless. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function mapApiRoutes() |
|
70 | + { |
|
71 | + Route::group([ |
|
72 | + 'middleware' => 'api', |
|
73 | + 'namespace' => $this->namespace, |
|
74 | + 'prefix' => 'api', |
|
75 | + ], function ($router) { |
|
76 | + require module_path('roles', 'Routes/api.php', 'app'); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | Route::group([ |
55 | 55 | 'middleware' => 'web', |
56 | 56 | 'namespace' => $this->namespace, |
57 | - ], function ($router) { |
|
57 | + ], function($router) { |
|
58 | 58 | require module_path('roles', 'Routes/web.php', 'app'); |
59 | 59 | }); |
60 | 60 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'middleware' => 'api', |
73 | 73 | 'namespace' => $this->namespace, |
74 | 74 | 'prefix' => 'api', |
75 | - ], function ($router) { |
|
75 | + ], function($router) { |
|
76 | 76 | require module_path('roles', 'Routes/api.php', 'app'); |
77 | 77 | }); |
78 | 78 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public function toArray($request) |
19 | 19 | { |
20 | - if (! $this->resource) { |
|
20 | + if ( ! $this->resource) { |
|
21 | 21 | return []; |
22 | 22 | } |
23 | 23 |
@@ -8,25 +8,25 @@ |
||
8 | 8 | |
9 | 9 | class Role extends JsonResource |
10 | 10 | { |
11 | - /** |
|
12 | - * Transform the resource into an array. |
|
13 | - * |
|
14 | - * @param Request $request |
|
15 | - * @return array |
|
16 | - */ |
|
17 | - public function toArray($request) |
|
18 | - { |
|
19 | - if (! $this->resource) { |
|
20 | - return []; |
|
21 | - } |
|
11 | + /** |
|
12 | + * Transform the resource into an array. |
|
13 | + * |
|
14 | + * @param Request $request |
|
15 | + * @return array |
|
16 | + */ |
|
17 | + public function toArray($request) |
|
18 | + { |
|
19 | + if (! $this->resource) { |
|
20 | + return []; |
|
21 | + } |
|
22 | 22 | |
23 | - return [ |
|
24 | - 'id' => $this->id, |
|
25 | - 'name' => $this->name, |
|
26 | - 'users' => UserResource::collection($this->whenLoaded('users')), |
|
27 | - 'permissions' => PermissionResource::collection($this->whenLoaded('permissions')), |
|
28 | - 'created_at' => $this->created_at, |
|
29 | - 'updated_at' => $this->updated_at, |
|
30 | - ]; |
|
31 | - } |
|
23 | + return [ |
|
24 | + 'id' => $this->id, |
|
25 | + 'name' => $this->name, |
|
26 | + 'users' => UserResource::collection($this->whenLoaded('users')), |
|
27 | + 'permissions' => PermissionResource::collection($this->whenLoaded('permissions')), |
|
28 | + 'created_at' => $this->created_at, |
|
29 | + 'updated_at' => $this->updated_at, |
|
30 | + ]; |
|
31 | + } |
|
32 | 32 | } |
@@ -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) |
@@ -8,280 +8,280 @@ |
||
8 | 8 | |
9 | 9 | class GenerateDoc extends Command |
10 | 10 | { |
11 | - /** |
|
12 | - * The name and signature of the console command. |
|
13 | - * |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $signature = 'doc:generate'; |
|
17 | - |
|
18 | - /** |
|
19 | - * The console command description. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $description = 'Generate api documentation'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var ReprotService |
|
27 | - */ |
|
28 | - protected $reportService; |
|
29 | - |
|
30 | - /** |
|
31 | - * Init new object. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function __construct(ReportService $reportService) |
|
36 | - { |
|
37 | - $this->reportService = $reportService; |
|
38 | - parent::__construct(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Execute the console command. |
|
43 | - * |
|
44 | - * @return mixed |
|
45 | - */ |
|
46 | - public function handle() |
|
47 | - { |
|
48 | - $docData = []; |
|
49 | - $docData['models'] = []; |
|
50 | - $routes = $this->getRoutes(); |
|
51 | - foreach ($routes as $route) { |
|
52 | - if ($route) { |
|
53 | - $actoinArray = explode('@', $route['action']); |
|
54 | - if (Arr::get($actoinArray, 1, false)) { |
|
55 | - |
|
56 | - $prefix = $route['prefix']; |
|
57 | - $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $prefix))); |
|
58 | - if($prefix === 'telescope') { |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - $controller = $actoinArray[0]; |
|
63 | - $method = $actoinArray[1]; |
|
64 | - $route['name'] = $method !== 'index' ? $method : 'list'; |
|
11 | + /** |
|
12 | + * The name and signature of the console command. |
|
13 | + * |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $signature = 'doc:generate'; |
|
17 | + |
|
18 | + /** |
|
19 | + * The console command description. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $description = 'Generate api documentation'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var ReprotService |
|
27 | + */ |
|
28 | + protected $reportService; |
|
29 | + |
|
30 | + /** |
|
31 | + * Init new object. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function __construct(ReportService $reportService) |
|
36 | + { |
|
37 | + $this->reportService = $reportService; |
|
38 | + parent::__construct(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Execute the console command. |
|
43 | + * |
|
44 | + * @return mixed |
|
45 | + */ |
|
46 | + public function handle() |
|
47 | + { |
|
48 | + $docData = []; |
|
49 | + $docData['models'] = []; |
|
50 | + $routes = $this->getRoutes(); |
|
51 | + foreach ($routes as $route) { |
|
52 | + if ($route) { |
|
53 | + $actoinArray = explode('@', $route['action']); |
|
54 | + if (Arr::get($actoinArray, 1, false)) { |
|
55 | + |
|
56 | + $prefix = $route['prefix']; |
|
57 | + $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $prefix))); |
|
58 | + if($prefix === 'telescope') { |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + $controller = $actoinArray[0]; |
|
63 | + $method = $actoinArray[1]; |
|
64 | + $route['name'] = $method !== 'index' ? $method : 'list'; |
|
65 | 65 | |
66 | - $reflectionClass = new \ReflectionClass($controller); |
|
67 | - $reflectionMethod = $reflectionClass->getMethod($method); |
|
68 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
69 | - $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
70 | - $modelName = explode('\\', $controller); |
|
71 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
72 | - |
|
73 | - $this->processDocBlock($route, $reflectionMethod); |
|
74 | - $this->getHeaders($route, $method, $skipLoginCheck); |
|
75 | - $this->getPostData($route, $reflectionMethod); |
|
76 | - |
|
77 | - $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
78 | - $docData['modules'][$module][] = $route; |
|
79 | - |
|
80 | - $this->getModels($modelName, $docData, $reflectionClass); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
66 | + $reflectionClass = new \ReflectionClass($controller); |
|
67 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
68 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
69 | + $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
70 | + $modelName = explode('\\', $controller); |
|
71 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
72 | + |
|
73 | + $this->processDocBlock($route, $reflectionMethod); |
|
74 | + $this->getHeaders($route, $method, $skipLoginCheck); |
|
75 | + $this->getPostData($route, $reflectionMethod); |
|
76 | + |
|
77 | + $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
78 | + $docData['modules'][$module][] = $route; |
|
79 | + |
|
80 | + $this->getModels($modelName, $docData, $reflectionClass); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - $docData['errors'] = $this->getErrors(); |
|
86 | - $docData['reports'] = $this->reportService->all(); |
|
87 | - \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get list of all registered routes. |
|
92 | - * |
|
93 | - * @return collection |
|
94 | - */ |
|
95 | - protected function getRoutes() |
|
96 | - { |
|
97 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
98 | - if (strpos($route->uri(), 'api/') !== false) { |
|
99 | - return [ |
|
100 | - 'method' => $route->methods()[0], |
|
101 | - 'uri' => $route->uri(), |
|
102 | - 'action' => $route->getActionName(), |
|
103 | - 'prefix' => $route->getPrefix() |
|
104 | - ]; |
|
105 | - } |
|
106 | - return false; |
|
107 | - })->all(); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Generate headers for the given route. |
|
112 | - * |
|
113 | - * @param array &$route |
|
114 | - * @param string $method |
|
115 | - * @param array $skipLoginCheck |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
119 | - { |
|
120 | - $route['headers'] = [ |
|
121 | - 'Accept' => 'application/json', |
|
122 | - 'Content-Type' => 'application/json', |
|
123 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
124 | - 'time-zone' => 'Your locale time zone', |
|
125 | - ]; |
|
126 | - |
|
127 | - |
|
128 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
129 | - $route['headers']['Authorization'] = 'Bearer {token}'; |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Generate description and params for the given route |
|
135 | - * based on the docblock. |
|
136 | - * |
|
137 | - * @param array &$route |
|
138 | - * @param \ReflectionMethod $reflectionMethod |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
142 | - { |
|
143 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
144 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
145 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
146 | - $params = $docblock->getTagsByName('param'); |
|
147 | - $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
148 | - |
|
149 | - foreach ($params as $param) { |
|
150 | - $name = $param->getVariableName(); |
|
151 | - if ($name !== 'request') { |
|
152 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - if ($route['name'] === 'list') { |
|
157 | - $route['parametars']['perPage'] = 'perPage?'; |
|
158 | - $route['parametars']['sortBy'] = 'sortBy?'; |
|
159 | - $route['parametars']['desc'] = 'desc?'; |
|
160 | - $route['parametars']['trashed'] = 'trashed?'; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Generate post body for the given route. |
|
166 | - * |
|
167 | - * @param array &$route |
|
168 | - * @param \ReflectionMethod $reflectionMethod |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - protected function getPostData(&$route, $reflectionMethod) |
|
172 | - { |
|
173 | - $parameters = $reflectionMethod->getParameters(); |
|
174 | - if (count($parameters)) { |
|
175 | - $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
176 | - if ($className) { |
|
177 | - $reflectionClass = new \ReflectionClass($className); |
|
85 | + $docData['errors'] = $this->getErrors(); |
|
86 | + $docData['reports'] = $this->reportService->all(); |
|
87 | + \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get list of all registered routes. |
|
92 | + * |
|
93 | + * @return collection |
|
94 | + */ |
|
95 | + protected function getRoutes() |
|
96 | + { |
|
97 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
98 | + if (strpos($route->uri(), 'api/') !== false) { |
|
99 | + return [ |
|
100 | + 'method' => $route->methods()[0], |
|
101 | + 'uri' => $route->uri(), |
|
102 | + 'action' => $route->getActionName(), |
|
103 | + 'prefix' => $route->getPrefix() |
|
104 | + ]; |
|
105 | + } |
|
106 | + return false; |
|
107 | + })->all(); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Generate headers for the given route. |
|
112 | + * |
|
113 | + * @param array &$route |
|
114 | + * @param string $method |
|
115 | + * @param array $skipLoginCheck |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
119 | + { |
|
120 | + $route['headers'] = [ |
|
121 | + 'Accept' => 'application/json', |
|
122 | + 'Content-Type' => 'application/json', |
|
123 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
124 | + 'time-zone' => 'Your locale time zone', |
|
125 | + ]; |
|
126 | + |
|
127 | + |
|
128 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
129 | + $route['headers']['Authorization'] = 'Bearer {token}'; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Generate description and params for the given route |
|
135 | + * based on the docblock. |
|
136 | + * |
|
137 | + * @param array &$route |
|
138 | + * @param \ReflectionMethod $reflectionMethod |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
142 | + { |
|
143 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
144 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
145 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
146 | + $params = $docblock->getTagsByName('param'); |
|
147 | + $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
148 | + |
|
149 | + foreach ($params as $param) { |
|
150 | + $name = $param->getVariableName(); |
|
151 | + if ($name !== 'request') { |
|
152 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + if ($route['name'] === 'list') { |
|
157 | + $route['parametars']['perPage'] = 'perPage?'; |
|
158 | + $route['parametars']['sortBy'] = 'sortBy?'; |
|
159 | + $route['parametars']['desc'] = 'desc?'; |
|
160 | + $route['parametars']['trashed'] = 'trashed?'; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Generate post body for the given route. |
|
166 | + * |
|
167 | + * @param array &$route |
|
168 | + * @param \ReflectionMethod $reflectionMethod |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + protected function getPostData(&$route, $reflectionMethod) |
|
172 | + { |
|
173 | + $parameters = $reflectionMethod->getParameters(); |
|
174 | + if (count($parameters)) { |
|
175 | + $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
176 | + if ($className) { |
|
177 | + $reflectionClass = new \ReflectionClass($className); |
|
178 | 178 | |
179 | - if ($reflectionClass->hasMethod('rules')) { |
|
180 | - $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
181 | - $route['body'] = $reflectionMethod->invoke(new $className); |
|
179 | + if ($reflectionClass->hasMethod('rules')) { |
|
180 | + $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
181 | + $route['body'] = $reflectionMethod->invoke(new $className); |
|
182 | 182 | |
183 | - foreach ($route['body'] as &$rule) { |
|
184 | - if (strpos($rule, 'unique')) { |
|
185 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
186 | - } elseif (strpos($rule, 'exists')) { |
|
187 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Generate application errors. |
|
197 | - * |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - protected function getErrors() |
|
201 | - { |
|
202 | - $errors = []; |
|
203 | - foreach (\Module::all() as $module) { |
|
204 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
205 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
206 | - $reflectionClass = new \ReflectionClass($class); |
|
207 | - foreach ($reflectionClass->getMethods() as $method) { |
|
208 | - $methodName = $method->name; |
|
209 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
210 | - $body = $this->getMethodBody($reflectionMethod); |
|
211 | - |
|
212 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
213 | - |
|
214 | - if (count($match)) { |
|
215 | - $errors[$match[1]][] = $methodName; |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - return $errors; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get the given method body code. |
|
225 | - * |
|
226 | - * @param object $reflectionMethod |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - protected function getMethodBody($reflectionMethod) |
|
230 | - { |
|
231 | - $filename = $reflectionMethod->getFileName(); |
|
232 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
233 | - $end_line = $reflectionMethod->getEndLine(); |
|
234 | - $length = $end_line - $start_line; |
|
235 | - $source = file($filename); |
|
236 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
237 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
238 | - |
|
239 | - return $body; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Get example object of all availble models. |
|
244 | - * |
|
245 | - * @param string $modelName |
|
246 | - * @param array $docData |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - protected function getModels($modelName, &$docData, $reflectionClass) |
|
250 | - { |
|
251 | - if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
252 | - $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
253 | - $model = factory($modelClass)->make(); |
|
254 | - |
|
255 | - $property = $reflectionClass->getProperty('modelResource'); |
|
256 | - $property->setAccessible(true); |
|
257 | - $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
258 | - $modelResource = new $modelResource($model); |
|
259 | - $modelArr = $modelResource->toArray([]); |
|
260 | - |
|
261 | - foreach ($modelArr as $key => $attr) { |
|
262 | - if (is_object($attr) && property_exists($attr, 'resource') && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
263 | - unset($modelArr[$key]); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Get the route response object type. |
|
273 | - * |
|
274 | - * @param string $modelName |
|
275 | - * @param string $method |
|
276 | - * @param string $returnDocBlock |
|
277 | - * @return array |
|
278 | - */ |
|
279 | - protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
280 | - { |
|
281 | - $config = \CoreConfig::getConfig(); |
|
282 | - $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
283 | - $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
284 | - |
|
285 | - return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
286 | - } |
|
183 | + foreach ($route['body'] as &$rule) { |
|
184 | + if (strpos($rule, 'unique')) { |
|
185 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
186 | + } elseif (strpos($rule, 'exists')) { |
|
187 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Generate application errors. |
|
197 | + * |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + protected function getErrors() |
|
201 | + { |
|
202 | + $errors = []; |
|
203 | + foreach (\Module::all() as $module) { |
|
204 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
205 | + $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
206 | + $reflectionClass = new \ReflectionClass($class); |
|
207 | + foreach ($reflectionClass->getMethods() as $method) { |
|
208 | + $methodName = $method->name; |
|
209 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
210 | + $body = $this->getMethodBody($reflectionMethod); |
|
211 | + |
|
212 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
213 | + |
|
214 | + if (count($match)) { |
|
215 | + $errors[$match[1]][] = $methodName; |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + return $errors; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get the given method body code. |
|
225 | + * |
|
226 | + * @param object $reflectionMethod |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + protected function getMethodBody($reflectionMethod) |
|
230 | + { |
|
231 | + $filename = $reflectionMethod->getFileName(); |
|
232 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
233 | + $end_line = $reflectionMethod->getEndLine(); |
|
234 | + $length = $end_line - $start_line; |
|
235 | + $source = file($filename); |
|
236 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
237 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
238 | + |
|
239 | + return $body; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Get example object of all availble models. |
|
244 | + * |
|
245 | + * @param string $modelName |
|
246 | + * @param array $docData |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + protected function getModels($modelName, &$docData, $reflectionClass) |
|
250 | + { |
|
251 | + if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
252 | + $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
253 | + $model = factory($modelClass)->make(); |
|
254 | + |
|
255 | + $property = $reflectionClass->getProperty('modelResource'); |
|
256 | + $property->setAccessible(true); |
|
257 | + $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
258 | + $modelResource = new $modelResource($model); |
|
259 | + $modelArr = $modelResource->toArray([]); |
|
260 | + |
|
261 | + foreach ($modelArr as $key => $attr) { |
|
262 | + if (is_object($attr) && property_exists($attr, 'resource') && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
263 | + unset($modelArr[$key]); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Get the route response object type. |
|
273 | + * |
|
274 | + * @param string $modelName |
|
275 | + * @param string $method |
|
276 | + * @param string $returnDocBlock |
|
277 | + * @return array |
|
278 | + */ |
|
279 | + protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
280 | + { |
|
281 | + $config = \CoreConfig::getConfig(); |
|
282 | + $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
283 | + $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
284 | + |
|
285 | + return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
286 | + } |
|
287 | 287 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | $prefix = $route['prefix']; |
57 | 57 | $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $prefix))); |
58 | - if($prefix === 'telescope') { |
|
58 | + if ($prefix === 'telescope') { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getRoutes() |
96 | 96 | { |
97 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
97 | + return collect(\Route::getRoutes())->map(function($route) { |
|
98 | 98 | if (strpos($route->uri(), 'api/') !== false) { |
99 | 99 | return [ |
100 | 100 | 'method' => $route->methods()[0], |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | ]; |
126 | 126 | |
127 | 127 | |
128 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
128 | + if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
129 | 129 | $route['headers']['Authorization'] = 'Bearer {token}'; |
130 | 130 | } |
131 | 131 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | if (count($parameters)) { |
175 | 175 | $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
176 | 176 | if ($className) { |
177 | - $reflectionClass = new \ReflectionClass($className); |
|
177 | + $reflectionClass = new \ReflectionClass($className); |
|
178 | 178 | |
179 | 179 | if ($reflectionClass->hasMethod('rules')) { |
180 | 180 | $reflectionMethod = $reflectionClass->getMethod('rules'); |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | { |
202 | 202 | $errors = []; |
203 | 203 | foreach (\Module::all() as $module) { |
204 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
205 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
204 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
205 | + $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors'; |
|
206 | 206 | $reflectionClass = new \ReflectionClass($class); |
207 | 207 | foreach ($reflectionClass->getMethods() as $method) { |
208 | 208 | $methodName = $method->name; |