Completed
Push — master ( 6c2405...30f758 )
by Sherif
11:32
created
src/Modules/Acl/Database/Migrations/2015_12_20_124153_users.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -13,31 +13,31 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('users', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('profile_picture', 150)->nullable();
18
-            $table->string('name', 100)->nullable();
19
-            $table->string('email')->unique();
20
-            $table->string('password', 60)->nullable();
21
-            $table->boolean('blocked')->default(0);
22
-            $table->boolean('confirmed')->default(0);
23
-            $table->string('confirmation_code')->nullable();
24
-            $table->softDeletes();
25
-            $table->rememberToken();
26
-            $table->timestamps();
27
-        });
16
+			$table->increments('id');
17
+			$table->string('profile_picture', 150)->nullable();
18
+			$table->string('name', 100)->nullable();
19
+			$table->string('email')->unique();
20
+			$table->string('password', 60)->nullable();
21
+			$table->boolean('blocked')->default(0);
22
+			$table->boolean('confirmed')->default(0);
23
+			$table->string('confirmation_code')->nullable();
24
+			$table->softDeletes();
25
+			$table->rememberToken();
26
+			$table->timestamps();
27
+		});
28 28
 
29 29
 		/**
30 30
 		 * Create Default users.
31 31
 		 */
32 32
 		\DB::table('users')->insertGetId(
33
-            [
33
+			[
34 34
 			'name'       => 'Admin',
35 35
 			'email'      => '[email protected]',
36 36
 			'password'   => bcrypt('123456'),
37 37
 			'created_at' => \DB::raw('NOW()'),
38 38
 			'updated_at' => \DB::raw('NOW()')
39 39
 			]
40
-        );
40
+		);
41 41
 	}
42 42
 
43 43
 	/**
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/UserRepository.php 3 patches
Indentation   +382 added lines, -382 removed lines patch added patch discarded remove patch
@@ -5,394 +5,394 @@
 block discarded – undo
5 5
 
6 6
 class UserRepository extends AbstractRepository
7 7
 {
8
-    /**
9
-     * Return the model full namespace.
10
-     * 
11
-     * @return string
12
-     */
13
-    protected function getModel()
14
-    {
15
-        return 'App\Modules\Acl\AclUser';
16
-    }
17
-
18
-
19
-    /**
20
-     * Return the logged in user account.
21
-     *
22
-     * @param  array   $relations
23
-     * @return boolean
24
-     */
25
-    public function account($relations = [])
26
-    {
27
-        $permissions = [];
28
-        $user        = \Core::users()->find(\Auth::id(), $relations);
29
-        foreach ($user->groups()->get() as $group)
30
-        {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
32
-                $permissions[$permission->model][$permission->id] = $permission->name;
33
-            });
34
-        }
35
-        $user->permissions = $permissions;
36
-
37
-       return $user;
38
-    }
39
-
40
-    /**
41
-     * Check if the logged in user or the given user 
42
-     * has the given permissions on the given model.
43
-     * 
44
-     * @param  string  $nameOfPermission
45
-     * @param  string  $model            
46
-     * @param  boolean $user
47
-     * @return boolean
48
-     */
49
-    public function can($nameOfPermission, $model, $user = false)
50
-    {      
51
-        $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
-        $permissions = [];
53
-
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
-        });
8
+	/**
9
+	 * Return the model full namespace.
10
+	 * 
11
+	 * @return string
12
+	 */
13
+	protected function getModel()
14
+	{
15
+		return 'App\Modules\Acl\AclUser';
16
+	}
17
+
18
+
19
+	/**
20
+	 * Return the logged in user account.
21
+	 *
22
+	 * @param  array   $relations
23
+	 * @return boolean
24
+	 */
25
+	public function account($relations = [])
26
+	{
27
+		$permissions = [];
28
+		$user        = \Core::users()->find(\Auth::id(), $relations);
29
+		foreach ($user->groups()->get() as $group)
30
+		{
31
+			$group->permissions->each(function ($permission) use (&$permissions){
32
+				$permissions[$permission->model][$permission->id] = $permission->name;
33
+			});
34
+		}
35
+		$user->permissions = $permissions;
36
+
37
+	   return $user;
38
+	}
39
+
40
+	/**
41
+	 * Check if the logged in user or the given user 
42
+	 * has the given permissions on the given model.
43
+	 * 
44
+	 * @param  string  $nameOfPermission
45
+	 * @param  string  $model            
46
+	 * @param  boolean $user
47
+	 * @return boolean
48
+	 */
49
+	public function can($nameOfPermission, $model, $user = false)
50
+	{      
51
+		$user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
+		$permissions = [];
53
+
54
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
+		});
57 57
         
