@@ -6,64 +6,64 @@ |
||
6 | 6 | |
7 | 7 | class PushNotificationDevicesTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to settings table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * pushNotificationDevices model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'index', |
|
26 | - 'model' => 'pushNotificationDevice', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'show', |
|
32 | - 'model' => 'pushNotificationDevice', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'store', |
|
38 | - 'model' => 'pushNotificationDevice', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'update', |
|
44 | - 'model' => 'pushNotificationDevice', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'delete', |
|
50 | - 'model' => 'pushNotificationDevice', |
|
51 | - 'created_at' => \DB::raw('NOW()'), |
|
52 | - 'updated_at' => \DB::raw('NOW()') |
|
53 | - ], |
|
54 | - [ |
|
55 | - 'name' => 'deleted', |
|
56 | - 'model' => 'pushNotificationDevice', |
|
57 | - 'created_at' => \DB::raw('NOW()'), |
|
58 | - 'updated_at' => \DB::raw('NOW()') |
|
59 | - ], |
|
60 | - [ |
|
61 | - 'name' => 'restore', |
|
62 | - 'model' => 'pushNotificationDevice', |
|
63 | - 'created_at' => \DB::raw('NOW()'), |
|
64 | - 'updated_at' => \DB::raw('NOW()') |
|
65 | - ] |
|
66 | - ] |
|
67 | - ); |
|
68 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to settings table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * pushNotificationDevices model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'index', |
|
26 | + 'model' => 'pushNotificationDevice', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'show', |
|
32 | + 'model' => 'pushNotificationDevice', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'store', |
|
38 | + 'model' => 'pushNotificationDevice', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'update', |
|
44 | + 'model' => 'pushNotificationDevice', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'delete', |
|
50 | + 'model' => 'pushNotificationDevice', |
|
51 | + 'created_at' => \DB::raw('NOW()'), |
|
52 | + 'updated_at' => \DB::raw('NOW()') |
|
53 | + ], |
|
54 | + [ |
|
55 | + 'name' => 'deleted', |
|
56 | + 'model' => 'pushNotificationDevice', |
|
57 | + 'created_at' => \DB::raw('NOW()'), |
|
58 | + 'updated_at' => \DB::raw('NOW()') |
|
59 | + ], |
|
60 | + [ |
|
61 | + 'name' => 'restore', |
|
62 | + 'model' => 'pushNotificationDevice', |
|
63 | + 'created_at' => \DB::raw('NOW()'), |
|
64 | + 'updated_at' => \DB::raw('NOW()') |
|
65 | + ] |
|
66 | + ] |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -8,46 +8,46 @@ |
||
8 | 8 | |
9 | 9 | class PushNotificationDeviceController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * Path of the sotre form request. |
|
13 | - * |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $storeFormRequest = 'App\Modules\Users\Http\PushNotificationDevices\StorePushNotificationDevice'; |
|
11 | + /** |
|
12 | + * Path of the sotre form request. |
|
13 | + * |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $storeFormRequest = 'App\Modules\Users\Http\PushNotificationDevices\StorePushNotificationDevice'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Path of the model resource |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $modelResource = 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice'; |
|
18 | + /** |
|
19 | + * Path of the model resource |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $modelResource = 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * List of all route actions that the base api controller |
|
27 | - * will skip permissions check for them. |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $skipPermissionCheck = ['registerDevice']; |
|
25 | + /** |
|
26 | + * List of all route actions that the base api controller |
|
27 | + * will skip permissions check for them. |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $skipPermissionCheck = ['registerDevice']; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Init new object. |
|
34 | - * |
|
35 | - * @param PushNotificationDeviceService $service |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function __construct(PushNotificationDeviceService $service) |
|
39 | - { |
|
40 | - parent::__construct($service); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Init new object. |
|
34 | + * |
|
35 | + * @param PushNotificationDeviceService $service |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function __construct(PushNotificationDeviceService $service) |
|
39 | + { |
|
40 | + parent::__construct($service); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Register the given device to the logged in user. |
|
45 | - * |
|
46 | - * @param RegisterDevice $request |
|
47 | - * @return \Illuminate\Http\Response |
|
48 | - */ |
|
49 | - public function registerDevice(RegisterDevice $request) |
|
50 | - { |
|
51 | - return new $this->modelResource($this->service->registerDevice($request->all())); |
|
52 | - } |
|
43 | + /** |
|
44 | + * Register the given device to the logged in user. |
|
45 | + * |
|
46 | + * @param RegisterDevice $request |
|
47 | + * @return \Illuminate\Http\Response |
|
48 | + */ |
|
49 | + public function registerDevice(RegisterDevice $request) |
|
50 | + { |
|
51 | + return new $this->modelResource($this->service->registerDevice($request->all())); |
|
52 | + } |
|
53 | 53 | } |
@@ -6,26 +6,26 @@ |
||
6 | 6 | |
7 | 7 | class StorePushNotificationDevice 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 | - 'device_token' => 'required|string|max:255', |
|
28 | - 'user_id' => 'required|exists:users,id' |
|
29 | - ]; |
|
30 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + 'device_token' => 'required|string|max:255', |
|
28 | + 'user_id' => 'required|exists:users,id' |
|
29 | + ]; |
|
30 | + } |
|
31 | 31 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | |
16 | 16 | Route::group(['prefix' => 'push/notification/devices'], function () { |
17 | 17 | |
18 | - Route::get('/', 'PushNotificationDeviceController@index'); |
|
19 | - Route::get('{id}', 'PushNotificationDeviceController@show'); |
|
20 | - Route::post('/', 'PushNotificationDeviceController@store'); |
|
21 | - Route::patch('{id}', 'PushNotificationDeviceController@update'); |
|
22 | - Route::delete('{id}', 'PushNotificationDeviceController@destroy'); |
|
23 | - Route::patch('{id}/restore', 'PushNotificationDeviceController@restore'); |
|
24 | - Route::post('register/device', 'PushNotificationDeviceController@registerDevice'); |
|
18 | + Route::get('/', 'PushNotificationDeviceController@index'); |
|
19 | + Route::get('{id}', 'PushNotificationDeviceController@show'); |
|
20 | + Route::post('/', 'PushNotificationDeviceController@store'); |
|
21 | + Route::patch('{id}', 'PushNotificationDeviceController@update'); |
|
22 | + Route::delete('{id}', 'PushNotificationDeviceController@destroy'); |
|
23 | + Route::patch('{id}/restore', 'PushNotificationDeviceController@restore'); |
|
24 | + Route::post('register/device', 'PushNotificationDeviceController@registerDevice'); |
|
25 | 25 | }); |
@@ -6,52 +6,52 @@ |
||
6 | 6 | |
7 | 7 | class SettingsTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to settings table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * Settings model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'index', |
|
26 | - 'model' => 'setting', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'show', |
|
32 | - 'model' => 'setting', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'update', |
|
38 | - 'model' => 'setting', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'destroy', |
|
44 | - 'model' => 'setting', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'saveMany', |
|
50 | - 'model' => 'setting', |
|
51 | - 'created_at' => \DB::raw('NOW()'), |
|
52 | - 'updated_at' => \DB::raw('NOW()') |
|
53 | - ] |
|
54 | - ] |
|
55 | - ); |
|
56 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to settings table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * Settings model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'index', |
|
26 | + 'model' => 'setting', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'show', |
|
32 | + 'model' => 'setting', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'update', |
|
38 | + 'model' => 'setting', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'destroy', |
|
44 | + 'model' => 'setting', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'saveMany', |
|
50 | + 'model' => 'setting', |
|
51 | + 'created_at' => \DB::raw('NOW()'), |
|
52 | + 'updated_at' => \DB::raw('NOW()') |
|
53 | + ] |
|
54 | + ] |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | } |
@@ -9,39 +9,39 @@ |
||
9 | 9 | |
10 | 10 | class SettingController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * Path of the sotre form request. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $storeFormRequest = 'App\Modules\Core\Http\Requests\StoreSetting'; |
|
12 | + /** |
|
13 | + * Path of the sotre form request. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $storeFormRequest = 'App\Modules\Core\Http\Requests\StoreSetting'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Path of the model resource |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $modelResource = 'App\Modules\Core\Http\Resources\Setting'; |
|
19 | + /** |
|
20 | + * Path of the model resource |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $modelResource = 'App\Modules\Core\Http\Resources\Setting'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Init new object. |
|
28 | - * |
|
29 | - * @param SettingService $service |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function __construct(SettingService $service) |
|
33 | - { |
|
34 | - parent::__construct($service); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Init new object. |
|
28 | + * |
|
29 | + * @param SettingService $service |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function __construct(SettingService $service) |
|
33 | + { |
|
34 | + parent::__construct($service); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Save list of settings. |
|
39 | - * |
|
40 | - * @param Request $request |
|
41 | - * @return \Illuminate\Http\Response |
|
42 | - */ |
|
43 | - public function saveMany(Request $request) |
|
44 | - { |
|
45 | - return new GeneralResource($this->service->saveMany($request->all())); |
|
46 | - } |
|
37 | + /** |
|
38 | + * Save list of settings. |
|
39 | + * |
|
40 | + * @param Request $request |
|
41 | + * @return \Illuminate\Http\Response |
|
42 | + */ |
|
43 | + public function saveMany(Request $request) |
|
44 | + { |
|
45 | + return new GeneralResource($this->service->saveMany($request->all())); |
|
46 | + } |
|
47 | 47 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class StoreSetting 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 | - 'value' => 'required|string' |
|
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 | + 'value' => 'required|string' |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | |
16 | 16 | Route::group(['prefix' => 'DummyRoutePrefix'], function () { |
17 | 17 | |
18 | - Route::get('/', 'DummyController@index'); |
|
19 | - Route::get('{id}', 'DummyController@show'); |
|
20 | - Route::post('/', 'DummyController@store'); |
|
21 | - Route::patch('{id}', 'DummyController@update'); |
|
22 | - Route::delete('{id}', 'DummyController@destroy'); |
|
23 | - Route::patch('restore/{id}', 'DummyController@restore'); |
|
18 | + Route::get('/', 'DummyController@index'); |
|
19 | + Route::get('{id}', 'DummyController@show'); |
|
20 | + Route::post('/', 'DummyController@store'); |
|
21 | + Route::patch('{id}', 'DummyController@update'); |
|
22 | + Route::delete('{id}', 'DummyController@destroy'); |
|
23 | + Route::patch('restore/{id}', 'DummyController@restore'); |
|
24 | 24 | }); |
@@ -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 | } |