@@ -11,39 +11,39 @@ |
||
11 | 11 | |
12 | 12 | class Kernel extends ConsoleKernel |
13 | 13 | { |
14 | - /** |
|
15 | - * The Artisan commands provided by your application. |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $commands = [ |
|
20 | - GenerateDocCommand::class, |
|
21 | - PassportInstallCommand::class, |
|
22 | - MakeNotificationsCommand::class, |
|
23 | - MakeModuleCommand::class |
|
24 | - ]; |
|
14 | + /** |
|
15 | + * The Artisan commands provided by your application. |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $commands = [ |
|
20 | + GenerateDocCommand::class, |
|
21 | + PassportInstallCommand::class, |
|
22 | + MakeNotificationsCommand::class, |
|
23 | + MakeModuleCommand::class |
|
24 | + ]; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Define the application's command schedule. |
|
28 | - * |
|
29 | - * @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - protected function schedule(Schedule $schedule) |
|
33 | - { |
|
34 | - // $schedule->command('inspire') |
|
35 | - // ->hourly(); |
|
36 | - } |
|
26 | + /** |
|
27 | + * Define the application's command schedule. |
|
28 | + * |
|
29 | + * @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + protected function schedule(Schedule $schedule) |
|
33 | + { |
|
34 | + // $schedule->command('inspire') |
|
35 | + // ->hourly(); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Register the commands for the application. |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - protected function commands() |
|
44 | - { |
|
45 | - $this->load(__DIR__.'/Commands'); |
|
38 | + /** |
|
39 | + * Register the commands for the application. |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + protected function commands() |
|
44 | + { |
|
45 | + $this->load(__DIR__.'/Commands'); |
|
46 | 46 | |
47 | - require base_path('routes/console.php'); |
|
48 | - } |
|
47 | + require base_path('routes/console.php'); |
|
48 | + } |
|
49 | 49 | } |
@@ -7,31 +7,31 @@ |
||
7 | 7 | |
8 | 8 | class AuthServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | - /** |
|
11 | - * The policy mappings for the application. |
|
12 | - * |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $policies = [ |
|
16 | - 'App\Model' => 'App\Policies\ModelPolicy', |
|
17 | - ]; |
|
10 | + /** |
|
11 | + * The policy mappings for the application. |
|
12 | + * |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $policies = [ |
|
16 | + 'App\Model' => 'App\Policies\ModelPolicy', |
|
17 | + ]; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Register any authentication / authorization services. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function boot() |
|
25 | - { |
|
26 | - $this->registerPolicies(); |
|
19 | + /** |
|
20 | + * Register any authentication / authorization services. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function boot() |
|
25 | + { |
|
26 | + $this->registerPolicies(); |
|
27 | 27 | |
28 | - Passport::routes(function ($router) { |
|
29 | - $router->forAuthorization(); |
|
30 | - $router->forAccessTokens(); |
|
31 | - $router->forPersonalAccessTokens(); |
|
32 | - $router->forTransientTokens(); |
|
33 | - }); |
|
34 | - Passport::tokensExpireIn(\Carbon\Carbon::now()->addMinutes(config('skeleton.token_expire_in'))); |
|
35 | - Passport::refreshTokensExpireIn(\Carbon\Carbon::now()->addMinutes(config('skeleton.refresh_token_expire_in'))); |
|
36 | - } |
|
28 | + Passport::routes(function ($router) { |
|
29 | + $router->forAuthorization(); |
|
30 | + $router->forAccessTokens(); |
|
31 | + $router->forPersonalAccessTokens(); |
|
32 | + $router->forTransientTokens(); |
|
33 | + }); |
|
34 | + Passport::tokensExpireIn(\Carbon\Carbon::now()->addMinutes(config('skeleton.token_expire_in'))); |
|
35 | + Passport::refreshTokensExpireIn(\Carbon\Carbon::now()->addMinutes(config('skeleton.refresh_token_expire_in'))); |
|
36 | + } |
|
37 | 37 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Disable Confirm Email |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | | |
12 | 12 | */ |
13 | 13 | |
14 | - 'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false), |
|
14 | + 'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false), |
|
15 | 15 | |
16 | - /* |
|
16 | + /* |
|
17 | 17 | |-------------------------------------------------------------------------- |
18 | 18 | | Confirm Email URL |
19 | 19 | |-------------------------------------------------------------------------- |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | | |
23 | 23 | */ |
24 | 24 | |
25 | - 'confrim_email_url' => env('CONFIRM_EMAIL_URL'), |
|
25 | + 'confrim_email_url' => env('CONFIRM_EMAIL_URL'), |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | |-------------------------------------------------------------------------- |
29 | 29 | | Reset Password URL |
30 | 30 | |-------------------------------------------------------------------------- |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | | |
34 | 34 | */ |
35 | 35 | |
36 | - 'reset_password_url' => env('RESET_PASSWORD_URL'), |
|
36 | + 'reset_password_url' => env('RESET_PASSWORD_URL'), |
|
37 | 37 | |
38 | - /* |
|
38 | + /* |
|
39 | 39 | |-------------------------------------------------------------------------- |
40 | 40 | | Passport Client Id |
41 | 41 | |-------------------------------------------------------------------------- |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | | |
45 | 45 | */ |
46 | 46 | |
47 | - 'passport_client_id' => env('PASSWORD_CLIENT_ID'), |
|
47 | + 'passport_client_id' => env('PASSWORD_CLIENT_ID'), |
|
48 | 48 | |
49 | - /* |
|
49 | + /* |
|
50 | 50 | |-------------------------------------------------------------------------- |
51 | 51 | | Passport Client Secret |
52 | 52 | |-------------------------------------------------------------------------- |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | | |
56 | 56 | */ |
57 | 57 | |
58 | - 'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
58 | + 'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
59 | 59 | |
60 | - /* |
|
60 | + /* |
|
61 | 61 | |-------------------------------------------------------------------------- |
62 | 62 | | Token Expire In |
63 | 63 | |-------------------------------------------------------------------------- |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | | |
67 | 67 | */ |
68 | 68 | |
69 | - 'token_expire_in' => env('TOKEN_EXPIRE_IN', 10), |
|
69 | + 'token_expire_in' => env('TOKEN_EXPIRE_IN', 10), |
|
70 | 70 | |
71 | - /* |
|
71 | + /* |
|
72 | 72 | |-------------------------------------------------------------------------- |
73 | 73 | | Refresh Token Expire In |
74 | 74 | |-------------------------------------------------------------------------- |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | | |
78 | 78 | */ |
79 | 79 | |
80 | - 'refresh_token_expire_in' => env('REFRESH_TOKEN_EXPIRE_IN', 14400), |
|
80 | + 'refresh_token_expire_in' => env('REFRESH_TOKEN_EXPIRE_IN', 14400), |
|
81 | 81 | |
82 | - /* |
|
82 | + /* |
|
83 | 83 | |-------------------------------------------------------------------------- |
84 | 84 | | Social Pass |
85 | 85 | |-------------------------------------------------------------------------- |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | | |
89 | 89 | */ |
90 | 90 | |
91 | - 'social_pass' => env('SOCIAL_PASS', false), |
|
91 | + 'social_pass' => env('SOCIAL_PASS', false), |
|
92 | 92 | |
93 | - /* |
|
93 | + /* |
|
94 | 94 | |-------------------------------------------------------------------------- |
95 | 95 | | Relations Between Models |
96 | 96 | |-------------------------------------------------------------------------- |
@@ -99,88 +99,88 @@ discard block |
||
99 | 99 | | |
100 | 100 | */ |
101 | 101 | |
102 | - 'relations' => [ |
|
103 | - 'user' => [ |
|
104 | - 'list' => [], |
|
105 | - 'find' => [], |
|
106 | - 'findby' => [], |
|
107 | - 'paginate' => [], |
|
108 | - 'paginateby' => [], |
|
109 | - 'first' => [], |
|
110 | - 'search' => [], |
|
111 | - 'account' => [], |
|
112 | - 'group' => [], |
|
113 | - 'deleted' => [], |
|
114 | - ], |
|
115 | - 'permission' => [ |
|
116 | - 'list' => [], |
|
117 | - 'find' => [], |
|
118 | - 'findby' => [], |
|
119 | - 'paginate' => [], |
|
120 | - 'paginateby' => [], |
|
121 | - 'first' => [], |
|
122 | - 'search' => [], |
|
123 | - 'deleted' => [], |
|
124 | - ], |
|
125 | - 'group' => [ |
|
126 | - 'list' => [], |
|
127 | - 'find' => [], |
|
128 | - 'findby' => [], |
|
129 | - 'paginate' => [], |
|
130 | - 'paginateby' => [], |
|
131 | - 'first' => [], |
|
132 | - 'search' => [], |
|
133 | - 'deleted' => [], |
|
134 | - ], |
|
135 | - 'oauthClient' => [ |
|
136 | - 'list' => [], |
|
137 | - 'find' => [], |
|
138 | - 'findby' => [], |
|
139 | - 'paginate' => [], |
|
140 | - 'paginateby' => [], |
|
141 | - 'first' => [], |
|
142 | - 'search' => [], |
|
143 | - 'account' => [], |
|
144 | - 'group' => [], |
|
145 | - 'deleted' => [], |
|
146 | - ], |
|
147 | - 'notification' => [ |
|
148 | - 'list' => [], |
|
149 | - 'unread' => [], |
|
150 | - ], |
|
151 | - 'pushNotificationDevice' => [ |
|
152 | - 'list' => [], |
|
153 | - 'find' => [], |
|
154 | - 'findby' => [], |
|
155 | - 'paginate' => [], |
|
156 | - 'paginateby' => [], |
|
157 | - 'first' => [], |
|
158 | - 'search' => [], |
|
159 | - 'deleted' => [], |
|
160 | - ], |
|
161 | - 'report' => [ |
|
162 | - 'list' => [], |
|
163 | - 'find' => [], |
|
164 | - 'findby' => [], |
|
165 | - 'paginate' => [], |
|
166 | - 'paginateby' => [], |
|
167 | - 'first' => [], |
|
168 | - 'search' => [], |
|
169 | - 'deleted' => [], |
|
170 | - ], |
|
171 | - 'setting' => [ |
|
172 | - 'list' => [], |
|
173 | - 'find' => [], |
|
174 | - 'findby' => [], |
|
175 | - 'paginate' => [], |
|
176 | - 'paginateby' => [], |
|
177 | - 'first' => [], |
|
178 | - 'search' => [], |
|
179 | - 'deleted' => [], |
|
180 | - ] |
|
181 | - ], |
|
102 | + 'relations' => [ |
|
103 | + 'user' => [ |
|
104 | + 'list' => [], |
|
105 | + 'find' => [], |
|
106 | + 'findby' => [], |
|
107 | + 'paginate' => [], |
|
108 | + 'paginateby' => [], |
|
109 | + 'first' => [], |
|
110 | + 'search' => [], |
|
111 | + 'account' => [], |
|
112 | + 'group' => [], |
|
113 | + 'deleted' => [], |
|
114 | + ], |
|
115 | + 'permission' => [ |
|
116 | + 'list' => [], |
|
117 | + 'find' => [], |
|
118 | + 'findby' => [], |
|
119 | + 'paginate' => [], |
|
120 | + 'paginateby' => [], |
|
121 | + 'first' => [], |
|
122 | + 'search' => [], |
|
123 | + 'deleted' => [], |
|
124 | + ], |
|
125 | + 'group' => [ |
|
126 | + 'list' => [], |
|
127 | + 'find' => [], |
|
128 | + 'findby' => [], |
|
129 | + 'paginate' => [], |
|
130 | + 'paginateby' => [], |
|
131 | + 'first' => [], |
|
132 | + 'search' => [], |
|
133 | + 'deleted' => [], |
|
134 | + ], |
|
135 | + 'oauthClient' => [ |
|
136 | + 'list' => [], |
|
137 | + 'find' => [], |
|
138 | + 'findby' => [], |
|
139 | + 'paginate' => [], |
|
140 | + 'paginateby' => [], |
|
141 | + 'first' => [], |
|
142 | + 'search' => [], |
|
143 | + 'account' => [], |
|
144 | + 'group' => [], |
|
145 | + 'deleted' => [], |
|
146 | + ], |
|
147 | + 'notification' => [ |
|
148 | + 'list' => [], |
|
149 | + 'unread' => [], |
|
150 | + ], |
|
151 | + 'pushNotificationDevice' => [ |
|
152 | + 'list' => [], |
|
153 | + 'find' => [], |
|
154 | + 'findby' => [], |
|
155 | + 'paginate' => [], |
|
156 | + 'paginateby' => [], |
|
157 | + 'first' => [], |
|
158 | + 'search' => [], |
|
159 | + 'deleted' => [], |
|
160 | + ], |
|
161 | + 'report' => [ |
|
162 | + 'list' => [], |
|
163 | + 'find' => [], |
|
164 | + 'findby' => [], |
|
165 | + 'paginate' => [], |
|
166 | + 'paginateby' => [], |
|
167 | + 'first' => [], |
|
168 | + 'search' => [], |
|
169 | + 'deleted' => [], |
|
170 | + ], |
|
171 | + 'setting' => [ |
|
172 | + 'list' => [], |
|
173 | + 'find' => [], |
|
174 | + 'findby' => [], |
|
175 | + 'paginate' => [], |
|
176 | + 'paginateby' => [], |
|
177 | + 'first' => [], |
|
178 | + 'search' => [], |
|
179 | + 'deleted' => [], |
|
180 | + ] |
|
181 | + ], |
|
182 | 182 | |
183 | - /* |
|
183 | + /* |
|
184 | 184 | |-------------------------------------------------------------------------- |
185 | 185 | | Cache Configurations |
186 | 186 | |-------------------------------------------------------------------------- |
@@ -189,46 +189,46 @@ discard block |
||
189 | 189 | | |
190 | 190 | */ |
191 | 191 | |
192 | - 'cache_config' => [ |
|
193 | - 'oauthClient' => [ |
|
194 | - 'cache' => [ |
|
195 | - 'all', |
|
196 | - 'find', |
|
197 | - 'findBy', |
|
198 | - 'paginate', |
|
199 | - 'paginateBy', |
|
200 | - 'first', |
|
201 | - 'search', |
|
202 | - 'deleted' |
|
203 | - ], |
|
204 | - 'clear' => [ |
|
205 | - 'update' => ['oauthClients', 'users', 'groups'], |
|
206 | - 'save' => ['oauthClients', 'users', 'groups'], |
|
207 | - 'delete' => ['oauthClients', 'users', 'groups'], |
|
208 | - 'restore' => ['oauthClients', 'users', 'groups'], |
|
209 | - 'revoke' => ['oauthClients', 'users', 'groups'], |
|
210 | - 'ubRevoke' => ['oauthClients', 'users', 'groups'], |
|
211 | - 'regenerateSecret' => ['oauthClients', 'users', 'groups'], |
|
212 | - ], |
|
213 | - ], |
|
214 | - 'setting' => [ |
|
215 | - 'cache' => [ |
|
216 | - 'all', |
|
217 | - 'find', |
|
218 | - 'findBy', |
|
219 | - 'paginate', |
|
220 | - 'paginateBy', |
|
221 | - 'first', |
|
222 | - 'search', |
|
223 | - 'deleted' |
|
224 | - ], |
|
225 | - 'clear' => [ |
|
226 | - 'update' => ['settings'], |
|
227 | - 'save' => ['settings'], |
|
228 | - 'delete' => ['settings'], |
|
229 | - 'restore' => ['settings'], |
|
230 | - 'saveMany' => ['settings'], |
|
231 | - ] |
|
232 | - ] |
|
233 | - ] |
|
192 | + 'cache_config' => [ |
|
193 | + 'oauthClient' => [ |
|
194 | + 'cache' => [ |
|
195 | + 'all', |
|
196 | + 'find', |
|
197 | + 'findBy', |
|
198 | + 'paginate', |
|
199 | + 'paginateBy', |
|
200 | + 'first', |
|
201 | + 'search', |
|
202 | + 'deleted' |
|
203 | + ], |
|
204 | + 'clear' => [ |
|
205 | + 'update' => ['oauthClients', 'users', 'groups'], |
|
206 | + 'save' => ['oauthClients', 'users', 'groups'], |
|
207 | + 'delete' => ['oauthClients', 'users', 'groups'], |
|
208 | + 'restore' => ['oauthClients', 'users', 'groups'], |
|
209 | + 'revoke' => ['oauthClients', 'users', 'groups'], |
|
210 | + 'ubRevoke' => ['oauthClients', 'users', 'groups'], |
|
211 | + 'regenerateSecret' => ['oauthClients', 'users', 'groups'], |
|
212 | + ], |
|
213 | + ], |
|
214 | + 'setting' => [ |
|
215 | + 'cache' => [ |
|
216 | + 'all', |
|
217 | + 'find', |
|
218 | + 'findBy', |
|
219 | + 'paginate', |
|
220 | + 'paginateBy', |
|
221 | + 'first', |
|
222 | + 'search', |
|
223 | + 'deleted' |
|
224 | + ], |
|
225 | + 'clear' => [ |
|
226 | + 'update' => ['settings'], |
|
227 | + 'save' => ['settings'], |
|
228 | + 'delete' => ['settings'], |
|
229 | + 'restore' => ['settings'], |
|
230 | + 'saveMany' => ['settings'], |
|
231 | + ] |
|
232 | + ] |
|
233 | + ] |
|
234 | 234 | ]; |
@@ -12,108 +12,108 @@ |
||
12 | 12 | |
13 | 13 | class AclUser extends User |
14 | 14 | { |
15 | - use SoftDeletes, HasApiTokens; |
|
16 | - protected $table = 'users'; |
|
17 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
18 | - protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
19 | - protected $guarded = ['id']; |
|
20 | - protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone']; |
|
21 | - |
|
22 | - /** |
|
23 | - * Encrypt the password attribute before |
|
24 | - * saving it in the storage. |
|
25 | - * |
|
26 | - * @param string $value |
|
27 | - */ |
|
28 | - public function setPasswordAttribute($value) |
|
29 | - { |
|
30 | - $this->attributes['password'] = \Hash::make($value); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Get the entity's notifications. |
|
35 | - */ |
|
36 | - public function notifications() |
|
37 | - { |
|
38 | - return $this->morphMany(Notification::class, 'notifiable')->orderBy('created_at', 'desc'); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Get the entity's read notifications. |
|
43 | - */ |
|
44 | - public function readNotifications() |
|
45 | - { |
|
46 | - return $this->notifications()->whereNotNull('read_at'); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Get the entity's unread notifications. |
|
51 | - */ |
|
52 | - public function unreadNotifications() |
|
53 | - { |
|
54 | - return $this->notifications()->whereNull('read_at'); |
|
55 | - } |
|
56 | - |
|
57 | - public function roles() |
|
58 | - { |
|
59 | - return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
60 | - } |
|
61 | - |
|
62 | - public function oauthClients() |
|
63 | - { |
|
64 | - return $this->hasMany(OauthClient::class, 'user_id'); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Return fcm device tokens that will be used in sending fcm notifications. |
|
69 | - * |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function routeNotificationForFCM() |
|
73 | - { |
|
74 | - $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
75 | - $tokens = []; |
|
76 | - |
|
77 | - foreach ($devices as $device) { |
|
78 | - if (\Core::oauthClients()->accessTokenExpiredOrRevoked($device->access_token)) { |
|
79 | - $device->forceDelete(); |
|
80 | - continue; |
|
81 | - } |
|
82 | - |
|
83 | - $tokens[] = $device->device_token; |
|
84 | - } |
|
85 | - |
|
86 | - return $tokens; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * The channels the user receives notification broadcasts on. |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function receivesBroadcastNotificationsOn() |
|
95 | - { |
|
96 | - return 'users.'.$this->id; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Custom password validation. |
|
101 | - * |
|
102 | - * @param string $password |
|
103 | - * @return boolean |
|
104 | - */ |
|
105 | - public function validateForPassportPasswordGrant($password) |
|
106 | - { |
|
107 | - if ($password == config('skeleton.social_pass')) { |
|
108 | - return true; |
|
109 | - } |
|
110 | - |
|
111 | - return \Hash::check($password, $this->password); |
|
112 | - } |
|
15 | + use SoftDeletes, HasApiTokens; |
|
16 | + protected $table = 'users'; |
|
17 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
18 | + protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
19 | + protected $guarded = ['id']; |
|
20 | + protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone']; |
|
21 | + |
|
22 | + /** |
|
23 | + * Encrypt the password attribute before |
|
24 | + * saving it in the storage. |
|
25 | + * |
|
26 | + * @param string $value |
|
27 | + */ |
|
28 | + public function setPasswordAttribute($value) |
|
29 | + { |
|
30 | + $this->attributes['password'] = \Hash::make($value); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Get the entity's notifications. |
|
35 | + */ |
|
36 | + public function notifications() |
|
37 | + { |
|
38 | + return $this->morphMany(Notification::class, 'notifiable')->orderBy('created_at', 'desc'); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Get the entity's read notifications. |
|
43 | + */ |
|
44 | + public function readNotifications() |
|
45 | + { |
|
46 | + return $this->notifications()->whereNotNull('read_at'); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Get the entity's unread notifications. |
|
51 | + */ |
|
52 | + public function unreadNotifications() |
|
53 | + { |
|
54 | + return $this->notifications()->whereNull('read_at'); |
|
55 | + } |
|
56 | + |
|
57 | + public function roles() |
|
58 | + { |
|
59 | + return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
60 | + } |
|
61 | + |
|
62 | + public function oauthClients() |
|
63 | + { |
|
64 | + return $this->hasMany(OauthClient::class, 'user_id'); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Return fcm device tokens that will be used in sending fcm notifications. |
|
69 | + * |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function routeNotificationForFCM() |
|
73 | + { |
|
74 | + $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
75 | + $tokens = []; |
|
76 | + |
|
77 | + foreach ($devices as $device) { |
|
78 | + if (\Core::oauthClients()->accessTokenExpiredOrRevoked($device->access_token)) { |
|
79 | + $device->forceDelete(); |
|
80 | + continue; |
|
81 | + } |
|
82 | + |
|
83 | + $tokens[] = $device->device_token; |
|
84 | + } |
|
85 | + |
|
86 | + return $tokens; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * The channels the user receives notification broadcasts on. |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function receivesBroadcastNotificationsOn() |
|
95 | + { |
|
96 | + return 'users.'.$this->id; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Custom password validation. |
|
101 | + * |
|
102 | + * @param string $password |
|
103 | + * @return boolean |
|
104 | + */ |
|
105 | + public function validateForPassportPasswordGrant($password) |
|
106 | + { |
|
107 | + if ($password == config('skeleton.social_pass')) { |
|
108 | + return true; |
|
109 | + } |
|
110 | + |
|
111 | + return \Hash::check($password, $this->password); |
|
112 | + } |
|
113 | 113 | |
114 | - public static function boot() |
|
115 | - { |
|
116 | - parent::boot(); |
|
117 | - AclUser::observe(AclUserObserver::class); |
|
118 | - } |
|
114 | + public static function boot() |
|
115 | + { |
|
116 | + parent::boot(); |
|
117 | + AclUser::observe(AclUserObserver::class); |
|
118 | + } |
|
119 | 119 | } |
@@ -9,32 +9,32 @@ |
||
9 | 9 | |
10 | 10 | class AclUser extends JsonResource |
11 | 11 | { |
12 | - /** |
|
13 | - * Transform the resource into an array. |
|
14 | - * |
|
15 | - * @param Request $request |
|
16 | - * @return array |
|
17 | - */ |
|
18 | - public function toArray($request) |
|
19 | - { |
|
20 | - if (! $this->resource) { |
|
21 | - return []; |
|
22 | - } |
|
12 | + /** |
|
13 | + * Transform the resource into an array. |
|
14 | + * |
|
15 | + * @param Request $request |
|
16 | + * @return array |
|
17 | + */ |
|
18 | + public function toArray($request) |
|
19 | + { |
|
20 | + if (! $this->resource) { |
|
21 | + return []; |
|
22 | + } |
|
23 | 23 | |
24 | - return [ |
|
25 | - 'id' => $this->id, |
|
26 | - 'name' => $this->name, |
|
27 | - 'email' => $this->email, |
|
28 | - 'profilePicture' => $this->profile_picture ? url(\Storage::url($this->profile_picture)) : null, |
|
29 | - 'notifications' => NotificationResource::collection($this->whenLoaded('notifications')), |
|
30 | - 'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')), |
|
31 | - 'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')), |
|
32 | - 'roles' => RoleResource::collection($this->whenLoaded('roles')), |
|
33 | - 'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')), |
|
34 | - 'locale' => $this->locale, |
|
35 | - 'timezone' => $this->timezone, |
|
36 | - 'created_at' => $this->created_at, |
|
37 | - 'updated_at' => $this->updated_at, |
|
38 | - ]; |
|
39 | - } |
|
24 | + return [ |
|
25 | + 'id' => $this->id, |
|
26 | + 'name' => $this->name, |
|
27 | + 'email' => $this->email, |
|
28 | + 'profilePicture' => $this->profile_picture ? url(\Storage::url($this->profile_picture)) : null, |
|
29 | + 'notifications' => NotificationResource::collection($this->whenLoaded('notifications')), |
|
30 | + 'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')), |
|
31 | + 'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')), |
|
32 | + 'roles' => RoleResource::collection($this->whenLoaded('roles')), |
|
33 | + 'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')), |
|
34 | + 'locale' => $this->locale, |
|
35 | + 'timezone' => $this->timezone, |
|
36 | + 'created_at' => $this->created_at, |
|
37 | + 'updated_at' => $this->updated_at, |
|
38 | + ]; |
|
39 | + } |
|
40 | 40 | } |
@@ -5,41 +5,41 @@ |
||
5 | 5 | |
6 | 6 | class Permissions extends Migration |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - Schema::create('permissions', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name', 100); |
|
18 | - $table->string('model', 100); |
|
19 | - $table->softDeletes(); |
|
20 | - $table->timestamps(); |
|
21 | - $table->unique(array('name', 'model')); |
|
22 | - }); |
|
23 | - Schema::create('permission_role', function (Blueprint $table) { |
|
24 | - $table->increments('id'); |
|
25 | - $table->unsignedInteger('role_id'); |
|
26 | - $table->unsignedInteger('permission_id'); |
|
27 | - $table->softDeletes(); |
|
28 | - $table->timestamps(); |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + Schema::create('permissions', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name', 100); |
|
18 | + $table->string('model', 100); |
|
19 | + $table->softDeletes(); |
|
20 | + $table->timestamps(); |
|
21 | + $table->unique(array('name', 'model')); |
|
22 | + }); |
|
23 | + Schema::create('permission_role', function (Blueprint $table) { |
|
24 | + $table->increments('id'); |
|
25 | + $table->unsignedInteger('role_id'); |
|
26 | + $table->unsignedInteger('permission_id'); |
|
27 | + $table->softDeletes(); |
|
28 | + $table->timestamps(); |
|
29 | 29 | |
30 | - $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | - $table->foreign('permission_id')->references('id')->on('permissions'); |
|
32 | - }); |
|
33 | - } |
|
30 | + $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | + $table->foreign('permission_id')->references('id')->on('permissions'); |
|
32 | + }); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Reverse the migrations. |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function down() |
|
41 | - { |
|
42 | - Schema::dropIfExists('permission_role'); |
|
43 | - Schema::dropIfExists('permissions'); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Reverse the migrations. |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function down() |
|
41 | + { |
|
42 | + Schema::dropIfExists('permission_role'); |
|
43 | + Schema::dropIfExists('permissions'); |
|
44 | + } |
|
45 | 45 | } |
@@ -5,40 +5,40 @@ |
||
5 | 5 | |
6 | 6 | class Roles extends Migration |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - Schema::create('roles', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name', 100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + Schema::create('roles', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name', 100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('role_user', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->unsignedInteger('user_id'); |
|
25 | - $table->unsignedInteger('role_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
22 | + Schema::create('role_user', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->unsignedInteger('user_id'); |
|
25 | + $table->unsignedInteger('role_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | 28 | |
29 | - $table->foreign('user_id')->references('id')->on('users'); |
|
30 | - $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | - }); |
|
32 | - } |
|
29 | + $table->foreign('user_id')->references('id')->on('users'); |
|
30 | + $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | + }); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Reverse the migrations. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function down() |
|
40 | - { |
|
41 | - Schema::dropIfExists('role_user'); |
|
42 | - Schema::dropIfExists('roles'); |
|
43 | - } |
|
34 | + /** |
|
35 | + * Reverse the migrations. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function down() |
|
40 | + { |
|
41 | + Schema::dropIfExists('role_user'); |
|
42 | + Schema::dropIfExists('roles'); |
|
43 | + } |
|
44 | 44 | } |
@@ -7,38 +7,38 @@ |
||
7 | 7 | |
8 | 8 | class PassportInstallCommand extends Command |
9 | 9 | { |
10 | - /** |
|
11 | - * The name and signature of the console command. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $signature = 'module:passport:install |
|
10 | + /** |
|
11 | + * The name and signature of the console command. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $signature = 'module:passport:install |
|
16 | 16 | {--force : Overwrite keys they already exist} |
17 | 17 | {--length=4096 : The length of the private key}'; |
18 | 18 | |
19 | - /** |
|
20 | - * The console command description. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $description = 'Run the commands necessary to prepare Passport for use'; |
|
19 | + /** |
|
20 | + * The console command description. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $description = 'Run the commands necessary to prepare Passport for use'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Execute the console command. |
|
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function handle(ClientRepository $client) |
|
32 | - { |
|
33 | - $this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]); |
|
34 | - if( ! \Core::oauthCLients()->first(['password_client' => 1])->count()) { |
|
26 | + /** |
|
27 | + * Execute the console command. |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function handle(ClientRepository $client) |
|
32 | + { |
|
33 | + $this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]); |
|
34 | + if( ! \Core::oauthCLients()->first(['password_client' => 1])->count()) { |
|
35 | 35 | |
36 | - $client = $client->createPasswordGrantClient( |
|
37 | - null, config('app.name'), 'http://localhost' |
|
38 | - ); |
|
39 | - \DotenvEditor::setKey('PASSWORD_CLIENT_ID', $client->id); |
|
40 | - \DotenvEditor::setKey('PASSWORD_CLIENT_SECRET', $client->secret); |
|
41 | - \DotenvEditor::save(); |
|
42 | - } |
|
43 | - } |
|
36 | + $client = $client->createPasswordGrantClient( |
|
37 | + null, config('app.name'), 'http://localhost' |
|
38 | + ); |
|
39 | + \DotenvEditor::setKey('PASSWORD_CLIENT_ID', $client->id); |
|
40 | + \DotenvEditor::setKey('PASSWORD_CLIENT_SECRET', $client->secret); |
|
41 | + \DotenvEditor::save(); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public function handle(ClientRepository $client) |
32 | 32 | { |
33 | 33 | $this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]); |
34 | - if( ! \Core::oauthCLients()->first(['password_client' => 1])->count()) { |
|
34 | + if ( ! \Core::oauthCLients()->first(['password_client' => 1])->count()) { |
|
35 | 35 | |
36 | 36 | $client = $client->createPasswordGrantClient( |
37 | 37 | null, config('app.name'), 'http://localhost' |
@@ -8,280 +8,280 @@ |
||
8 | 8 | |
9 | 9 | class GenerateDocCommand 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 | } |