58
-        return in_array($nameOfPermission, $permissions);
59
-    }
60
-
61
-    /**
62
-     * Check if the logged in user has the given group.
63
-     * 
64
-     * @param  string  $groupName
65
-     * @param  integer $userId
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groups, $user = false)
69
-    {
70
-        $user = $user ?: $this->find(\Auth::id());
71
-        return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
-    }
73
-
74
-    /**
75
-     * Assign the given group ids to the given user.
76
-     * 
77
-     * @param  integer $user_id    
78
-     * @param  array   $group_ids
79
-     * @return object
80
-     */
81
-    public function assignGroups($user_id, $group_ids)
82
-    {
83
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
-            $user = $this->find($user_id);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($group_ids);
87
-        });
88
-
89
-        return $this->find($user_id);
90
-    }
91
-
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     * 
96
-     * @param  array   $credentials    
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
-        {
104
-            \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
-        {
108
-            \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
-        {
112
-            \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
115
-        {
116
-            \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if (! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
119
-        {
120
-            \ErrorHandler::emailNotConfirmed();
121
-        }
122
-
123
-        return $user;
124
-    }
125
-
126
-    /**
127
-     * Handle a social login request of the none admin to the application.
128
-     * 
129
-     * @param  array   $credentials
130
-     * @return array
131
-     */
132
-    public function loginSocial($credentials)
133
-    {
134
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
-
137
-        if ( ! $user->email)
138
-        {
139
-            \ErrorHandler::noSocialEmail();
140
-        }
141
-
142
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
-        {
144
-            $data = ['email' => $user->email, 'password' => ''];
145
-            return $this->register($data);
146
-        }
147
-        else
148
-        {
149
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
-            {
151
-                \ErrorHandler::userAlreadyRegistered();
152
-            }
153
-
154
-            $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
155
-            return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
-        }
157
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  string  $groupName
65
+	 * @param  integer $userId
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groups, $user = false)
69
+	{
70
+		$user = $user ?: $this->find(\Auth::id());
71
+		return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
+	}
73
+
74
+	/**
75
+	 * Assign the given group ids to the given user.
76
+	 * 
77
+	 * @param  integer $user_id    
78
+	 * @param  array   $group_ids
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($user_id, $group_ids)
82
+	{
83
+		\DB::transaction(function () use ($user_id, $group_ids) {
84
+			$user = $this->find($user_id);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($group_ids);
87
+		});
88
+
89
+		return $this->find($user_id);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 * 
96
+	 * @param  array   $credentials    
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
+		{
104
+			\ErrorHandler::loginFailed();
105
+		}
106
+		else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
+		{
108
+			\ErrorHandler::loginFailed();
109
+		}
110
+		else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
+		{
112
+			\ErrorHandler::loginFailed();
113
+		}
114
+		else if ($user->blocked)
115
+		{
116
+			\ErrorHandler::userIsBlocked();
117
+		}
118
+		else if (! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
119
+		{
120
+			\ErrorHandler::emailNotConfirmed();
121
+		}
122
+
123
+		return $user;
124
+	}
125
+
126
+	/**
127
+	 * Handle a social login request of the none admin to the application.
128
+	 * 
129
+	 * @param  array   $credentials
130
+	 * @return array
131
+	 */
132
+	public function loginSocial($credentials)
133
+	{
134
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
+
137
+		if ( ! $user->email)
138
+		{
139
+			\ErrorHandler::noSocialEmail();
140
+		}
141
+
142
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
+		{
144
+			$data = ['email' => $user->email, 'password' => ''];
145
+			return $this->register($data);
146
+		}
147
+		else
148
+		{
149
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
+			{
151
+				\ErrorHandler::userAlreadyRegistered();
152
+			}
153
+
154
+			$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
155
+			return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
+		}
157
+	}
158 158
     
159
-    /**
160
-     * Handle a registration request.
161
-     * 
162
-     * @param  array $credentials
163
-     * @return array
164
-     */
165
-    public function register($credentials)
166
-    {
167
-        $user = $this->save($credentials);
168
-
169
-        if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-    }
159
+	/**
160
+	 * Handle a registration request.
161
+	 * 
162
+	 * @param  array $credentials
163
+	 * @return array
164
+	 */
165
+	public function register($credentials)
166
+	{
167
+		$user = $this->save($credentials);
168
+
169
+		if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+	}
174 174
     
175
-    /**
176
-     * Block the user.
177
-     *
178
-     * @param  integer $user_id
179
-     * @return object
180
-     */
181
-    public function block($user_id)
182
-    {
183
-        if ( ! $user = $this->find($user_id)) 
184
-        {
185
-            \ErrorHandler::notFound('user');
186
-        }
187
-        if ( ! $this->hasGroup(['Admin']))
188
-        {
189
-            \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
192
-        {
193
-            \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
-        {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user->blocked = 1;
201
-        $user->save();
175
+	/**
176
+	 * Block the user.
177
+	 *
178
+	 * @param  integer $user_id
179
+	 * @return object
180
+	 */
181
+	public function block($user_id)
182
+	{
183
+		if ( ! $user = $this->find($user_id)) 
184
+		{
185
+			\ErrorHandler::notFound('user');
186
+		}
187
+		if ( ! $this->hasGroup(['Admin']))
188
+		{
189
+			\ErrorHandler::noPermissions();
190
+		}
191
+		else if (\Auth::id() == $user_id)
192
+		{
193
+			\ErrorHandler::noPermissions();
194
+		}
195
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
+		{
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user->blocked = 1;
201
+		$user->save();
202 202
         
203
-        return $user;
204
-    }
205
-
206
-    /**
207
-     * Unblock the user.
208
-     *
209
-     * @param  integer $user_id
210
-     * @return object
211
-     */
212
-    public function unblock($user_id)
213
-    {
214
-        if ( ! $this->hasGroup(['Admin']))
215
-        {
216
-            \ErrorHandler::noPermissions();
217
-        }
218
-
219
-        $user          = $this->find($user_id);
220
-        $user->blocked = 0;
221
-        $user->save();
222
-
223
-        return $user;
224
-    }
225
-
226
-    /**
227
-     * Send a reset link to the given user.
228
-     *
229
-     * @param  string  $email
230
-     * @return void
231
-     */
232
-    public function sendReset($email)
233
-    {
234
-        if ( ! $user = $this->model->where('email', $email)->first())
235
-        {
236
-            \ErrorHandler::notFound('email');
237
-        }
238
-
239
-        $token = \Password::getRepository()->create($user);
240
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
241
-    }
242
-
243
-    /**
244
-     * Reset the given user's password.
245
-     *
246
-     * @param  array  $credentials
247
-     * @return array
248
-     */
249
-    public function resetPassword($credentials)
250
-    {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
252
-            $user->password = $password;
253
-            $user->save();
254
-        });
255
-
256
-        switch ($response) {
257
-            case \Password::PASSWORD_RESET:
258
-                return 'success';
203
+		return $user;
204
+	}
205
+
206
+	/**
207
+	 * Unblock the user.
208
+	 *
209
+	 * @param  integer $user_id
210
+	 * @return object
211
+	 */
212
+	public function unblock($user_id)
213
+	{
214
+		if ( ! $this->hasGroup(['Admin']))
215
+		{
216
+			\ErrorHandler::noPermissions();
217
+		}
218
+
219
+		$user          = $this->find($user_id);
220
+		$user->blocked = 0;
221
+		$user->save();
222
+
223
+		return $user;
224
+	}
225
+
226
+	/**
227
+	 * Send a reset link to the given user.
228
+	 *
229
+	 * @param  string  $email
230
+	 * @return void
231
+	 */
232
+	public function sendReset($email)
233
+	{
234
+		if ( ! $user = $this->model->where('email', $email)->first())
235
+		{
236
+			\ErrorHandler::notFound('email');
237
+		}
238
+
239
+		$token = \Password::getRepository()->create($user);
240
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
241
+	}
242
+
243
+	/**
244
+	 * Reset the given user's password.
245
+	 *
246
+	 * @param  array  $credentials
247
+	 * @return array
248
+	 */
249
+	public function resetPassword($credentials)
250
+	{
251
+		$response = \Password::reset($credentials, function ($user, $password) {
252
+			$user->password = $password;
253
+			$user->save();
254
+		});
255
+
256
+		switch ($response) {
257
+			case \Password::PASSWORD_RESET:
258
+				return 'success';
259 259
                 
260
-            case \Password::INVALID_TOKEN:
261
-                \ErrorHandler::invalidResetToken('token');
262
-
263
-            case \Password::INVALID_PASSWORD:
264
-                \ErrorHandler::invalidResetPassword('email');
265
-
266
-            case \Password::INVALID_USER:
267
-                \ErrorHandler::notFound('user');
268
-
269
-            default:
270
-                \ErrorHandler::generalError();
271
-        }
272
-    }
273
-
274
-    /**
275
-     * Change the logged in user password.
276
-     *
277
-     * @param  array  $credentials
278
-     * @return void
279
-     */
280
-    public function changePassword($credentials)
281
-    {
282
-        $user = \Auth::user();
283
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
-        {
285
-            \ErrorHandler::invalidOldPassword();
286
-        }
287
-
288
-        $user->password = $credentials['password'];
289
-        $user->save();
290
-    }
291
-
292
-    /**
293
-     * Confirm email using the confirmation code.
294
-     *
295
-     * @param  string $confirmationCode
296
-     * @return void
297
-     */
298
-    public function confirmEmail($confirmationCode)
299
-    {
300
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
-        $user->confirmed         = 1;
302
-        $user->confirmation_code = null;
303
-        $user->save();
304
-    }
305
-
306
-    /**
307
-     * Send the confirmation mail.
308
-     *
309
-     * @param  string $email
310
-     * @return void
311
-     */
312
-    public function sendConfirmationEmail($email)
313
-    {
314
-        $user = $this->first(['email' => $email]);
315
-        if ($user->confirmed) 
316
-        {
317
-            \ErrorHandler::emailAlreadyConfirmed();
318
-        }
319
-
320
-        $user->confirmed         = 0;
321
-        $user->confirmation_code = sha1(microtime());
322
-        $user->save();
323
-        \Core::notifications()->notify($user, 'ConfirmEmail');
324
-    }
325
-
326
-    /**
327
-     * Paginate all users in the given group based on the given conditions.
328
-     * 
329
-     * @param  string  $groupName
330
-     * @param  array   $relations
331
-     * @param  integer $perPage
332
-     * @param  string  $sortBy
333
-     * @param  boolean $desc
334
-     * @return \Illuminate\Http\Response
335
-     */
336
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
-    {   
338
-        unset($conditions['page']);
339
-        $conditions = $this->constructConditions($conditions, $this->model);
340
-        $sort       = $desc ? 'desc' : 'asc';
341
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
-
343
-        $model->whereHas('groups', function($q) use ($groupName){
344
-            $q->where('name', $groupName);
345
-        });
260
+			case \Password::INVALID_TOKEN:
261
+				\ErrorHandler::invalidResetToken('token');
262
+
263
+			case \Password::INVALID_PASSWORD:
264
+				\ErrorHandler::invalidResetPassword('email');
265
+
266
+			case \Password::INVALID_USER:
267
+				\ErrorHandler::notFound('user');
268
+
269
+			default:
270
+				\ErrorHandler::generalError();
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * Change the logged in user password.
276
+	 *
277
+	 * @param  array  $credentials
278
+	 * @return void
279
+	 */
280
+	public function changePassword($credentials)
281
+	{
282
+		$user = \Auth::user();
283
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
+		{
285
+			\ErrorHandler::invalidOldPassword();
286
+		}
287
+
288
+		$user->password = $credentials['password'];
289
+		$user->save();
290
+	}
291
+
292
+	/**
293
+	 * Confirm email using the confirmation code.
294
+	 *
295
+	 * @param  string $confirmationCode
296
+	 * @return void
297
+	 */
298
+	public function confirmEmail($confirmationCode)
299
+	{
300
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
+		$user->confirmed         = 1;
302
+		$user->confirmation_code = null;
303
+		$user->save();
304
+	}
305
+
306
+	/**
307
+	 * Send the confirmation mail.
308
+	 *
309
+	 * @param  string $email
310
+	 * @return void
311
+	 */
312
+	public function sendConfirmationEmail($email)
313
+	{
314
+		$user = $this->first(['email' => $email]);
315
+		if ($user->confirmed) 
316
+		{
317
+			\ErrorHandler::emailAlreadyConfirmed();
318
+		}
319
+
320
+		$user->confirmed         = 0;
321
+		$user->confirmation_code = sha1(microtime());
322
+		$user->save();
323
+		\Core::notifications()->notify($user, 'ConfirmEmail');
324
+	}
325
+
326
+	/**
327
+	 * Paginate all users in the given group based on the given conditions.
328
+	 * 
329
+	 * @param  string  $groupName
330
+	 * @param  array   $relations
331
+	 * @param  integer $perPage
332
+	 * @param  string  $sortBy
333
+	 * @param  boolean $desc
334
+	 * @return \Illuminate\Http\Response
335
+	 */
336
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
+	{   
338
+		unset($conditions['page']);
339
+		$conditions = $this->constructConditions($conditions, $this->model);
340
+		$sort       = $desc ? 'desc' : 'asc';
341
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
+
343
+		$model->whereHas('groups', function($q) use ($groupName){
344
+			$q->where('name', $groupName);
345
+		});
346 346
 
347 347
         
348
-        if (count($conditions['conditionValues']))
349
-        {
350
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
-        }
352
-
353
-        if ($perPage) 
354
-        {
355
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
-        }
357
-
358
-        return $model->orderBy($sortBy, $sort)->get();
359
-    }
360
-
361
-    /**
362
-     * Save the given data to the logged in user.
363
-     *
364
-     * @param  array $credentials
365
-     * @return void
366
-     */
367
-    public function saveProfile($data) 
368
-    {
369
-        if (array_key_exists('profile_picture', $data)) 
370
-        {
371
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
-        }
348
+		if (count($conditions['conditionValues']))
349
+		{
350
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
+		}
352
+
353
+		if ($perPage) 
354
+		{
355
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
+		}
357
+
358
+		return $model->orderBy($sortBy, $sort)->get();
359
+	}
360
+
361
+	/**
362
+	 * Save the given data to the logged in user.
363
+	 *
364
+	 * @param  array $credentials
365
+	 * @return void
366
+	 */
367
+	public function saveProfile($data) 
368
+	{
369
+		if (array_key_exists('profile_picture', $data)) 
370
+		{
371
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
+		}
373 373
         
374
-        $data['id'] = \Auth::id();
375
-        $this->save($data);
376
-    }
377
-
378
-    /**
379
-     * Ensure access token hasn't expired or revoked.
380
-     * 
381
-     * @param  string $accessToken
382
-     * @return boolean
383
-     */
384
-    public function accessTokenExpiredOrRevoked($accessToken)
385
-    {
386
-
387
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
-        $data = new ValidationData();
389
-        $data->setCurrentTime(time());
390
-
391
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
-        {
393
-            return true;
394
-        }
395
-
396
-        return false;
397
-    }
374
+		$data['id'] = \Auth::id();
375
+		$this->save($data);
376
+	}
377
+
378
+	/**
379
+	 * Ensure access token hasn't expired or revoked.
380
+	 * 
381
+	 * @param  string $accessToken
382
+	 * @return boolean
383
+	 */
384
+	public function accessTokenExpiredOrRevoked($accessToken)
385
+	{
386
+
387
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
+		$data = new ValidationData();
389
+		$data->setCurrentTime(time());
390
+
391
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
+		{
393
+			return true;
394
+		}
395
+
396
+		return false;
397
+	}
398 398
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $user        = \Core::users()->find(\Auth::id(), $relations);
29 29
         foreach ($user->groups()->get() as $group)
30 30
         {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
31
+            $group->permissions->each(function($permission) use (&$permissions){
32 32
                 $permissions[$permission->model][$permission->id] = $permission->name;
33 33
             });
34 34
         }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52 52
         $permissions = [];
53 53
 
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
54
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
55 55
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56 56
         });
57 57
         
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function assignGroups($user_id, $group_ids)
82 82
     {
83
-        \DB::transaction(function () use ($user_id, $group_ids) {
83
+        \DB::transaction(function() use ($user_id, $group_ids) {
84 84
             $user = $this->find($user_id);
85 85
             $user->groups()->detach();
86 86
             $user->groups()->attach($group_ids);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         {
116 116
             \ErrorHandler::userIsBlocked();
117 117
         }
118
-        else if (! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
118
+        else if ( ! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
119 119
         {
120 120
             \ErrorHandler::emailNotConfirmed();
121 121
         }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function resetPassword($credentials)
250 250
     {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
251
+        $response = \Password::reset($credentials, function($user, $password) {
252 252
             $user->password = $password;
253 253
             $user->save();
254 254
         });
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -102,20 +102,16 @@  discard block
 block discarded – undo
102 102
         if ( ! $user = $this->first(['email' => $credentials['email']])) 
103 103
         {
104 104
             \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
105
+        } else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107 106
         {
108 107
             \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
108
+        } else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111 109
         {
112 110
             \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
111
+        } else if ($user->blocked)
115 112
         {
116 113
             \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if (! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
114
+        } else if (! env('DISABLE_CONFIRM_EMAIL') && ! $user->confirmed)
119 115
         {
120 116
             \ErrorHandler::emailNotConfirmed();
121 117
         }
@@ -143,8 +139,7 @@  discard block
 block discarded – undo
143 139
         {
144 140
             $data = ['email' => $user->email, 'password' => ''];
145 141
             return $this->register($data);
146
-        }
147
-        else
142
+        } else
148 143
         {
149 144
             if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150 145
             {
@@ -187,12 +182,10 @@  discard block
 block discarded – undo
187 182
         if ( ! $this->hasGroup(['Admin']))
188 183
         {
189 184
             \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
185
+        } else if (\Auth::id() == $user_id)
192 186
         {
193 187
             \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
188
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196 189
         {
197 190
             \ErrorHandler::noPermissions();
198 191
         }
Please login to merge, or discard this patch.
src/Modules/Acl/AclUser.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -7,119 +7,119 @@
 block discarded – undo
7 7
 
8 8
 class AclUser extends User {
9 9
 
10
-    use SoftDeletes, HasApiTokens;
11
-    protected $table    = 'users';
12
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
13
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
14
-    protected $guarded  = ['id'];
15
-    protected $fillable = ['profile_picture', 'name', 'email', 'password'];
16
-    public $searchable  = ['name', 'email'];
10
+	use SoftDeletes, HasApiTokens;
11
+	protected $table    = 'users';
12
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
13
+	protected $hidden   = ['password', 'remember_token','deleted_at'];
14
+	protected $guarded  = ['id'];
15
+	protected $fillable = ['profile_picture', 'name', 'email', 'password'];
16
+	public $searchable  = ['name', 'email'];
17 17
     
18
-    public function getCreatedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
-    }
22
-
23
-    public function getUpdatedAtAttribute($value)
24
-    {
25
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
26
-    }
27
-
28
-    public function getDeletedAtAttribute($value)
29
-    {
30
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
31
-    }
32
-
33
-    /**
34
-     * Encrypt the password attribute before
35
-     * saving it in the storage.
36
-     * 
37
-     * @param string $value 
38
-     */
39
-    public function setPasswordAttribute($value)
40
-    {
41
-        $this->attributes['password'] = bcrypt($value);
42
-    }
43
-
44
-    /**
45
-     * Get the entity's notifications.
46
-     */
47
-    public function notifications()
48
-    {
49
-        return $this->morphMany('\App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc');
50
-    }
51
-
52
-    /**
53
-     * Get the entity's read notifications.
54
-     */
55
-    public function readNotifications()
56
-    {
57
-        return $this->notifications()->whereNotNull('read_at');
58
-    }
59
-
60
-    /**
61
-     * Get the entity's unread notifications.
62
-     */
63
-    public function unreadNotifications()
64
-    {
65
-        return $this->notifications()->whereNull('read_at');
66
-    }
67
-
68
-    public function groups()
69
-    {
70
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
71
-    }
72
-
73
-    public function oauthClients()
74
-    {
75
-        return $this->hasMany('App\Modules\Acl\OauthClient', 'user_id');
76
-    }
77
-
78
-    /**
79
-     * Return fcm device tokens that will be used in sending fcm notifications.
80
-     * 
81
-     * @return array
82
-     */
83
-    public function routeNotificationForFCM()
84
-    {
85
-        $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]);
86
-        $tokens  = [];
87
-
88
-        foreach ($devices as $device) 
89
-        {
90
-            $accessToken = decrypt($device->access_token);
91
-
92
-            try
93
-            {
94
-                if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) 
95
-                {
96
-                    continue;
97
-                }
98
-
99
-                $tokens[] = $device->device_token;
100
-            } 
101
-            catch (\Exception $e) 
102
-            {
103
-                $device->forceDelete();
104
-            }
105
-        }
106
-
107
-        return $tokens;
108
-    }
109
-
110
-    /**
111
-     * The channels the user receives notification broadcasts on.
112
-     *
113
-     * @return string
114
-     */
115
-    public function receivesBroadcastNotificationsOn()
116
-    {
117
-        return 'users.' . $this->id;
118
-    }
18
+	public function getCreatedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
+	}
22
+
23
+	public function getUpdatedAtAttribute($value)
24
+	{
25
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
26
+	}
27
+
28
+	public function getDeletedAtAttribute($value)
29
+	{
30
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
31
+	}
32
+
33
+	/**
34
+	 * Encrypt the password attribute before
35
+	 * saving it in the storage.
36
+	 * 
37
+	 * @param string $value 
38
+	 */
39
+	public function setPasswordAttribute($value)
40
+	{
41
+		$this->attributes['password'] = bcrypt($value);
42
+	}
43
+
44
+	/**
45
+	 * Get the entity's notifications.
46
+	 */
47
+	public function notifications()
48
+	{
49
+		return $this->morphMany('\App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc');
50
+	}
51
+
52
+	/**
53
+	 * Get the entity's read notifications.
54
+	 */
55
+	public function readNotifications()
56
+	{
57
+		return $this->notifications()->whereNotNull('read_at');
58
+	}
59
+
60
+	/**
61
+	 * Get the entity's unread notifications.
62
+	 */
63
+	public function unreadNotifications()
64
+	{
65
+		return $this->notifications()->whereNull('read_at');
66
+	}
67
+
68
+	public function groups()
69
+	{
70
+		return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
71
+	}
72
+
73
+	public function oauthClients()
74
+	{
75
+		return $this->hasMany('App\Modules\Acl\OauthClient', 'user_id');
76
+	}
77
+
78
+	/**
79
+	 * Return fcm device tokens that will be used in sending fcm notifications.
80
+	 * 
81
+	 * @return array
82
+	 */
83
+	public function routeNotificationForFCM()
84
+	{
85
+		$devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]);
86
+		$tokens  = [];
87
+
88
+		foreach ($devices as $device) 
89
+		{
90
+			$accessToken = decrypt($device->access_token);
91
+
92
+			try
93
+			{
94
+				if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) 
95
+				{
96
+					continue;
97
+				}
98
+
99
+				$tokens[] = $device->device_token;
100
+			} 
101
+			catch (\Exception $e) 
102
+			{
103
+				$device->forceDelete();
104
+			}
105
+		}
106
+
107
+		return $tokens;
108
+	}
109
+
110
+	/**
111
+	 * The channels the user receives notification broadcasts on.
112
+	 *
113
+	 * @return string
114
+	 */
115
+	public function receivesBroadcastNotificationsOn()
116
+	{
117
+		return 'users.' . $this->id;
118
+	}
119 119
     
120
-    public static function boot()
121
-    {
122
-        parent::boot();
123
-        parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver'));
124
-    }
120
+	public static function boot()
121
+	{
122
+		parent::boot();
123
+		parent::observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver'));
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     use SoftDeletes, HasApiTokens;
11 11
     protected $table    = 'users';
12 12
     protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
13
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
13
+    protected $hidden   = ['password', 'remember_token', 'deleted_at'];
14 14
     protected $guarded  = ['id'];
15 15
     protected $fillable = ['profile_picture', 'name', 'email', 'password'];
16 16
     public $searchable  = ['name', 'email'];
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
     public function groups()
69 69
     {
70
-        return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
70
+        return $this->belongsToMany('\App\Modules\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
71 71
     }
72 72
 
73 73
     public function oauthClients()
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function receivesBroadcastNotificationsOn()
116 116
     {
117
-        return 'users.' . $this->id;
117
+        return 'users.'.$this->id;
118 118
     }
119 119
     
120 120
     public static function boot()
Please login to merge, or discard this patch.
src/Modules/Core/Console/Commands/GenerateDoc.php 2 patches
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -6,275 +6,275 @@
 block discarded – undo
6 6
 
7 7
 class GenerateDoc extends Command
8 8
 {
9
-    /**
10
-     * The name and signature of the console command.
11
-     *
12
-     * @var string
13
-     */
14
-    protected $signature = 'doc:generate';
9
+	/**
10
+	 * The name and signature of the console command.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $signature = 'doc:generate';
15 15
 
16
-    /**
17
-     * The console command description.
18
-     *
19
-     * @var string
20
-     */
21
-    protected $description = 'Generate api documentation';
16
+	/**
17
+	 * The console command description.
18
+	 *
19
+	 * @var string
20
+	 */
21
+	protected $description = 'Generate api documentation';
22 22
 
23
-    /**
24
-     * Create a new command instance.
25
-     *
26
-     * @return void
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct();
31
-    }
23
+	/**
24
+	 * Create a new command instance.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct();
31
+	}
32 32
 
33
-    /**
34
-     * Execute the console command.
35
-     *
36
-     * @return mixed
37
-     */
38
-    public function handle()
39
-    {
40
-        $docData           = [];
41
-        $docData['models'] = [];
42
-        $routes            = $this->getRoutes();
43
-        foreach ($routes as $route) 
44
-        {
45
-            if ($route) 
46
-            {
47
-                $actoinArray = explode('@', $route['action']);
48
-                if(array_get($actoinArray, 1, false))
49
-                {
50
-                    $controller       = $actoinArray[0];
51
-                    $method           = $actoinArray[1];
52
-                    $route['name']    = $method !== 'index' ? $method : 'list';
33
+	/**
34
+	 * Execute the console command.
35
+	 *
36
+	 * @return mixed
37
+	 */
38
+	public function handle()
39
+	{
40
+		$docData           = [];
41
+		$docData['models'] = [];
42
+		$routes            = $this->getRoutes();
43
+		foreach ($routes as $route) 
44
+		{
45
+			if ($route) 
46
+			{
47
+				$actoinArray = explode('@', $route['action']);
48
+				if(array_get($actoinArray, 1, false))
49
+				{
50
+					$controller       = $actoinArray[0];
51
+					$method           = $actoinArray[1];
52
+					$route['name']    = $method !== 'index' ? $method : 'list';
53 53
                     
54
-                    $reflectionClass  = new \ReflectionClass($controller);
55
-                    $reflectionMethod = $reflectionClass->getMethod($method);
56
-                    $classProperties  = $reflectionClass->getDefaultProperties();
57
-                    $skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
58
-                    $validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
54
+					$reflectionClass  = new \ReflectionClass($controller);
55
+					$reflectionMethod = $reflectionClass->getMethod($method);
56
+					$classProperties  = $reflectionClass->getDefaultProperties();
57
+					$skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
58
+					$validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
59 59
 
60
-                    $this->processDocBlock($route, $reflectionMethod);
61
-                    $this->getHeaders($route, $method, $skipLoginCheck);
62
-                    $this->getPostData($route, $reflectionMethod, $validationRules);
60
+					$this->processDocBlock($route, $reflectionMethod);
61
+					$this->getHeaders($route, $method, $skipLoginCheck);
62
+					$this->getPostData($route, $reflectionMethod, $validationRules);
63 63
 
64
-                    $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
64
+					$route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
65 65
 
66
-                    preg_match('/api\/([^#]+)\//iU', $route['uri'], $module);
67
-                    $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/' . $module[1] . '/') - 1)][] = $route;
66
+					preg_match('/api\/([^#]+)\//iU', $route['uri'], $module);
67
+					$docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/' . $module[1] . '/') - 1)][] = $route;
68 68
 
69
-                    $this->getModels($classProperties['model'], $docData);   
70
-                }
71
-            }
72
-        }
69
+					$this->getModels($classProperties['model'], $docData);   
70
+				}
71
+			}
72
+		}
73 73
         
74
-        $docData['errors'] = $this->getErrors();
75
-        \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData));
76
-    }
74
+		$docData['errors'] = $this->getErrors();
75
+		\File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData));
76
+	}
77 77
 
78
-    /**
79
-     * Get list of all registered routes.
80
-     * 
81
-     * @return collection
82
-     */
83
-    protected function getRoutes()
84
-    {
85
-        return collect(\Route::getRoutes())->map(function ($route) {
86
-            if (strpos($route->uri(), 'api') !== false) 
87
-            {
88
-                return [
89
-                    'method' => $route->methods()[0],
90
-                    'uri'    => $route->uri(),
91
-                    'action' => $route->getActionName(),
92
-                    'prefix' => $route->getPrefix()
93
-                ];
94
-            }
95
-            return false;
96
-        })->all();
97
-    }
78
+	/**
79
+	 * Get list of all registered routes.
80
+	 * 
81
+	 * @return collection
82
+	 */
83
+	protected function getRoutes()
84
+	{
85
+		return collect(\Route::getRoutes())->map(function ($route) {
86
+			if (strpos($route->uri(), 'api') !== false) 
87
+			{
88
+				return [
89
+					'method' => $route->methods()[0],
90
+					'uri'    => $route->uri(),
91
+					'action' => $route->getActionName(),
92
+					'prefix' => $route->getPrefix()
93
+				];
94
+			}
95
+			return false;
96
+		})->all();
97
+	}
98 98
 
99
-    /**
100
-     * Generate headers for the given route.
101
-     * 
102
-     * @param  array  &$route
103
-     * @param  string $method
104
-     * @param  array  $skipLoginCheck
105
-     * @return void
106
-     */
107
-    protected function getHeaders(&$route, $method, $skipLoginCheck)
108
-    {
109
-        $route['headers'] = [
110
-        'Accept'         => 'application/json',
111
-        'Content-Type'   => 'application/json',
112
-        'locale'         => 'The language of the returned data: ar, en or all.',
113
-        'time-zone-diff' => 'Timezone difference between UTC and Local Time',
114
-        ];
99
+	/**
100
+	 * Generate headers for the given route.
101
+	 * 
102
+	 * @param  array  &$route
103
+	 * @param  string $method
104
+	 * @param  array  $skipLoginCheck
105
+	 * @return void
106
+	 */
107
+	protected function getHeaders(&$route, $method, $skipLoginCheck)
108
+	{
109
+		$route['headers'] = [
110
+		'Accept'         => 'application/json',
111
+		'Content-Type'   => 'application/json',
112
+		'locale'         => 'The language of the returned data: ar, en or all.',
113
+		'time-zone-diff' => 'Timezone difference between UTC and Local Time',
114
+		];
115 115
 
116 116
 
117
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
118
-        {
119
-            $route['headers']['Authorization'] = 'Bearer {token}';
120
-        }
121
-    }
117
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
118
+		{
119
+			$route['headers']['Authorization'] = 'Bearer {token}';
120
+		}
121
+	}
122 122
 
123
-    /**
124
-     * Generate description and params for the given route
125
-     * based on the docblock.
126
-     * 
127
-     * @param  array  &$route
128
-     * @param  object $reflectionMethod]
129
-     * @return void
130
-     */
131
-    protected function processDocBlock(&$route, $reflectionMethod)
132
-    {
133
-        $factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
134
-        $docblock                = $factory->create($reflectionMethod->getDocComment());
135
-        $route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
136
-        $params                  = $docblock->getTagsByName('param');
137
-        $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
138
-        foreach ($params as $param) 
139
-        {
140
-            $name = $param->getVariableName();
141
-            if ($name !== 'request') 
142
-            {
143
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
144
-            }
145
-        }
146
-    }
123
+	/**
124
+	 * Generate description and params for the given route
125
+	 * based on the docblock.
126
+	 * 
127
+	 * @param  array  &$route
128
+	 * @param  object $reflectionMethod]
129
+	 * @return void
130
+	 */
131
+	protected function processDocBlock(&$route, $reflectionMethod)
132
+	{
133
+		$factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
134
+		$docblock                = $factory->create($reflectionMethod->getDocComment());
135
+		$route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
136
+		$params                  = $docblock->getTagsByName('param');
137
+		$route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
138
+		foreach ($params as $param) 
139
+		{
140
+			$name = $param->getVariableName();
141
+			if ($name !== 'request') 
142
+			{
143
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
144
+			}
145
+		}
146
+	}
147 147
 
148
-    /**
149
-     * Generate post body for the given route.
150
-     * 
151
-     * @param  array  &$route
152
-     * @param  object $reflectionMethod
153
-     * @param  array  $validationRules
154
-     * @return void
155
-     */
156
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
157
-    {
158
-        if ($route['method'] == 'POST') 
159
-        {
160
-            $body = $this->getMethodBody($reflectionMethod);
148
+	/**
149
+	 * Generate post body for the given route.
150
+	 * 
151
+	 * @param  array  &$route
152
+	 * @param  object $reflectionMethod
153
+	 * @param  array  $validationRules
154
+	 * @return void
155
+	 */
156
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
157
+	{
158
+		if ($route['method'] == 'POST') 
159
+		{
160
+			$body = $this->getMethodBody($reflectionMethod);
161 161
 
162
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
163
-            if (count($match)) 
164
-            {
165
-                if ($match[1] == '$this->validationRules')
166
-                {
167
-                    $route['body'] = $validationRules;
168
-                }
169
-                else
170
-                {
171
-                    $route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
172
-                }
162
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
163
+			if (count($match)) 
164
+			{
165
+				if ($match[1] == '$this->validationRules')
166
+				{
167
+					$route['body'] = $validationRules;
168
+				}
169
+				else
170
+				{
171
+					$route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
172
+				}
173 173
 
174
-                foreach ($route['body'] as &$rule) 
175
-                {
176
-                    if(strpos($rule, 'unique'))
177
-                    {
178
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
179
-                    }
180
-                    elseif(strpos($rule, 'exists'))
181
-                    {
182
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
183
-                    }
184
-                }
185
-            }
186
-            else
187
-            {
188
-                $route['body'] = 'conditions';
189
-            }
190
-        }
191
-    }
174
+				foreach ($route['body'] as &$rule) 
175
+				{
176
+					if(strpos($rule, 'unique'))
177
+					{
178
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
179
+					}
180
+					elseif(strpos($rule, 'exists'))
181
+					{
182
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
183
+					}
184
+				}
185
+			}
186
+			else
187
+			{
188
+				$route['body'] = 'conditions';
189
+			}
190
+		}
191
+	}
192 192
 
193
-    /**
194
-     * Generate application errors.
195
-     * 
196
-     * @return array
197
-     */
198
-    protected function getErrors()
199
-    {
200
-        $errors          = [];
201
-        $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
202
-        foreach ($reflectionClass->getMethods() as $method) 
203
-        {
204
-            $methodName       = $method->getName();
205
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
206
-            $body             = $this->getMethodBody($reflectionMethod);
193
+	/**
194
+	 * Generate application errors.
195
+	 * 
196
+	 * @return array
197
+	 */
198
+	protected function getErrors()
199
+	{
200
+		$errors          = [];
201
+		$reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
202
+		foreach ($reflectionClass->getMethods() as $method) 
203
+		{
204
+			$methodName       = $method->getName();
205
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
206
+			$body             = $this->getMethodBody($reflectionMethod);
207 207
 
208
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
208
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
209 209
 
210
-            if (count($match)) 
211
-            {
212
-                $errors[$match[1]][] = $methodName;
213
-            }
214
-        }
210
+			if (count($match)) 
211
+			{
212
+				$errors[$match[1]][] = $methodName;
213
+			}
214
+		}
215 215
 
216
-        return $errors;
217
-    }
216
+		return $errors;
217
+	}
218 218
 
219
-    /**
220
-     * Get the given method body code.
221
-     * 
222
-     * @param  object $reflectionMethod
223
-     * @return string
224
-     */
225
-    protected function getMethodBody($reflectionMethod)
226
-    {
227
-        $filename   = $reflectionMethod->getFileName();
228
-        $start_line = $reflectionMethod->getStartLine() - 1;
229
-        $end_line   = $reflectionMethod->getEndLine();
230
-        $length     = $end_line - $start_line;         
231
-        $source     = file($filename);
232
-        $body       = implode("", array_slice($source, $start_line, $length));
233
-        $body       = trim(preg_replace('/\s+/', '', $body));
219
+	/**
220
+	 * Get the given method body code.
221
+	 * 
222
+	 * @param  object $reflectionMethod
223
+	 * @return string
224
+	 */
225
+	protected function getMethodBody($reflectionMethod)
226
+	{
227
+		$filename   = $reflectionMethod->getFileName();
228
+		$start_line = $reflectionMethod->getStartLine() - 1;
229
+		$end_line   = $reflectionMethod->getEndLine();
230
+		$length     = $end_line - $start_line;         
231
+		$source     = file($filename);
232
+		$body       = implode("", array_slice($source, $start_line, $length));
233
+		$body       = trim(preg_replace('/\s+/', '', $body));
234 234
 
235
-        return $body;
236
-    }
235
+		return $body;
236
+	}
237 237
 
238
-    /**
239
-     * Get example object of all availble models.
240
-     * 
241
-     * @param  string $modelName
242
-     * @param  array  $docData
243
-     * @return string
244
-     */
245
-    protected function getModels($modelName, &$docData)
246
-    {
247
-        if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
248
-        {
249
-            $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
250
-            $model      = factory($modelClass)->make();
251
-            $modelArr   = $model->toArray();
238
+	/**
239
+	 * Get example object of all availble models.
240
+	 * 
241
+	 * @param  string $modelName
242
+	 * @param  array  $docData
243
+	 * @return string
244
+	 */
245
+	protected function getModels($modelName, &$docData)
246
+	{
247
+		if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
248
+		{
249
+			$modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
250
+			$model      = factory($modelClass)->make();
251
+			$modelArr   = $model->toArray();
252 252
 
253
-            if ( $model->trans && ! $model->trans->count()) 
254
-            {
255
-                $modelArr['trans'] = [
256
-                    'en' => factory($modelClass . 'Translation')->make()->toArray()
257
-                ];
258
-            }
253
+			if ( $model->trans && ! $model->trans->count()) 
254
+			{
255
+				$modelArr['trans'] = [
256
+					'en' => factory($modelClass . 'Translation')->make()->toArray()
257
+				];
258
+			}
259 259
 
260
-            $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
261
-        }
262
-    }
260
+			$docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
261
+		}
262
+	}
263 263
 
264
-    /**
265
-     * Get the route response object type.
266
-     * 
267
-     * @param  string $modelName
268
-     * @param  string $method
269
-     * @param  string $returnDocBlock
270
-     * @return array
271
-     */
272
-    protected function getResponseObject($modelName, $method, $returnDocBlock)
273
-    {
274
-        $config    = \CoreConfig::getConfig();
275
-        $relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
276
-        $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
264
+	/**
265
+	 * Get the route response object type.
266
+	 * 
267
+	 * @param  string $modelName
268
+	 * @param  string $method
269
+	 * @param  string $returnDocBlock
270
+	 * @return array
271
+	 */
272
+	protected function getResponseObject($modelName, $method, $returnDocBlock)
273
+	{
274
+		$config    = \CoreConfig::getConfig();
275
+		$relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
276
+		$modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
277 277
 
278
-        return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
279
-    }
278
+		return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
279
+	}
280 280
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             if ($route) 
46 46
             {
47 47
                 $actoinArray = explode('@', $route['action']);
48
-                if(array_get($actoinArray, 1, false))
48
+                if (array_get($actoinArray, 1, false))
49 49
                 {
50 50
                     $controller       = $actoinArray[0];
51 51
                     $method           = $actoinArray[1];
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                     $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
65 65
 
66 66
                     preg_match('/api\/([^#]+)\//iU', $route['uri'], $module);
67
-                    $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/' . $module[1] . '/') - 1)][] = $route;
67
+                    $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/'.$module[1].'/') - 1)][] = $route;
68 68
 
69 69
                     $this->getModels($classProperties['model'], $docData);   
70 70
                 }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     protected function getRoutes()
84 84
     {
85
-        return collect(\Route::getRoutes())->map(function ($route) {
85
+        return collect(\Route::getRoutes())->map(function($route) {
86 86
             if (strpos($route->uri(), 'api') !== false) 
87 87
             {
88 88
                 return [
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         ];
115 115
 
116 116
 
117
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
117
+        if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
118 118
         {
119 119
             $route['headers']['Authorization'] = 'Bearer {token}';
120 120
         }
@@ -168,16 +168,16 @@  discard block
 block discarded – undo
168 168
                 }
169 169
                 else
170 170
                 {
171
-                    $route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
171
+                    $route['body'] = eval('return '.str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]).';');
172 172
                 }
173 173
 
174 174
                 foreach ($route['body'] as &$rule) 
175 175
                 {
176
-                    if(strpos($rule, 'unique'))
176
+                    if (strpos($rule, 'unique'))
177 177
                     {
178 178
                         $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
179 179
                     }
180
-                    elseif(strpos($rule, 'exists'))
180
+                    elseif (strpos($rule, 'exists'))
181 181
                     {
182 182
                         $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
183 183
                     }
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
             $model      = factory($modelClass)->make();
251 251
             $modelArr   = $model->toArray();
252 252
 
253
-            if ( $model->trans && ! $model->trans->count()) 
253
+            if ($model->trans && ! $model->trans->count()) 
254 254
             {
255 255
                 $modelArr['trans'] = [
256
-                    'en' => factory($modelClass . 'Translation')->make()->toArray()
256
+                    'en' => factory($modelClass.'Translation')->make()->toArray()
257 257
                 ];
258 258
             }
259 259
 
Please login to merge, or discard this patch.