Completed
Push — master ( 456045...7e51b9 )
by Sherif
04:39
created
src/Modules/Acl/Repositories/UserRepository.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     /**
62 62
      * Check if the logged in user has the given group.
63 63
      * 
64
-     * @param  array $groups
64
+     * @param  string[] $groups
65 65
      * @param  mixed $user
66 66
      * @return boolean
67 67
      */
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * 
156 156
      * @param  array   $credentials
157 157
      * @param  boolean $skipConfirmEmail
158
-     * @return array
158
+     * @return boolean
159 159
      */
160 160
     public function register($credentials, $skipConfirmEmail = false)
161 161
     {
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * Reset the given user's password.
247 247
      *
248 248
      * @param  array  $credentials
249
-     * @return array
249
+     * @return string|null
250 250
      */
251 251
     public function resetPassword($credentials)
252 252
     {
Please login to merge, or discard this patch.
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -5,414 +5,414 @@
 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  mixed  $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  mixed  $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  array $groups
65
-     * @param  mixed $user
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 $userId    
78
-     * @param  array   $groupIds
79
-     * @return object
80
-     */
81
-    public function assignGroups($userId, $groupIds)
82
-    {
83
-        \DB::transaction(function () use ($userId, $groupIds) {
84
-            $user = $this->find($userId);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($groupIds);
87
-        });
88
-
89
-        return $this->find($userId);
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 ( ! config('skeleton.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  string $authCode
130
-     * @param  string $accessToken
131
-     * @param  string $type
132
-     * @return array
133
-     */
134
-    public function loginSocial($authCode, $accessToken, $type)
135
-    {
136
-        $access_token = $authCode ? array_get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
137
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
138
-
139
-        if ( ! $user->email)
140
-        {
141
-            \ErrorHandler::noSocialEmail();
142
-        }
143
-
144
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
145
-        {
146
-            $this->register(['email' => $user->email, 'password' => ''], true);
147
-        }
148
-
149
-        $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
150
-        return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
151
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  array $groups
65
+	 * @param  mixed $user
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 $userId    
78
+	 * @param  array   $groupIds
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($userId, $groupIds)
82
+	{
83
+		\DB::transaction(function () use ($userId, $groupIds) {
84
+			$user = $this->find($userId);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($groupIds);
87
+		});
88
+
89
+		return $this->find($userId);
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 ( ! config('skeleton.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  string $authCode
130
+	 * @param  string $accessToken
131
+	 * @param  string $type
132
+	 * @return array
133
+	 */
134
+	public function loginSocial($authCode, $accessToken, $type)
135
+	{
136
+		$access_token = $authCode ? array_get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
137
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
138
+
139
+		if ( ! $user->email)
140
+		{
141
+			\ErrorHandler::noSocialEmail();
142
+		}
143
+
144
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
145
+		{
146
+			$this->register(['email' => $user->email, 'password' => ''], true);
147
+		}
148
+
149
+		$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
150
+		return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
151
+	}
152 152
     
153
-    /**
154
-     * Handle a registration request.
155
-     * 
156
-     * @param  array   $credentials
157
-     * @param  boolean $skipConfirmEmail
158
-     * @return array
159
-     */
160
-    public function register($credentials, $skipConfirmEmail = false)
161
-    {
162
-        $user = $this->save($credentials);
163
-
164
-        if ($skipConfirmEmail) 
165
-        {
166
-            $user->confirmed = 1;
167
-            $user->save();
168
-        }
169
-        else if ( ! config('skeleton.disable_confirm_email'))  
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-
174
-        return $user;
175
-    }
153
+	/**
154
+	 * Handle a registration request.
155
+	 * 
156
+	 * @param  array   $credentials
157
+	 * @param  boolean $skipConfirmEmail
158
+	 * @return array
159
+	 */
160
+	public function register($credentials, $skipConfirmEmail = false)
161
+	{
162
+		$user = $this->save($credentials);
163
+
164
+		if ($skipConfirmEmail) 
165
+		{
166
+			$user->confirmed = 1;
167
+			$user->save();
168
+		}
169
+		else if ( ! config('skeleton.disable_confirm_email'))  
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+
174
+		return $user;
175
+	}
176 176
     
177
-    /**
178
-     * Block the user.
179
-     *
180
-     * @param  integer $userId
181
-     * @return object
182
-     */
183
-    public function block($userId)
184
-    {
185
-        if ( ! $user = $this->find($userId)) 
186
-        {
187
-            \ErrorHandler::notFound('user');
188
-        }
189
-        if ( ! $this->hasGroup(['Admin']))
190
-        {
191
-            \ErrorHandler::noPermissions();
192
-        }
193
-        else if (\Auth::id() == $userId)
194
-        {
195
-            \ErrorHandler::noPermissions();
196
-        }
197
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
198
-        {
199
-            \ErrorHandler::noPermissions();
200
-        }
201
-
202
-        $user->blocked = 1;
203
-        $user->save();
177
+	/**
178
+	 * Block the user.
179
+	 *
180
+	 * @param  integer $userId
181
+	 * @return object
182
+	 */
183
+	public function block($userId)
184
+	{
185
+		if ( ! $user = $this->find($userId)) 
186
+		{
187
+			\ErrorHandler::notFound('user');
188
+		}
189
+		if ( ! $this->hasGroup(['Admin']))
190
+		{
191
+			\ErrorHandler::noPermissions();
192
+		}
193
+		else if (\Auth::id() == $userId)
194
+		{
195
+			\ErrorHandler::noPermissions();
196
+		}
197
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
198
+		{
199
+			\ErrorHandler::noPermissions();
200
+		}
201
+
202
+		$user->blocked = 1;
203
+		$user->save();
204 204
         
205
-        return $user;
206
-    }
207
-
208
-    /**
209
-     * Unblock the user.
210
-     *
211
-     * @param  integer $userId
212
-     * @return object
213
-     */
214
-    public function unblock($userId)
215
-    {
216
-        if ( ! $this->hasGroup(['Admin']))
217
-        {
218
-            \ErrorHandler::noPermissions();
219
-        }
220
-
221
-        $user          = $this->find($userId);
222
-        $user->blocked = 0;
223
-        $user->save();
224
-
225
-        return $user;
226
-    }
227
-
228
-    /**
229
-     * Send a reset link to the given user.
230
-     *
231
-     * @param  string  $email
232
-     * @return void
233
-     */
234
-    public function sendReset($email)
235
-    {
236
-        if ( ! $user = $this->model->where('email', $email)->first())
237
-        {
238
-            \ErrorHandler::notFound('email');
239
-        }
240
-
241
-        $token = \Password::getRepository()->create($user);
242
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
243
-    }
244
-
245
-    /**
246
-     * Reset the given user's password.
247
-     *
248
-     * @param  array  $credentials
249
-     * @return array
250
-     */
251
-    public function resetPassword($credentials)
252
-    {
253
-        $response = \Password::reset($credentials, function ($user, $password) {
254
-            $user->password = $password;
255
-            $user->save();
256
-        });
257
-
258
-        switch ($response) {
259
-            case \Password::PASSWORD_RESET:
260
-                return 'success';
205
+		return $user;
206
+	}
207
+
208
+	/**
209
+	 * Unblock the user.
210
+	 *
211
+	 * @param  integer $userId
212
+	 * @return object
213
+	 */
214
+	public function unblock($userId)
215
+	{
216
+		if ( ! $this->hasGroup(['Admin']))
217
+		{
218
+			\ErrorHandler::noPermissions();
219
+		}
220
+
221
+		$user          = $this->find($userId);
222
+		$user->blocked = 0;
223
+		$user->save();
224
+
225
+		return $user;
226
+	}
227
+
228
+	/**
229
+	 * Send a reset link to the given user.
230
+	 *
231
+	 * @param  string  $email
232
+	 * @return void
233
+	 */
234
+	public function sendReset($email)
235
+	{
236
+		if ( ! $user = $this->model->where('email', $email)->first())
237
+		{
238
+			\ErrorHandler::notFound('email');
239
+		}
240
+
241
+		$token = \Password::getRepository()->create($user);
242
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
243
+	}
244
+
245
+	/**
246
+	 * Reset the given user's password.
247
+	 *
248
+	 * @param  array  $credentials
249
+	 * @return array
250
+	 */
251
+	public function resetPassword($credentials)
252
+	{
253
+		$response = \Password::reset($credentials, function ($user, $password) {
254
+			$user->password = $password;
255
+			$user->save();
256
+		});
257
+
258
+		switch ($response) {
259
+			case \Password::PASSWORD_RESET:
260
+				return 'success';
261 261
                 
262
-            case \Password::INVALID_TOKEN:
263
-                \ErrorHandler::invalidResetToken('token');
264
-
265
-            case \Password::INVALID_PASSWORD:
266
-                \ErrorHandler::invalidResetPassword('email');
267
-
268
-            case \Password::INVALID_USER:
269
-                \ErrorHandler::notFound('user');
270
-
271
-            default:
272
-                \ErrorHandler::generalError();
273
-        }
274
-    }
275
-
276
-    /**
277
-     * Change the logged in user password.
278
-     *
279
-     * @param  array  $credentials
280
-     * @return void
281
-     */
282
-    public function changePassword($credentials)
283
-    {
284
-        $user = \Auth::user();
285
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
286
-        {
287
-            \ErrorHandler::invalidOldPassword();
288
-        }
289
-
290
-        $user->password = $credentials['password'];
291
-        $user->save();
292
-    }
293
-
294
-    /**
295
-     * Confirm email using the confirmation code.
296
-     *
297
-     * @param  string $confirmationCode
298
-     * @return void
299
-     */
300
-    public function confirmEmail($confirmationCode)
301
-    {
302
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
303
-        $user->confirmed         = 1;
304
-        $user->confirmation_code = null;
305
-        $user->save();
306
-    }
307
-
308
-    /**
309
-     * Send the confirmation mail.
310
-     *
311
-     * @param  string $email
312
-     * @return void
313
-     */
314
-    public function sendConfirmationEmail($email)
315
-    {
316
-        $user = $this->first(['email' => $email]);
317
-        if ($user->confirmed) 
318
-        {
319
-            \ErrorHandler::emailAlreadyConfirmed();
320
-        }
321
-
322
-        $user->confirmed         = 0;
323
-        $user->confirmation_code = sha1(microtime());
324
-        $user->save();
325
-        \Core::notifications()->notify($user, 'ConfirmEmail');
326
-    }
327
-
328
-    /**
329
-     * Paginate all users in the given group based on the given conditions.
330
-     * 
331
-     * @param  string  $groupName
332
-     * @param  array   $relations
333
-     * @param  integer $perPage
334
-     * @param  string  $sortBy
335
-     * @param  boolean $desc
336
-     * @return \Illuminate\Http\Response
337
-     */
338
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
339
-    {   
340
-        unset($conditions['page']);
341
-        $conditions = $this->constructConditions($conditions, $this->model);
342
-        $sort       = $desc ? 'desc' : 'asc';
343
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
344
-
345
-        $model->whereHas('groups', function($q) use ($groupName){
346
-            $q->where('name', $groupName);
347
-        });
262
+			case \Password::INVALID_TOKEN:
263
+				\ErrorHandler::invalidResetToken('token');
264
+
265
+			case \Password::INVALID_PASSWORD:
266
+				\ErrorHandler::invalidResetPassword('email');
267
+
268
+			case \Password::INVALID_USER:
269
+				\ErrorHandler::notFound('user');
270
+
271
+			default:
272
+				\ErrorHandler::generalError();
273
+		}
274
+	}
275
+
276
+	/**
277
+	 * Change the logged in user password.
278
+	 *
279
+	 * @param  array  $credentials
280
+	 * @return void
281
+	 */
282
+	public function changePassword($credentials)
283
+	{
284
+		$user = \Auth::user();
285
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
286
+		{
287
+			\ErrorHandler::invalidOldPassword();
288
+		}
289
+
290
+		$user->password = $credentials['password'];
291
+		$user->save();
292
+	}
293
+
294
+	/**
295
+	 * Confirm email using the confirmation code.
296
+	 *
297
+	 * @param  string $confirmationCode
298
+	 * @return void
299
+	 */
300
+	public function confirmEmail($confirmationCode)
301
+	{
302
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
303
+		$user->confirmed         = 1;
304
+		$user->confirmation_code = null;
305
+		$user->save();
306
+	}
307
+
308
+	/**
309
+	 * Send the confirmation mail.
310
+	 *
311
+	 * @param  string $email
312
+	 * @return void
313
+	 */
314
+	public function sendConfirmationEmail($email)
315
+	{
316
+		$user = $this->first(['email' => $email]);
317
+		if ($user->confirmed) 
318
+		{
319
+			\ErrorHandler::emailAlreadyConfirmed();
320
+		}
321
+
322
+		$user->confirmed         = 0;
323
+		$user->confirmation_code = sha1(microtime());
324
+		$user->save();
325
+		\Core::notifications()->notify($user, 'ConfirmEmail');
326
+	}
327
+
328
+	/**
329
+	 * Paginate all users in the given group based on the given conditions.
330
+	 * 
331
+	 * @param  string  $groupName
332
+	 * @param  array   $relations
333
+	 * @param  integer $perPage
334
+	 * @param  string  $sortBy
335
+	 * @param  boolean $desc
336
+	 * @return \Illuminate\Http\Response
337
+	 */
338
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
339
+	{   
340
+		unset($conditions['page']);
341
+		$conditions = $this->constructConditions($conditions, $this->model);
342
+		$sort       = $desc ? 'desc' : 'asc';
343
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
344
+
345
+		$model->whereHas('groups', function($q) use ($groupName){
346
+			$q->where('name', $groupName);
347
+		});
348 348
 
349 349
         
350
-        if (count($conditions['conditionValues']))
351
-        {
352
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
353
-        }
354
-
355
-        if ($perPage) 
356
-        {
357
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
358
-        }
359
-
360
-        return $model->orderBy($sortBy, $sort)->get();
361
-    }
362
-
363
-    /**
364
-     * Save the given data to the logged in user.
365
-     *
366
-     * @param  array $data
367
-     * @return void
368
-     */
369
-    public function saveProfile($data) 
370
-    {
371
-        if (array_key_exists('profile_picture', $data)) 
372
-        {
373
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
374
-        }
350
+		if (count($conditions['conditionValues']))
351
+		{
352
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
353
+		}
354
+
355
+		if ($perPage) 
356
+		{
357
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
358
+		}
359
+
360
+		return $model->orderBy($sortBy, $sort)->get();
361
+	}
362
+
363
+	/**
364
+	 * Save the given data to the logged in user.
365
+	 *
366
+	 * @param  array $data
367
+	 * @return void
368
+	 */
369
+	public function saveProfile($data) 
370
+	{
371
+		if (array_key_exists('profile_picture', $data)) 
372
+		{
373
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
374
+		}
375 375
         
376
-        $data['id'] = \Auth::id();
377
-        $this->save($data);
378
-    }
379
-
380
-    /**
381
-     * Ensure access token hasn't expired or revoked.
382
-     * 
383
-     * @param  oject $accessToken
384
-     * @return boolean
385
-     */
386
-    public function accessTokenExpiredOrRevoked($accessToken)
387
-    {
388
-
389
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
390
-        $data                  = new ValidationData();
391
-        $data->setCurrentTime(time());
392
-
393
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
394
-        {
395
-            return true;
396
-        }
397
-
398
-        return false;
399
-    }
400
-
401
-    /**
402
-     * Revoke the given access token and all 
403
-     * associated refresh tokens.
404
-     *
405
-     * @param  oject $accessToken
406
-     * @return void
407
-     */
408
-    public function revokeAccessToken($accessToken)
409
-    {
410
-        \DB::table('oauth_refresh_tokens')
411
-            ->where('access_token_id', $accessToken->id)
412
-            ->update([
413
-                'revoked' => true
414
-            ]);
415
-
416
-        $accessToken->revoke();
417
-    }
376
+		$data['id'] = \Auth::id();
377
+		$this->save($data);
378
+	}
379
+
380
+	/**
381
+	 * Ensure access token hasn't expired or revoked.
382
+	 * 
383
+	 * @param  oject $accessToken
384
+	 * @return boolean
385
+	 */
386
+	public function accessTokenExpiredOrRevoked($accessToken)
387
+	{
388
+
389
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
390
+		$data                  = new ValidationData();
391
+		$data->setCurrentTime(time());
392
+
393
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
394
+		{
395
+			return true;
396
+		}
397
+
398
+		return false;
399
+	}
400
+
401
+	/**
402
+	 * Revoke the given access token and all 
403
+	 * associated refresh tokens.
404
+	 *
405
+	 * @param  oject $accessToken
406
+	 * @return void
407
+	 */
408
+	public function revokeAccessToken($accessToken)
409
+	{
410
+		\DB::table('oauth_refresh_tokens')
411
+			->where('access_token_id', $accessToken->id)
412
+			->update([
413
+				'revoked' => true
414
+			]);
415
+
416
+		$accessToken->revoke();
417
+	}
418 418
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Repositories/PushNotificationDeviceRepository.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -7,56 +7,56 @@
 block discarded – undo
7 7
 
8 8
 class PushNotificationDeviceRepository extends AbstractRepository
9 9
 {
10
-    /**
11
-    * Return the model full namespace.
12
-    * 
13
-    * @return string
14
-    */
15
-    protected function getModel()
16
-    {
17
-        return 'App\Modules\Notifications\PushNotificationDevice';
18
-    }
19
-
20
-    /**
21
-     * Register the given device to the logged in user.
22
-     *
23
-     * @param  array $data
24
-     * @return void
25
-     */
26
-    public function registerDevice($data)
27
-    {
28
-        $data['access_token'] = \Auth::user()->token();
29
-        $data['user_id']      = \Auth::id();
30
-        if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) 
31
-        {
32
-            $data['id'] = $device->id;
33
-        }
34
-
35
-        return $this->save($data);
36
-    }
37
-
38
-    /**
39
-     * Generate the given message data.
40
-     *
41
-     * @param  string $title
42
-     * @param  string $message
43
-     * @param  array  $data
44
-     * @return void
45
-     */
46
-    public function generateMessageData($title, $message, $data = [])
47
-    {
48
-        $optionBuilder       = new OptionsBuilder();
49
-        $notificationBuilder = new PayloadNotificationBuilder($title);
50
-        $dataBuilder         = new PayloadDataBuilder();
51
-
52
-        $optionBuilder->setTimeToLive(60*20);
53
-        $notificationBuilder->setBody($message);
54
-        $dataBuilder->addData($data);
55
-
56
-        $options             = $optionBuilder->build();
57
-        $notification        = $notificationBuilder->build();
58
-        $data                = $dataBuilder->build();
59
-
60
-        return compact('options', 'notification', 'data');
61
-    }
10
+	/**
11
+	 * Return the model full namespace.
12
+	 * 
13
+	 * @return string
14
+	 */
15
+	protected function getModel()
16
+	{
17
+		return 'App\Modules\Notifications\PushNotificationDevice';
18
+	}
19
+
20
+	/**
21
+	 * Register the given device to the logged in user.
22
+	 *
23
+	 * @param  array $data
24
+	 * @return void
25
+	 */
26
+	public function registerDevice($data)
27
+	{
28
+		$data['access_token'] = \Auth::user()->token();
29
+		$data['user_id']      = \Auth::id();
30
+		if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) 
31
+		{
32
+			$data['id'] = $device->id;
33
+		}
34
+
35
+		return $this->save($data);
36
+	}
37
+
38
+	/**
39
+	 * Generate the given message data.
40
+	 *
41
+	 * @param  string $title
42
+	 * @param  string $message
43
+	 * @param  array  $data
44
+	 * @return void
45
+	 */
46
+	public function generateMessageData($title, $message, $data = [])
47
+	{
48
+		$optionBuilder       = new OptionsBuilder();
49
+		$notificationBuilder = new PayloadNotificationBuilder($title);
50
+		$dataBuilder         = new PayloadDataBuilder();
51
+
52
+		$optionBuilder->setTimeToLive(60*20);
53
+		$notificationBuilder->setBody($message);
54
+		$dataBuilder->addData($data);
55
+
56
+		$options             = $optionBuilder->build();
57
+		$notification        = $notificationBuilder->build();
58
+		$data                = $dataBuilder->build();
59
+
60
+		return compact('options', 'notification', 'data');
61
+	}
62 62
 }
Please login to merge, or discard this patch.
src/Modules/Core/Console/Commands/GenerateDoc.php 1 patch
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -6,274 +6,274 @@
 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
-    public function __construct()
27
-    {
28
-        parent::__construct();
29
-    }
23
+	/**
24
+	 * Create a new command instance.
25
+	 */
26
+	public function __construct()
27
+	{
28
+		parent::__construct();
29
+	}
30 30
 
31
-    /**
32
-     * Execute the console command.
33
-     *
34
-     * @return mixed
35
-     */
36
-    public function handle()
37
-    {
38
-        $docData           = [];
39
-        $docData['models'] = [];
40
-        $routes            = $this->getRoutes();
41
-        foreach ($routes as $route) 
42
-        {
43
-            if ($route) 
44
-            {
45
-                $actoinArray = explode('@', $route['action']);
46
-                if(array_get($actoinArray, 1, false))
47
-                {
48
-                    $controller       = $actoinArray[0];
49
-                    $method           = $actoinArray[1];
50
-                    $route['name']    = $method !== 'index' ? $method : 'list';
31
+	/**
32
+	 * Execute the console command.
33
+	 *
34
+	 * @return mixed
35
+	 */
36
+	public function handle()
37
+	{
38
+		$docData           = [];
39
+		$docData['models'] = [];
40
+		$routes            = $this->getRoutes();
41
+		foreach ($routes as $route) 
42
+		{
43
+			if ($route) 
44
+			{
45
+				$actoinArray = explode('@', $route['action']);
46
+				if(array_get($actoinArray, 1, false))
47
+				{
48
+					$controller       = $actoinArray[0];
49
+					$method           = $actoinArray[1];
50
+					$route['name']    = $method !== 'index' ? $method : 'list';
51 51
                     
52
-                    $reflectionClass  = new \ReflectionClass($controller);
53
-                    $reflectionMethod = $reflectionClass->getMethod($method);
54
-                    $classProperties  = $reflectionClass->getDefaultProperties();
55
-                    $skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
-                    $validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
52
+					$reflectionClass  = new \ReflectionClass($controller);
53
+					$reflectionMethod = $reflectionClass->getMethod($method);
54
+					$classProperties  = $reflectionClass->getDefaultProperties();
55
+					$skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
+					$validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
57 57
 
58
-                    $this->processDocBlock($route, $reflectionMethod);
59
-                    $this->getHeaders($route, $method, $skipLoginCheck);
60
-                    $this->getPostData($route, $reflectionMethod, $validationRules);
58
+					$this->processDocBlock($route, $reflectionMethod);
59
+					$this->getHeaders($route, $method, $skipLoginCheck);
60
+					$this->getPostData($route, $reflectionMethod, $validationRules);
61 61
 
62
-                    $route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
62
+					$route['response'] = $this->getResponseObject($classProperties['model'], $route['name'], $route['returnDocBlock']);
63 63
 
64
-                    preg_match('/api\/([^#]+)\//iU', $route['uri'], $module);
65
-                    $docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/' . $module[1] . '/') - 1)][] = $route;
64
+					preg_match('/api\/([^#]+)\//iU', $route['uri'], $module);
65
+					$docData['modules'][$module[1]][substr($route['prefix'], strlen('/api/' . $module[1] . '/') - 1)][] = $route;
66 66
 
67
-                    $this->getModels($classProperties['model'], $docData);   
68
-                }
69
-            }
70
-        }
67
+					$this->getModels($classProperties['model'], $docData);   
68
+				}
69
+			}
70
+		}
71 71
         
72
-        $docData['errors']  = $this->getErrors();
73
-        $docData['reports'] = \Core::reports()->all();
74
-        \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData));
75
-    }
72
+		$docData['errors']  = $this->getErrors();
73
+		$docData['reports'] = \Core::reports()->all();
74
+		\File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData));
75
+	}
76 76
 
77
-    /**
78
-     * Get list of all registered routes.
79
-     * 
80
-     * @return collection
81
-     */
82
-    protected function getRoutes()
83
-    {
84
-        return collect(\Route::getRoutes())->map(function ($route) {
85
-            if (strpos($route->uri(), 'api') !== false) 
86
-            {
87
-                return [
88
-                    'method' => $route->methods()[0],
89
-                    'uri'    => $route->uri(),
90
-                    'action' => $route->getActionName(),
91
-                    'prefix' => $route->getPrefix()
92
-                ];
93
-            }
94
-            return false;
95
-        })->all();
96
-    }
77
+	/**
78
+	 * Get list of all registered routes.
79
+	 * 
80
+	 * @return collection
81
+	 */
82
+	protected function getRoutes()
83
+	{
84
+		return collect(\Route::getRoutes())->map(function ($route) {
85
+			if (strpos($route->uri(), 'api') !== false) 
86
+			{
87
+				return [
88
+					'method' => $route->methods()[0],
89
+					'uri'    => $route->uri(),
90
+					'action' => $route->getActionName(),
91
+					'prefix' => $route->getPrefix()
92
+				];
93
+			}
94
+			return false;
95
+		})->all();
96
+	}
97 97
 
98
-    /**
99
-     * Generate headers for the given route.
100
-     * 
101
-     * @param  array  &$route
102
-     * @param  string $method
103
-     * @param  array  $skipLoginCheck
104
-     * @return void
105
-     */
106
-    protected function getHeaders(&$route, $method, $skipLoginCheck)
107
-    {
108
-        $route['headers'] = [
109
-        'Accept'       => 'application/json',
110
-        'Content-Type' => 'application/json',
111
-        'locale'       => 'The language of the returned data: ar, en or all.',
112
-        'time-zone'    => 'Your locale time zone',
113
-        ];
98
+	/**
99
+	 * Generate headers for the given route.
100
+	 * 
101
+	 * @param  array  &$route
102
+	 * @param  string $method
103
+	 * @param  array  $skipLoginCheck
104
+	 * @return void
105
+	 */
106
+	protected function getHeaders(&$route, $method, $skipLoginCheck)
107
+	{
108
+		$route['headers'] = [
109
+		'Accept'       => 'application/json',
110
+		'Content-Type' => 'application/json',
111
+		'locale'       => 'The language of the returned data: ar, en or all.',
112
+		'time-zone'    => 'Your locale time zone',
113
+		];
114 114
 
115 115
 
116
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
117
-        {
118
-            $route['headers']['Authorization'] = 'Bearer {token}';
119
-        }
120
-    }
116
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
117
+		{
118
+			$route['headers']['Authorization'] = 'Bearer {token}';
119
+		}
120
+	}
121 121
 
122
-    /**
123
-     * Generate description and params for the given route
124
-     * based on the docblock.
125
-     * 
126
-     * @param  array  &$route
127
-     * @param  object $reflectionMethod
128
-     * @return void
129
-     */
130
-    protected function processDocBlock(&$route, $reflectionMethod)
131
-    {
132
-        $factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
133
-        $docblock                = $factory->create($reflectionMethod->getDocComment());
134
-        $route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
135
-        $params                  = $docblock->getTagsByName('param');
136
-        $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
137
-        foreach ($params as $param) 
138
-        {
139
-            $name = $param->getVariableName();
140
-            if ($name !== 'request') 
141
-            {
142
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
143
-            }
144
-        }
145
-    }
122
+	/**
123
+	 * Generate description and params for the given route
124
+	 * based on the docblock.
125
+	 * 
126
+	 * @param  array  &$route
127
+	 * @param  object $reflectionMethod
128
+	 * @return void
129
+	 */
130
+	protected function processDocBlock(&$route, $reflectionMethod)
131
+	{
132
+		$factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
133
+		$docblock                = $factory->create($reflectionMethod->getDocComment());
134
+		$route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
135
+		$params                  = $docblock->getTagsByName('param');
136
+		$route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
137
+		foreach ($params as $param) 
138
+		{
139
+			$name = $param->getVariableName();
140
+			if ($name !== 'request') 
141
+			{
142
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
143
+			}
144
+		}
145
+	}
146 146
 
147
-    /**
148
-     * Generate post body for the given route.
149
-     * 
150
-     * @param  array  &$route
151
-     * @param  object $reflectionMethod
152
-     * @param  array  $validationRules
153
-     * @return void
154
-     */
155
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
156
-    {
157
-        if ($route['method'] == 'POST') 
158
-        {
159
-            $body = $this->getMethodBody($reflectionMethod);
147
+	/**
148
+	 * Generate post body for the given route.
149
+	 * 
150
+	 * @param  array  &$route
151
+	 * @param  object $reflectionMethod
152
+	 * @param  array  $validationRules
153
+	 * @return void
154
+	 */
155
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
156
+	{
157
+		if ($route['method'] == 'POST') 
158
+		{
159
+			$body = $this->getMethodBody($reflectionMethod);
160 160
 
161
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
162
-            if (count($match)) 
163
-            {
164
-                if ($match[1] == '$this->validationRules')
165
-                {
166
-                    $route['body'] = $validationRules;
167
-                }
168
-                else
169
-                {
170
-                    $route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
171
-                }
161
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
162
+			if (count($match)) 
163
+			{
164
+				if ($match[1] == '$this->validationRules')
165
+				{
166
+					$route['body'] = $validationRules;
167
+				}
168
+				else
169
+				{
170
+					$route['body'] = eval('return ' . str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]) . ';');
171
+				}
172 172
 
173
-                foreach ($route['body'] as &$rule) 
174
-                {
175
-                    if(strpos($rule, 'unique'))
176
-                    {
177
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
178
-                    }
179
-                    elseif(strpos($rule, 'exists'))
180
-                    {
181
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
182
-                    }
183
-                }
184
-            }
185
-            else
186
-            {
187
-                $route['body'] = 'conditions';
188
-            }
189
-        }
190
-    }
173
+				foreach ($route['body'] as &$rule) 
174
+				{
175
+					if(strpos($rule, 'unique'))
176
+					{
177
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
178
+					}
179
+					elseif(strpos($rule, 'exists'))
180
+					{
181
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
182
+					}
183
+				}
184
+			}
185
+			else
186
+			{
187
+				$route['body'] = 'conditions';
188
+			}
189
+		}
190
+	}
191 191
 
192
-    /**
193
-     * Generate application errors.
194
-     * 
195
-     * @return array
196
-     */
197
-    protected function getErrors()
198
-    {
199
-        $errors          = [];
200
-        $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
201
-        foreach ($reflectionClass->getMethods() as $method) 
202
-        {
203
-            $methodName       = $method->name;
204
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
205
-            $body             = $this->getMethodBody($reflectionMethod);
192
+	/**
193
+	 * Generate application errors.
194
+	 * 
195
+	 * @return array
196
+	 */
197
+	protected function getErrors()
198
+	{
199
+		$errors          = [];
200
+		$reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
201
+		foreach ($reflectionClass->getMethods() as $method) 
202
+		{
203
+			$methodName       = $method->name;
204
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
205
+			$body             = $this->getMethodBody($reflectionMethod);
206 206
 
207
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
207
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
208 208
 
209
-            if (count($match)) 
210
-            {
211
-                $errors[$match[1]][] = $methodName;
212
-            }
213
-        }
209
+			if (count($match)) 
210
+			{
211
+				$errors[$match[1]][] = $methodName;
212
+			}
213
+		}
214 214
 
215
-        return $errors;
216
-    }
215
+		return $errors;
216
+	}
217 217
 
218
-    /**
219
-     * Get the given method body code.
220
-     * 
221
-     * @param  object $reflectionMethod
222
-     * @return string
223
-     */
224
-    protected function getMethodBody($reflectionMethod)
225
-    {
226
-        $filename   = $reflectionMethod->getFileName();
227
-        $start_line = $reflectionMethod->getStartLine() - 1;
228
-        $end_line   = $reflectionMethod->getEndLine();
229
-        $length     = $end_line - $start_line;         
230
-        $source     = file($filename);
231
-        $body       = implode("", array_slice($source, $start_line, $length));
232
-        $body       = trim(preg_replace('/\s+/', '', $body));
218
+	/**
219
+	 * Get the given method body code.
220
+	 * 
221
+	 * @param  object $reflectionMethod
222
+	 * @return string
223
+	 */
224
+	protected function getMethodBody($reflectionMethod)
225
+	{
226
+		$filename   = $reflectionMethod->getFileName();
227
+		$start_line = $reflectionMethod->getStartLine() - 1;
228
+		$end_line   = $reflectionMethod->getEndLine();
229
+		$length     = $end_line - $start_line;         
230
+		$source     = file($filename);
231
+		$body       = implode("", array_slice($source, $start_line, $length));
232
+		$body       = trim(preg_replace('/\s+/', '', $body));
233 233
 
234
-        return $body;
235
-    }
234
+		return $body;
235
+	}
236 236
 
237
-    /**
238
-     * Get example object of all availble models.
239
-     * 
240
-     * @param  string $modelName
241
-     * @param  array  $docData
242
-     * @return string
243
-     */
244
-    protected function getModels($modelName, &$docData)
245
-    {
246
-        if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
247
-        {
248
-            $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
249
-            $model      = factory($modelClass)->make();
250
-            $modelArr   = $model->toArray();
237
+	/**
238
+	 * Get example object of all availble models.
239
+	 * 
240
+	 * @param  string $modelName
241
+	 * @param  array  $docData
242
+	 * @return string
243
+	 */
244
+	protected function getModels($modelName, &$docData)
245
+	{
246
+		if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
247
+		{
248
+			$modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
249
+			$model      = factory($modelClass)->make();
250
+			$modelArr   = $model->toArray();
251 251
 
252
-            if ( $model->trans && ! $model->trans->count()) 
253
-            {
254
-                $modelArr['trans'] = [
255
-                    'en' => factory($modelClass . 'Translation')->make()->toArray()
256
-                ];
257
-            }
252
+			if ( $model->trans && ! $model->trans->count()) 
253
+			{
254
+				$modelArr['trans'] = [
255
+					'en' => factory($modelClass . 'Translation')->make()->toArray()
256
+				];
257
+			}
258 258
 
259
-            $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
260
-        }
261
-    }
259
+			$docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
260
+		}
261
+	}
262 262
 
263
-    /**
264
-     * Get the route response object type.
265
-     * 
266
-     * @param  string $modelName
267
-     * @param  string $method
268
-     * @param  string $returnDocBlock
269
-     * @return array
270
-     */
271
-    protected function getResponseObject($modelName, $method, $returnDocBlock)
272
-    {
273
-        $config    = \CoreConfig::getConfig();
274
-        $relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
275
-        $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
263
+	/**
264
+	 * Get the route response object type.
265
+	 * 
266
+	 * @param  string $modelName
267
+	 * @param  string $method
268
+	 * @param  string $returnDocBlock
269
+	 * @return array
270
+	 */
271
+	protected function getResponseObject($modelName, $method, $returnDocBlock)
272
+	{
273
+		$config    = \CoreConfig::getConfig();
274
+		$relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
275
+		$modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
276 276
 
277
-        return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
278
-    }
277
+		return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
278
+	}
279 279
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -2,118 +2,118 @@
 block discarded – undo
2 2
 
3 3
 interface RepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
     
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30
-    /**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
30
+	/**
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
     
42
-    /**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
42
+	/**
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array $data
60
-     * @return mixed
61
-     */
62
-    public function save(array $data);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array $data
60
+	  * @return mixed
61
+	  */
62
+	public function save(array $data);
63 63
 
64
-    /**
65
-     * Update record in the storage based on the given
66
-     * condition.
67
-     * 
68
-     * @param  var     $value condition value
69
-     * @param  array   $data
70
-     * @param  string  $attribute condition column name
71
-     * @return integer affected rows
72
-     */
73
-    public function update($value, array $data, $attribute = 'id');
64
+	/**
65
+	 * Update record in the storage based on the given
66
+	 * condition.
67
+	 * 
68
+	 * @param  var     $value condition value
69
+	 * @param  array   $data
70
+	 * @param  string  $attribute condition column name
71
+	 * @return integer affected rows
72
+	 */
73
+	public function update($value, array $data, $attribute = 'id');
74 74
 
75
-    /**
76
-     * Delete record from the storage based on the given
77
-     * condition.
78
-     * 
79
-     * @param  var     $value condition value
80
-     * @param  string  $attribute condition column name
81
-     * @return integer affected rows
82
-     */
83
-    public function delete($value, $attribute = 'id');
75
+	/**
76
+	 * Delete record from the storage based on the given
77
+	 * condition.
78
+	 * 
79
+	 * @param  var     $value condition value
80
+	 * @param  string  $attribute condition column name
81
+	 * @return integer affected rows
82
+	 */
83
+	public function delete($value, $attribute = 'id');
84 84
     
85
-    /**
86
-     * Fetch records from the storage based on the given
87
-     * id.
88
-     * 
89
-     * @param  integer $id
90
-     * @param  array   $relations
91
-     * @param  array   $columns
92
-     * @return object
93
-     */
94
-    public function find($id, $relations = [], $columns = array('*'));
85
+	/**
86
+	 * Fetch records from the storage based on the given
87
+	 * id.
88
+	 * 
89
+	 * @param  integer $id
90
+	 * @param  array   $relations
91
+	 * @param  array   $columns
92
+	 * @return object
93
+	 */
94
+	public function find($id, $relations = [], $columns = array('*'));
95 95
     
96
-    /**
97
-     * Fetch records from the storage based on the given
98
-     * condition.
99
-     * 
100
-     * @param  array   $conditions array of conditions
101
-     * @param  array   $relations
102
-     * @param  array   $sortBy
103
-     * @param  array   $desc
104
-     * @param  array   $columns
105
-     * @return collection
106
-     */
107
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
96
+	/**
97
+	 * Fetch records from the storage based on the given
98
+	 * condition.
99
+	 * 
100
+	 * @param  array   $conditions array of conditions
101
+	 * @param  array   $relations
102
+	 * @param  array   $sortBy
103
+	 * @param  array   $desc
104
+	 * @param  array   $columns
105
+	 * @return collection
106
+	 */
107
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
108 108
 
109
-    /**
110
-     * Fetch the first record fro the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  array   $conditions array of conditions
114
-     * @param  array   $relations
115
-     * @param  array   $columns
116
-     * @return object
117
-     */
118
-    public function first($conditions, $relations = [], $columns = array('*'));
109
+	/**
110
+	 * Fetch the first record fro the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  array   $conditions array of conditions
114
+	 * @param  array   $relations
115
+	 * @param  array   $columns
116
+	 * @return object
117
+	 */
118
+	public function first($conditions, $relations = [], $columns = array('*'));
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.