Completed
Push — master ( e2d103...eb2586 )
by Sherif
01:46
created
src/Modules/Core/Console/Commands/GenerateDoc.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -7,254 +7,254 @@
 block discarded – undo
7 7
 
8 8
 class GenerateDoc extends Command
9 9
 {
10
-    /**
11
-     * The name and signature of the console command.
12
-     *
13
-     * @var string
14
-     */
15
-    protected $signature = 'doc:generate';
10
+	/**
11
+	 * The name and signature of the console command.
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $signature = 'doc:generate';
16 16
 
17
-    /**
18
-     * The console command description.
19
-     *
20
-     * @var string
21
-     */
22
-    protected $description = 'Generate api documentation';
17
+	/**
18
+	 * The console command description.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $description = 'Generate api documentation';
23 23
 
24
-    /**
25
-     * Init new object.
26
-     *
27
-     * @return  void
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct();
32
-    }
24
+	/**
25
+	 * Init new object.
26
+	 *
27
+	 * @return  void
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct();
32
+	}
33 33
 
34
-    /**
35
-     * Execute the console command.
36
-     *
37
-     * @return mixed
38
-     */
39
-    public function handle()
40
-    {
41
-        $docData           = [];
42
-        $docData['models'] = [];
43
-        $routes            = $this->getRoutes();
44
-        foreach ($routes as $route) {
45
-            if ($route) {
46
-                $actoinArray = explode('@', $route['action']);
47
-                if (Arr::get($actoinArray, 1, false)) {
48
-                    $controller       = $actoinArray[0];
49
-                    $method           = $actoinArray[1];
50
-                    $route['name']    = $method !== 'index' ? $method : 'list';
34
+	/**
35
+	 * Execute the console command.
36
+	 *
37
+	 * @return mixed
38
+	 */
39
+	public function handle()
40
+	{
41
+		$docData           = [];
42
+		$docData['models'] = [];
43
+		$routes            = $this->getRoutes();
44
+		foreach ($routes as $route) {
45
+			if ($route) {
46
+				$actoinArray = explode('@', $route['action']);
47
+				if (Arr::get($actoinArray, 1, false)) {
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   = Arr::get($classProperties, 'skipLoginCheck', false);
56
-                    $validationRules  = Arr::get($classProperties, 'validationRules', false);
52
+					$reflectionClass  = new \ReflectionClass($controller);
53
+					$reflectionMethod = $reflectionClass->getMethod($method);
54
+					$classProperties  = $reflectionClass->getDefaultProperties();
55
+					$skipLoginCheck   = Arr::get($classProperties, 'skipLoginCheck', false);
56
+					$validationRules  = Arr::get($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
-                return [
87
-                    'method' => $route->methods()[0],
88
-                    'uri'    => $route->uri(),
89
-                    'action' => $route->getActionName(),
90
-                    'prefix' => $route->getPrefix()
91
-                ];
92
-            }
93
-            return false;
94
-        })->all();
95
-    }
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
+				return [
87
+					'method' => $route->methods()[0],
88
+					'uri'    => $route->uri(),
89
+					'action' => $route->getActionName(),
90
+					'prefix' => $route->getPrefix()
91
+				];
92
+			}
93
+			return false;
94
+		})->all();
95
+	}
96 96
 
97
-    /**
98
-     * Generate headers for the given route.
99
-     *
100
-     * @param  array  &$route
101
-     * @param  string $method
102
-     * @param  array  $skipLoginCheck
103
-     * @return void
104
-     */
105
-    protected function getHeaders(&$route, $method, $skipLoginCheck)
106
-    {
107
-        $route['headers'] = [
108
-        'Accept'       => 'application/json',
109
-        'Content-Type' => 'application/json',
110
-        'locale'       => 'The language of the returned data: ar, en or all.',
111
-        'time-zone'    => 'Your locale time zone',
112
-        ];
97
+	/**
98
+	 * Generate headers for the given route.
99
+	 *
100
+	 * @param  array  &$route
101
+	 * @param  string $method
102
+	 * @param  array  $skipLoginCheck
103
+	 * @return void
104
+	 */
105
+	protected function getHeaders(&$route, $method, $skipLoginCheck)
106
+	{
107
+		$route['headers'] = [
108
+		'Accept'       => 'application/json',
109
+		'Content-Type' => 'application/json',
110
+		'locale'       => 'The language of the returned data: ar, en or all.',
111
+		'time-zone'    => 'Your locale time zone',
112
+		];
113 113
 
114 114
 
115
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) {
116
-            $route['headers']['Authorization'] = 'Bearer {token}';
117
-        }
118
-    }
115
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) {
116
+			$route['headers']['Authorization'] = 'Bearer {token}';
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * Generate description and params for the given route
122
-     * based on the docblock.
123
-     *
124
-     * @param  array  &$route
125
-     * @param  \ReflectionMethod $reflectionMethod
126
-     * @return void
127
-     */
128
-    protected function processDocBlock(&$route, $reflectionMethod)
129
-    {
130
-        $factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
131
-        $docblock                = $factory->create($reflectionMethod->getDocComment());
132
-        $route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
133
-        $params                  = $docblock->getTagsByName('param');
134
-        $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
135
-        foreach ($params as $param) {
136
-            $name = $param->getVariableName();
137
-            if ($name !== 'request') {
138
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
139
-            }
140
-        }
141
-    }
120
+	/**
121
+	 * Generate description and params for the given route
122
+	 * based on the docblock.
123
+	 *
124
+	 * @param  array  &$route
125
+	 * @param  \ReflectionMethod $reflectionMethod
126
+	 * @return void
127
+	 */
128
+	protected function processDocBlock(&$route, $reflectionMethod)
129
+	{
130
+		$factory                 = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
131
+		$docblock                = $factory->create($reflectionMethod->getDocComment());
132
+		$route['description']    = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
133
+		$params                  = $docblock->getTagsByName('param');
134
+		$route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName();
135
+		foreach ($params as $param) {
136
+			$name = $param->getVariableName();
137
+			if ($name !== 'request') {
138
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
139
+			}
140
+		}
141
+	}
142 142
 
143
-    /**
144
-     * Generate post body for the given route.
145
-     *
146
-     * @param  array  &$route
147
-     * @param  \ReflectionMethod $reflectionMethod
148
-     * @param  array  $validationRules
149
-     * @return void
150
-     */
151
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
152
-    {
153
-        if ($route['method'] == 'POST') {
154
-            $body = $this->getMethodBody($reflectionMethod);
143
+	/**
144
+	 * Generate post body for the given route.
145
+	 *
146
+	 * @param  array  &$route
147
+	 * @param  \ReflectionMethod $reflectionMethod
148
+	 * @param  array  $validationRules
149
+	 * @return void
150
+	 */
151
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
152
+	{
153
+		if ($route['method'] == 'POST') {
154
+			$body = $this->getMethodBody($reflectionMethod);
155 155
 
156
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
157
-            if (count($match)) {
158
-                if ($match[1] == '$this->validationRules') {
159
-                    $route['body'] = $validationRules;
160
-                } else {
161
-                    $route['body'] = eval('return '.str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]).';');
162
-                }
156
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
157
+			if (count($match)) {
158
+				if ($match[1] == '$this->validationRules') {
159
+					$route['body'] = $validationRules;
160
+				} else {
161
+					$route['body'] = eval('return '.str_replace(',\'.$request->get(\'id\')', ',{id}\'', $match[1]).';');
162
+				}
163 163
 
164
-                foreach ($route['body'] as &$rule) {
165
-                    if (strpos($rule, 'unique')) {
166
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
167
-                    } elseif (strpos($rule, 'exists')) {
168
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
169
-                    }
170
-                }
171
-            } else {
172
-                $route['body'] = 'conditions';
173
-            }
174
-        }
175
-    }
164
+				foreach ($route['body'] as &$rule) {
165
+					if (strpos($rule, 'unique')) {
166
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
167
+					} elseif (strpos($rule, 'exists')) {
168
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
169
+					}
170
+				}
171
+			} else {
172
+				$route['body'] = 'conditions';
173
+			}
174
+		}
175
+	}
176 176
 
177
-    /**
178
-     * Generate application errors.
179
-     *
180
-     * @return array
181
-     */
182
-    protected function getErrors()
183
-    {
184
-        $errors          = [];
185
-        $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
186
-        foreach ($reflectionClass->getMethods() as $method) {
187
-            $methodName       = $method->name;
188
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
189
-            $body             = $this->getMethodBody($reflectionMethod);
177
+	/**
178
+	 * Generate application errors.
179
+	 *
180
+	 * @return array
181
+	 */
182
+	protected function getErrors()
183
+	{
184
+		$errors          = [];
185
+		$reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler');
186
+		foreach ($reflectionClass->getMethods() as $method) {
187
+			$methodName       = $method->name;
188
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
189
+			$body             = $this->getMethodBody($reflectionMethod);
190 190
 
191
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
191
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
192 192
 
193
-            if (count($match)) {
194
-                $errors[$match[1]][] = $methodName;
195
-            }
196
-        }
193
+			if (count($match)) {
194
+				$errors[$match[1]][] = $methodName;
195
+			}
196
+		}
197 197
 
198
-        return $errors;
199
-    }
198
+		return $errors;
199
+	}
200 200
 
201
-    /**
202
-     * Get the given method body code.
203
-     *
204
-     * @param  object $reflectionMethod
205
-     * @return string
206
-     */
207
-    protected function getMethodBody($reflectionMethod)
208
-    {
209
-        $filename   = $reflectionMethod->getFileName();
210
-        $start_line = $reflectionMethod->getStartLine() - 1;
211
-        $end_line   = $reflectionMethod->getEndLine();
212
-        $length     = $end_line - $start_line;
213
-        $source     = file($filename);
214
-        $body       = implode("", array_slice($source, $start_line, $length));
215
-        $body       = trim(preg_replace('/\s+/', '', $body));
201
+	/**
202
+	 * Get the given method body code.
203
+	 *
204
+	 * @param  object $reflectionMethod
205
+	 * @return string
206
+	 */
207
+	protected function getMethodBody($reflectionMethod)
208
+	{
209
+		$filename   = $reflectionMethod->getFileName();
210
+		$start_line = $reflectionMethod->getStartLine() - 1;
211
+		$end_line   = $reflectionMethod->getEndLine();
212
+		$length     = $end_line - $start_line;
213
+		$source     = file($filename);
214
+		$body       = implode("", array_slice($source, $start_line, $length));
215
+		$body       = trim(preg_replace('/\s+/', '', $body));
216 216
 
217
-        return $body;
218
-    }
217
+		return $body;
218
+	}
219 219
 
220
-    /**
221
-     * Get example object of all availble models.
222
-     *
223
-     * @param  string $modelName
224
-     * @param  array  $docData
225
-     * @return string
226
-     */
227
-    protected function getModels($modelName, &$docData)
228
-    {
229
-        if ($modelName && ! Arr::has($docData['models'], $modelName)) {
230
-            $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
231
-            $model      = factory($modelClass)->make();
232
-            $modelArr   = $model->toArray();
220
+	/**
221
+	 * Get example object of all availble models.
222
+	 *
223
+	 * @param  string $modelName
224
+	 * @param  array  $docData
225
+	 * @return string
226
+	 */
227
+	protected function getModels($modelName, &$docData)
228
+	{
229
+		if ($modelName && ! Arr::has($docData['models'], $modelName)) {
230
+			$modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
231
+			$model      = factory($modelClass)->make();
232
+			$modelArr   = $model->toArray();
233 233
 
234
-            if ($model->trans && ! $model->trans->count()) {
235
-                $modelArr['trans'] = [
236
-                    'en' => factory($modelClass.'Translation')->make()->toArray()
237
-                ];
238
-            }
234
+			if ($model->trans && ! $model->trans->count()) {
235
+				$modelArr['trans'] = [
236
+					'en' => factory($modelClass.'Translation')->make()->toArray()
237
+				];
238
+			}
239 239
 
240
-            $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
241
-        }
242
-    }
240
+			$docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
241
+		}
242
+	}
243 243
 
244
-    /**
245
-     * Get the route response object type.
246
-     *
247
-     * @param  string $modelName
248
-     * @param  string $method
249
-     * @param  string $returnDocBlock
250
-     * @return array
251
-     */
252
-    protected function getResponseObject($modelName, $method, $returnDocBlock)
253
-    {
254
-        $config    = \CoreConfig::getConfig();
255
-        $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false;
256
-        $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
244
+	/**
245
+	 * Get the route response object type.
246
+	 *
247
+	 * @param  string $modelName
248
+	 * @param  string $method
249
+	 * @param  string $returnDocBlock
250
+	 * @return array
251
+	 */
252
+	protected function getResponseObject($modelName, $method, $returnDocBlock)
253
+	{
254
+		$config    = \CoreConfig::getConfig();
255
+		$relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false;
256
+		$modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName;
257 257
 
258
-        return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
259
-    }
258
+		return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
259
+	}
260 260
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseFactoryInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@
 block discarded – undo
2 2
 
3 3
 interface BaseFactoryInterface
4 4
 {
5
-    /**
6
-     * Construct the repository class name based on
7
-     * the method name called, search in the
8
-     * given namespaces for the class and
9
-     * return an instance.
10
-     *
11
-     * @param  string $name the called method name
12
-     * @param  array  $arguments the method arguments
13
-     * @return object
14
-     */
15
-    public function __call($name, $arguments);
5
+	/**
6
+	 * Construct the repository class name based on
7
+	 * the method name called, search in the
8
+	 * given namespaces for the class and
9
+	 * return an instance.
10
+	 *
11
+	 * @param  string $name the called method name
12
+	 * @param  array  $arguments the method arguments
13
+	 * @return object
14
+	 */
15
+	public function __call($name, $arguments);
16 16
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseRepositoryInterface.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 BaseRepositoryInterface
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
 }
Please login to merge, or discard this patch.
src/Modules/Core/Decorators/CachingDecorator.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -5,113 +5,113 @@
 block discarded – undo
5 5
 
6 6
 class CachingDecorator
7 7
 {
8
-    /**
9
-     * The repo implementation.
10
-     *
11
-     * @var string
12
-     */
13
-    public $repo;
8
+	/**
9
+	 * The repo implementation.
10
+	 *
11
+	 * @var string
12
+	 */
13
+	public $repo;
14 14
 
15
-    /**
16
-     * The cache implementation.
17
-     *
18
-     * @var object
19
-     */
20
-    protected $cache;
15
+	/**
16
+	 * The cache implementation.
17
+	 *
18
+	 * @var object
19
+	 */
20
+	protected $cache;
21 21
 
22
-    /**
23
-     * The modelKey implementation.
24
-     *
25
-     * @var string
26
-     */
27
-    public $modelKey;
22
+	/**
23
+	 * The modelKey implementation.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	public $modelKey;
28 28
 
29
-    /**
30
-     * The model implementation.
31
-     *
32
-     * @var string
33
-     */
34
-    public $model;
29
+	/**
30
+	 * The model implementation.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $model;
35 35
 
36
-    /**
37
-     * The modelClass implementation.
38
-     *
39
-     * @var string
40
-     */
41
-    public $modelClass;
36
+	/**
37
+	 * The modelClass implementation.
38
+	 *
39
+	 * @var string
40
+	 */
41
+	public $modelClass;
42 42
 
43
-    /**
44
-     * The cacheConfig implementation.
45
-     *
46
-     * @var mixed
47
-     */
48
-    public $cacheConfig;
43
+	/**
44
+	 * The cacheConfig implementation.
45
+	 *
46
+	 * @var mixed
47
+	 */
48
+	public $cacheConfig;
49 49
 
50
-    /**
51
-     * The cacheTag implementation.
52
-     *
53
-     * @var string
54
-     */
55
-    public $cacheTag;
50
+	/**
51
+	 * The cacheTag implementation.
52
+	 *
53
+	 * @var string
54
+	 */
55
+	public $cacheTag;
56 56
     
57
-    /**
58
-     * Init new object.
59
-     *
60
-     * @return  void
61
-     */
62
-    public function __construct($repo, $cache)
63
-    {
64
-        $this->repo       = $repo;
65
-        $this->cache      = $cache;
66
-        $this->model      = $this->repo->model;
67
-        $this->modelClass = get_class($this->model);
68
-        $repoClass        = explode('\\', get_class($this->repo));
69
-        $repoName         = end($repoClass);
70
-        $this->cacheTag   = Str::plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))));
71
-    }
57
+	/**
58
+	 * Init new object.
59
+	 *
60
+	 * @return  void
61
+	 */
62
+	public function __construct($repo, $cache)
63
+	{
64
+		$this->repo       = $repo;
65
+		$this->cache      = $cache;
66
+		$this->model      = $this->repo->model;
67
+		$this->modelClass = get_class($this->model);
68
+		$repoClass        = explode('\\', get_class($this->repo));
69
+		$repoName         = end($repoClass);
70
+		$this->cacheTag   = Str::plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))));
71
+	}
72 72
 
73
-    /**
74
-     * Handle the cache mechanism for the called method
75
-     * based the configurations.
76
-     *
77
-     * @param  string $name the called method name
78
-     * @param  array  $arguments the method arguments
79
-     * @return object
80
-     */
81
-    public function __call($name, $arguments)
82
-    {
83
-        $this->setCacheConfig($name);
73
+	/**
74
+	 * Handle the cache mechanism for the called method
75
+	 * based the configurations.
76
+	 *
77
+	 * @param  string $name the called method name
78
+	 * @param  array  $arguments the method arguments
79
+	 * @return object
80
+	 */
81
+	public function __call($name, $arguments)
82
+	{
83
+		$this->setCacheConfig($name);
84 84
 
85
-        if ($this->cacheConfig && $this->cacheConfig == 'cache') {
86
-            $page     = \Request::get('page') !== null ? \Request::get('page') : '1';
87
-            $cacheKey = $name.$page.\Session::get('locale').serialize($arguments);
88
-            return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) {
89
-                return call_user_func_array([$this->repo, $name], $arguments);
90
-            });
91
-        } elseif ($this->cacheConfig) {
92
-            $this->cache->tags($this->cacheConfig)->flush();
93
-            return call_user_func_array([$this->repo, $name], $arguments);
94
-        }
85
+		if ($this->cacheConfig && $this->cacheConfig == 'cache') {
86
+			$page     = \Request::get('page') !== null ? \Request::get('page') : '1';
87
+			$cacheKey = $name.$page.\Session::get('locale').serialize($arguments);
88
+			return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) {
89
+				return call_user_func_array([$this->repo, $name], $arguments);
90
+			});
91
+		} elseif ($this->cacheConfig) {
92
+			$this->cache->tags($this->cacheConfig)->flush();
93
+			return call_user_func_array([$this->repo, $name], $arguments);
94
+		}
95 95
 
96
-        return call_user_func_array([$this->repo, $name], $arguments);
97
-    }
96
+		return call_user_func_array([$this->repo, $name], $arguments);
97
+	}
98 98
 
99
-    /**
100
-     * Set cache config based on the called method.
101
-     *
102
-     * @param  string $name
103
-     * @return void
104
-     */
105
-    private function setCacheConfig($name)
106
-    {
107
-        $config            = \CoreConfig::getConfig();
108
-        $cacheConfig       = Arr::get($config['cacheConfig'], $this->cacheTag, false);
109
-        $this->cacheConfig = false;
99
+	/**
100
+	 * Set cache config based on the called method.
101
+	 *
102
+	 * @param  string $name
103
+	 * @return void
104
+	 */
105
+	private function setCacheConfig($name)
106
+	{
107
+		$config            = \CoreConfig::getConfig();
108
+		$cacheConfig       = Arr::get($config['cacheConfig'], $this->cacheTag, false);
109
+		$this->cacheConfig = false;
110 110
 
111
-        if ($cacheConfig && in_array($name, $cacheConfig['cache'])) {
112
-            $this->cacheConfig = 'cache';
113
-        } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) {
114
-            $this->cacheConfig = $cacheConfig['clear'][$name];
115
-        }
116
-    }
111
+		if ($cacheConfig && in_array($name, $cacheConfig['cache'])) {
112
+			$this->cacheConfig = 'cache';
113
+		} elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) {
114
+			$this->cacheConfig = $cacheConfig['clear'][$name];
115
+		}
116
+	}
117 117
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/PermissionRepository.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@
 block discarded – undo
5 5
 
6 6
 class PermissionRepository extends BaseRepository
7 7
 {
8
-    /**
9
-     * Init new object.
10
-     *
11
-     * @param   AclPermission $model
12
-     * @return  void
13
-     */
14
-    public function __construct(AclPermission $model)
15
-    {
16
-        parent::__construct($model);
17
-    }
8
+	/**
9
+	 * Init new object.
10
+	 *
11
+	 * @param   AclPermission $model
12
+	 * @return  void
13
+	 */
14
+	public function __construct(AclPermission $model)
15
+	{
16
+		parent::__construct($model);
17
+	}
18 18
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/OauthClientRepository.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -5,38 +5,38 @@
 block discarded – undo
5 5
 
6 6
 class OauthClientRepository extends BaseRepository
7 7
 {
8
-    /**
9
-     * Init new object.
10
-     *
11
-     * @param   OauthClient $model
12
-     * @return  void
13
-     */
14
-    public function __construct(OauthClient $model)
15
-    {
16
-        parent::__construct($model);
17
-    }
8
+	/**
9
+	 * Init new object.
10
+	 *
11
+	 * @param   OauthClient $model
12
+	 * @return  void
13
+	 */
14
+	public function __construct(OauthClient $model)
15
+	{
16
+		parent::__construct($model);
17
+	}
18 18
 
19
-    /**
20
-     * Revoke the given client.
21
-     *
22
-     * @param  integer  $clientId
23
-     * @return void
24
-     */
25
-    public function revoke($clientId)
26
-    {
27
-        $client = $this->find($clientId);
28
-        $client->tokens()->update(['revoked' => true]);
29
-        $this->save(['id'=> $clientId, 'revoked' => true]);
30
-    }
19
+	/**
20
+	 * Revoke the given client.
21
+	 *
22
+	 * @param  integer  $clientId
23
+	 * @return void
24
+	 */
25
+	public function revoke($clientId)
26
+	{
27
+		$client = $this->find($clientId);
28
+		$client->tokens()->update(['revoked' => true]);
29
+		$this->save(['id'=> $clientId, 'revoked' => true]);
30
+	}
31 31
 
32
-    /**
33
-     * Un revoke the given client.
34
-     *
35
-     * @param  integer  $clientId
36
-     * @return void
37
-     */
38
-    public function unRevoke($clientId)
39
-    {
40
-        $this->save(['id'=> $clientId, 'revoked' => false]);
41
-    }
32
+	/**
33
+	 * Un revoke the given client.
34
+	 *
35
+	 * @param  integer  $clientId
36
+	 * @return void
37
+	 */
38
+	public function unRevoke($clientId)
39
+	{
40
+		$this->save(['id'=> $clientId, 'revoked' => false]);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/GroupRepository.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -5,32 +5,32 @@
 block discarded – undo
5 5
 
6 6
 class GroupRepository extends BaseRepository
7 7
 {
8
-    /**
9
-     * Init new object.
10
-     *
11
-     * @param   AclGroup $model
12
-     * @return  void
13
-     */
14
-    public function __construct(AclGroup $model)
15
-    {
16
-        parent::__construct($model);
17
-    }
8
+	/**
9
+	 * Init new object.
10
+	 *
11
+	 * @param   AclGroup $model
12
+	 * @return  void
13
+	 */
14
+	public function __construct(AclGroup $model)
15
+	{
16
+		parent::__construct($model);
17
+	}
18 18
 
19
-    /**
20
-     * Assign the given permission ids to the given group.
21
-     *
22
-     * @param  integer $groupId
23
-     * @param  array   $permissionIds
24
-     * @return object
25
-     */
26
-    public function assignPermissions($groupId, $permissionIds)
27
-    {
28
-        \DB::transaction(function () use ($groupId, $permissionIds) {
29
-            $group = $this->find($groupId);
30
-            $group->permissions()->detach();
31
-            $group->permissions()->attach($permissionIds);
32
-        });
19
+	/**
20
+	 * Assign the given permission ids to the given group.
21
+	 *
22
+	 * @param  integer $groupId
23
+	 * @param  array   $permissionIds
24
+	 * @return object
25
+	 */
26
+	public function assignPermissions($groupId, $permissionIds)
27
+	{
28
+		\DB::transaction(function () use ($groupId, $permissionIds) {
29
+			$group = $this->find($groupId);
30
+			$group->permissions()->detach();
31
+			$group->permissions()->attach($permissionIds);
32
+		});
33 33
 
34
-        return $this->find($groupId);
35
-    }
34
+		return $this->find($groupId);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/UserRepository.php 1 patch
Indentation   +379 added lines, -379 removed lines patch added patch discarded remove patch
@@ -6,391 +6,391 @@
 block discarded – undo
6 6
 
7 7
 class UserRepository extends BaseRepository
8 8
 {
9
-    /**
10
-     * Init new object.
11
-     *
12
-     * @param   AclUser $model
13
-     * @return  void
14
-     */
15
-    public function __construct(AclUser $model)
16
-    {
17
-        parent::__construct($model);
18
-    }
19
-
20
-    /**
21
-     * Return the logged in user account.
22
-     *
23
-     * @param  array   $relations
24
-     * @return boolean
25
-     */
26
-    public function account($relations = [])
27
-    {
28
-        $permissions = [];
29
-        $user        = $this->find(\Auth::id(), $relations);
30
-        foreach ($user->groups()->get() as $group) {
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
-        });
9
+	/**
10
+	 * Init new object.
11
+	 *
12
+	 * @param   AclUser $model
13
+	 * @return  void
14
+	 */
15
+	public function __construct(AclUser $model)
16
+	{
17
+		parent::__construct($model);
18
+	}
19
+
20
+	/**
21
+	 * Return the logged in user account.
22
+	 *
23
+	 * @param  array   $relations
24
+	 * @return boolean
25
+	 */
26
+	public function account($relations = [])
27
+	{
28
+		$permissions = [];
29
+		$user        = $this->find(\Auth::id(), $relations);
30
+		foreach ($user->groups()->get() as $group) {
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  string[] $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
-            \ErrorHandler::loginFailed();
104
-        } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
-            \ErrorHandler::loginFailed();
106
-        } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
-            \ErrorHandler::loginFailed();
108
-        } elseif ($user->blocked) {
109
-            \ErrorHandler::userIsBlocked();
110
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
-            \ErrorHandler::emailNotConfirmed();
112
-        }
113
-
114
-        return $user;
115
-    }
116
-
117
-    /**
118
-     * Handle a social login request of the none admin to the application.
119
-     *
120
-     * @param  string $authCode
121
-     * @param  string $accessToken
122
-     * @param  string $type
123
-     * @return array
124
-     */
125
-    public function loginSocial($authCode, $accessToken, $type)
126
-    {
127
-        $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
129
-
130
-        if (! $user->email) {
131
-            \ErrorHandler::noSocialEmail();
132
-        }
133
-
134
-        if ( ! $this->model->where('email', $user->email)->first()) {
135
-            $this->register(['email' => $user->email, 'password' => ''], true);
136
-        }
137
-
138
-        $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
139
-        return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 *
64
+	 * @param  string[] $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
+			\ErrorHandler::loginFailed();
104
+		} elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
+			\ErrorHandler::loginFailed();
106
+		} elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
+			\ErrorHandler::loginFailed();
108
+		} elseif ($user->blocked) {
109
+			\ErrorHandler::userIsBlocked();
110
+		} elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
+			\ErrorHandler::emailNotConfirmed();
112
+		}
113
+
114
+		return $user;
115
+	}
116
+
117
+	/**
118
+	 * Handle a social login request of the none admin to the application.
119
+	 *
120
+	 * @param  string $authCode
121
+	 * @param  string $accessToken
122
+	 * @param  string $type
123
+	 * @return array
124
+	 */
125
+	public function loginSocial($authCode, $accessToken, $type)
126
+	{
127
+		$access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
129
+
130
+		if (! $user->email) {
131
+			\ErrorHandler::noSocialEmail();
132
+		}
133
+
134
+		if ( ! $this->model->where('email', $user->email)->first()) {
135
+			$this->register(['email' => $user->email, 'password' => ''], true);
136
+		}
137
+
138
+		$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
139
+		return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
+	}
141 141
     
142
-    /**
143
-     * Handle a registration request.
144
-     *
145
-     * @param  array   $credentials
146
-     * @param  boolean $skipConfirmEmail
147
-     * @return array
148
-     */
149
-    public function register($credentials, $skipConfirmEmail = false)
150
-    {
151
-        $user = $this->save($credentials);
152
-
153
-        if ($skipConfirmEmail) {
154
-            $user->confirmed = 1;
155
-            $user->save();
156
-        } elseif (! config('skeleton.disable_confirm_email')) {
157
-            $this->sendConfirmationEmail($user->email);
158
-        }
159
-
160
-        return $user;
161
-    }
142
+	/**
143
+	 * Handle a registration request.
144
+	 *
145
+	 * @param  array   $credentials
146
+	 * @param  boolean $skipConfirmEmail
147
+	 * @return array
148
+	 */
149
+	public function register($credentials, $skipConfirmEmail = false)
150
+	{
151
+		$user = $this->save($credentials);
152
+
153
+		if ($skipConfirmEmail) {
154
+			$user->confirmed = 1;
155
+			$user->save();
156
+		} elseif (! config('skeleton.disable_confirm_email')) {
157
+			$this->sendConfirmationEmail($user->email);
158
+		}
159
+
160
+		return $user;
161
+	}
162 162
     
163
-    /**
164
-     * Block the user.
165
-     *
166
-     * @param  integer $userId
167
-     * @return object
168
-     */
169
-    public function block($userId)
170
-    {
171
-        if (! $user = $this->find($userId)) {
172
-            \ErrorHandler::notFound('user');
173
-        }
174
-        if (! $this->hasGroup(['Admin'])) {
175
-            \ErrorHandler::noPermissions();
176
-        } elseif (\Auth::id() == $userId) {
177
-            \ErrorHandler::noPermissions();
178
-        } elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
-            \ErrorHandler::noPermissions();
180
-        }
181
-
182
-        $user->blocked = 1;
183
-        $user->save();
163
+	/**
164
+	 * Block the user.
165
+	 *
166
+	 * @param  integer $userId
167
+	 * @return object
168
+	 */
169
+	public function block($userId)
170
+	{
171
+		if (! $user = $this->find($userId)) {
172
+			\ErrorHandler::notFound('user');
173
+		}
174
+		if (! $this->hasGroup(['Admin'])) {
175
+			\ErrorHandler::noPermissions();
176
+		} elseif (\Auth::id() == $userId) {
177
+			\ErrorHandler::noPermissions();
178
+		} elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
+			\ErrorHandler::noPermissions();
180
+		}
181
+
182
+		$user->blocked = 1;
183
+		$user->save();
184 184
         
185
-        return $user;
186
-    }
187
-
188
-    /**
189
-     * Unblock the user.
190
-     *
191
-     * @param  integer $userId
192
-     * @return object
193
-     */
194
-    public function unblock($userId)
195
-    {
196
-        if (! $this->hasGroup(['Admin'])) {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user          = $this->find($userId);
201
-        $user->blocked = 0;
202
-        $user->save();
203
-
204
-        return $user;
205
-    }
206
-
207
-    /**
208
-     * Send a reset link to the given user.
209
-     *
210
-     * @param  string  $email
211
-     * @return void
212
-     */
213
-    public function sendReset($email)
214
-    {
215
-        if (! $user = $this->model->where('email', $email)->first()) {
216
-            \ErrorHandler::notFound('email');
217
-        }
218
-
219
-        $token = \Password::getRepository()->create($user);
220
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
221
-    }
222
-
223
-    /**
224
-     * Reset the given user's password.
225
-     *
226
-     * @param  array  $credentials
227
-     * @return string|null
228
-     */
229
-    public function resetPassword($credentials)
230
-    {
231
-        $response = \Password::reset($credentials, function ($user, $password) {
232
-            $user->password = $password;
233
-            $user->save();
234
-        });
235
-
236
-        switch ($response) {
237
-            case \Password::PASSWORD_RESET:
238
-                return 'success';
239
-
240
-            case \Password::INVALID_TOKEN:
241
-                \ErrorHandler::invalidResetToken('token');
242
-                //no break
243
-
244
-            case \Password::INVALID_PASSWORD:
245
-                \ErrorHandler::invalidResetPassword('email');
246
-                //no break
247
-
248
-            case \Password::INVALID_USER:
249
-                \ErrorHandler::notFound('user');
250
-                //no break
251
-
252
-            default:
253
-                \ErrorHandler::generalError();
254
-        }
255
-    }
256
-
257
-    /**
258
-     * Change the logged in user password.
259
-     *
260
-     * @param  array  $credentials
261
-     * @return void
262
-     */
263
-    public function changePassword($credentials)
264
-    {
265
-        $user = \Auth::user();
266
-        if (! \Hash::check($credentials['old_password'], $user->password)) {
267
-            \ErrorHandler::invalidOldPassword();
268
-        }
269
-
270
-        $user->password = $credentials['password'];
271
-        $user->save();
272
-    }
273
-
274
-    /**
275
-     * Confirm email using the confirmation code.
276
-     *
277
-     * @param  string $confirmationCode
278
-     * @return void
279
-     */
280
-    public function confirmEmail($confirmationCode)
281
-    {
282
-        if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
-            \ErrorHandler::invalidConfirmationCode();
284
-        }
285
-
286
-        $user->confirmed         = 1;
287
-        $user->confirmation_code = null;
288
-        $user->save();
289
-    }
290
-
291
-    /**
292
-     * Send the confirmation mail.
293
-     *
294
-     * @param  string $email
295
-     * @return void
296
-     */
297
-    public function sendConfirmationEmail($email)
298
-    {
299
-        $user = $this->first(['email' => $email]);
300
-        if ($user->confirmed) {
301
-            \ErrorHandler::emailAlreadyConfirmed();
302
-        }
303
-
304
-        $user->confirmed         = 0;
305
-        $user->confirmation_code = sha1(microtime());
306
-        $user->save();
307
-        \Core::notifications()->notify($user, 'ConfirmEmail');
308
-    }
309
-
310
-    /**
311
-     * Paginate all users in the given group based on the given conditions.
312
-     *
313
-     * @param  string  $groupName
314
-     * @param  array   $relations
315
-     * @param  integer $perPage
316
-     * @param  string  $sortBy
317
-     * @param  boolean $desc
318
-     * @return \Illuminate\Http\Response
319
-     */
320
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
-    {
322
-        unset($conditions['page']);
323
-        $conditions = $this->constructConditions($conditions, $this->model);
324
-        $sort       = $desc ? 'desc' : 'asc';
325
-        $model      = $this->model->with($relations);
326
-
327
-        $model->whereHas('groups', function ($q) use ($groupName) {
328
-            $q->where('name', $groupName);
329
-        });
185
+		return $user;
186
+	}
187
+
188
+	/**
189
+	 * Unblock the user.
190
+	 *
191
+	 * @param  integer $userId
192
+	 * @return object
193
+	 */
194
+	public function unblock($userId)
195
+	{
196
+		if (! $this->hasGroup(['Admin'])) {
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user          = $this->find($userId);
201
+		$user->blocked = 0;
202
+		$user->save();
203
+
204
+		return $user;
205
+	}
206
+
207
+	/**
208
+	 * Send a reset link to the given user.
209
+	 *
210
+	 * @param  string  $email
211
+	 * @return void
212
+	 */
213
+	public function sendReset($email)
214
+	{
215
+		if (! $user = $this->model->where('email', $email)->first()) {
216
+			\ErrorHandler::notFound('email');
217
+		}
218
+
219
+		$token = \Password::getRepository()->create($user);
220
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
221
+	}
222
+
223
+	/**
224
+	 * Reset the given user's password.
225
+	 *
226
+	 * @param  array  $credentials
227
+	 * @return string|null
228
+	 */
229
+	public function resetPassword($credentials)
230
+	{
231
+		$response = \Password::reset($credentials, function ($user, $password) {
232
+			$user->password = $password;
233
+			$user->save();
234
+		});
235
+
236
+		switch ($response) {
237
+			case \Password::PASSWORD_RESET:
238
+				return 'success';
239
+
240
+			case \Password::INVALID_TOKEN:
241
+				\ErrorHandler::invalidResetToken('token');
242
+				//no break
243
+
244
+			case \Password::INVALID_PASSWORD:
245
+				\ErrorHandler::invalidResetPassword('email');
246
+				//no break
247
+
248
+			case \Password::INVALID_USER:
249
+				\ErrorHandler::notFound('user');
250
+				//no break
251
+
252
+			default:
253
+				\ErrorHandler::generalError();
254
+		}
255
+	}
256
+
257
+	/**
258
+	 * Change the logged in user password.
259
+	 *
260
+	 * @param  array  $credentials
261
+	 * @return void
262
+	 */
263
+	public function changePassword($credentials)
264
+	{
265
+		$user = \Auth::user();
266
+		if (! \Hash::check($credentials['old_password'], $user->password)) {
267
+			\ErrorHandler::invalidOldPassword();
268
+		}
269
+
270
+		$user->password = $credentials['password'];
271
+		$user->save();
272
+	}
273
+
274
+	/**
275
+	 * Confirm email using the confirmation code.
276
+	 *
277
+	 * @param  string $confirmationCode
278
+	 * @return void
279
+	 */
280
+	public function confirmEmail($confirmationCode)
281
+	{
282
+		if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
+			\ErrorHandler::invalidConfirmationCode();
284
+		}
285
+
286
+		$user->confirmed         = 1;
287
+		$user->confirmation_code = null;
288
+		$user->save();
289
+	}
290
+
291
+	/**
292
+	 * Send the confirmation mail.
293
+	 *
294
+	 * @param  string $email
295
+	 * @return void
296
+	 */
297
+	public function sendConfirmationEmail($email)
298
+	{
299
+		$user = $this->first(['email' => $email]);
300
+		if ($user->confirmed) {
301
+			\ErrorHandler::emailAlreadyConfirmed();
302
+		}
303
+
304
+		$user->confirmed         = 0;
305
+		$user->confirmation_code = sha1(microtime());
306
+		$user->save();
307
+		\Core::notifications()->notify($user, 'ConfirmEmail');
308
+	}
309
+
310
+	/**
311
+	 * Paginate all users in the given group based on the given conditions.
312
+	 *
313
+	 * @param  string  $groupName
314
+	 * @param  array   $relations
315
+	 * @param  integer $perPage
316
+	 * @param  string  $sortBy
317
+	 * @param  boolean $desc
318
+	 * @return \Illuminate\Http\Response
319
+	 */
320
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
+	{
322
+		unset($conditions['page']);
323
+		$conditions = $this->constructConditions($conditions, $this->model);
324
+		$sort       = $desc ? 'desc' : 'asc';
325
+		$model      = $this->model->with($relations);
326
+
327
+		$model->whereHas('groups', function ($q) use ($groupName) {
328
+			$q->where('name', $groupName);
329
+		});
330 330
 
331 331
         
332
-        if (count($conditions['conditionValues'])) {
333
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
-        }
335
-
336
-        if ($perPage) {
337
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
-        }
339
-
340
-        return $model->orderBy($sortBy, $sort)->get();
341
-    }
342
-
343
-    /**
344
-     * Save the given data to the logged in user.
345
-     *
346
-     * @param  array $data
347
-     * @return void
348
-     */
349
-    public function saveProfile($data)
350
-    {
351
-        if (Arr::has($data, 'profile_picture')) {
352
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
-        }
332
+		if (count($conditions['conditionValues'])) {
333
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
+		}
335
+
336
+		if ($perPage) {
337
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
+		}
339
+
340
+		return $model->orderBy($sortBy, $sort)->get();
341
+	}
342
+
343
+	/**
344
+	 * Save the given data to the logged in user.
345
+	 *
346
+	 * @param  array $data
347
+	 * @return void
348
+	 */
349
+	public function saveProfile($data)
350
+	{
351
+		if (Arr::has($data, 'profile_picture')) {
352
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
+		}
354 354
         
355
-        $data['id'] = \Auth::id();
356
-        return $this->save($data);
357
-    }
358
-
359
-    /**
360
-     * Ensure access token hasn't expired or revoked.
361
-     *
362
-     * @param  string $accessToken
363
-     * @return boolean
364
-     */
365
-    public function accessTokenExpiredOrRevoked($accessToken)
366
-    {
367
-        $accessTokenId = json_decode($accessToken, true)['id'];
368
-        $accessToken   = \DB::table('oauth_access_tokens')
369
-                ->where('id', $accessTokenId)
370
-                ->first();
355
+		$data['id'] = \Auth::id();
356
+		return $this->save($data);
357
+	}
358
+
359
+	/**
360
+	 * Ensure access token hasn't expired or revoked.
361
+	 *
362
+	 * @param  string $accessToken
363
+	 * @return boolean
364
+	 */
365
+	public function accessTokenExpiredOrRevoked($accessToken)
366
+	{
367
+		$accessTokenId = json_decode($accessToken, true)['id'];
368
+		$accessToken   = \DB::table('oauth_access_tokens')
369
+				->where('id', $accessTokenId)
370
+				->first();
371 371
         
372
-        if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
-            return true;
374
-        }
375
-
376
-        return false;
377
-    }
378
-
379
-    /**
380
-     * Revoke the given access token and all
381
-     * associated refresh tokens.
382
-     *
383
-     * @param  oject $accessToken
384
-     * @return void
385
-     */
386
-    public function revokeAccessToken($accessToken)
387
-    {
388
-        \DB::table('oauth_refresh_tokens')
389
-            ->where('access_token_id', $accessToken->id)
390
-            ->update([
391
-                'revoked' => true
392
-            ]);
393
-
394
-        $accessToken->revoke();
395
-    }
372
+		if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
+			return true;
374
+		}
375
+
376
+		return false;
377
+	}
378
+
379
+	/**
380
+	 * Revoke the given access token and all
381
+	 * associated refresh tokens.
382
+	 *
383
+	 * @param  oject $accessToken
384
+	 * @return void
385
+	 */
386
+	public function revokeAccessToken($accessToken)
387
+	{
388
+		\DB::table('oauth_refresh_tokens')
389
+			->where('access_token_id', $accessToken->id)
390
+			->update([
391
+				'revoked' => true
392
+			]);
393
+
394
+		$accessToken->revoke();
395
+	}
396 396
 }
Please login to merge, or discard this patch.
src/Modules/Reporting/Repositories/ReportRepository.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,65 +5,65 @@
 block discarded – undo
5 5
 
6 6
 class ReportRepository extends BaseRepository
7 7
 {
8
-    /**
9
-     * Init new object.
10
-     *
11
-     * @param   Report $model
12
-     * @return  void
13
-     */
14
-    public function __construct(Report $model)
15
-    {
16
-        parent::__construct($model);
17
-    }
8
+	/**
9
+	 * Init new object.
10
+	 *
11
+	 * @param   Report $model
12
+	 * @return  void
13
+	 */
14
+	public function __construct(Report $model)
15
+	{
16
+		parent::__construct($model);
17
+	}
18 18
 
19
-    /**
20
-     * Render the given report db view based on the given
21
-     * condition.
22
-     *
23
-     * @param  string  $reportName
24
-     * @param  array   $conditions
25
-     * @param  integer $perPage
26
-     * @param  array   $relations
27
-     * @param  boolean $skipPermission
28
-     * @return object
29
-     */
30
-    public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false)
31
-    {
32
-        /**
33
-         * Fetch the report from db.
34
-         */
35
-        $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model);
36
-        $report           = $this->model->with($relations)
37
-        ->whereRaw(
38
-            $reportConditions['conditionString'],
39
-            $reportConditions['conditionValues']
40
-        )->first();
19
+	/**
20
+	 * Render the given report db view based on the given
21
+	 * condition.
22
+	 *
23
+	 * @param  string  $reportName
24
+	 * @param  array   $conditions
25
+	 * @param  integer $perPage
26
+	 * @param  array   $relations
27
+	 * @param  boolean $skipPermission
28
+	 * @return object
29
+	 */
30
+	public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false)
31
+	{
32
+		/**
33
+		 * Fetch the report from db.
34
+		 */
35
+		$reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model);
36
+		$report           = $this->model->with($relations)
37
+		->whereRaw(
38
+			$reportConditions['conditionString'],
39
+			$reportConditions['conditionValues']
40
+		)->first();
41 41
         
42
-        /**
43
-         * Check report existance and permission.
44
-         */
45
-        if (! $report) {
46
-            \ErrorHandler::notFound('report');
47
-        } elseif (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) {
48
-            \ErrorHandler::noPermissions();
49
-        }
42
+		/**
43
+		 * Check report existance and permission.
44
+		 */
45
+		if (! $report) {
46
+			\ErrorHandler::notFound('report');
47
+		} elseif (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) {
48
+			\ErrorHandler::noPermissions();
49
+		}
50 50
 
51
-        /**
52
-         * Fetch data from the report based on the given conditions.
53
-         */
54
-        $report = \DB::table($report->view_name);
55
-        unset($conditions['page']);
56
-        if (count($conditions)) {
57
-            $conditions = $this->constructConditions($conditions, $this->model);
58
-            $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
59
-        }
60
-        /**
61
-         * Paginate or all data.
62
-         */
63
-        if ($perPage) {
64
-            return $report->paginate($perPage);
65
-        } else {
66
-            return $report->get();
67
-        }
68
-    }
51
+		/**
52
+		 * Fetch data from the report based on the given conditions.
53
+		 */
54
+		$report = \DB::table($report->view_name);
55
+		unset($conditions['page']);
56
+		if (count($conditions)) {
57
+			$conditions = $this->constructConditions($conditions, $this->model);
58
+			$report->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
59
+		}
60
+		/**
61
+		 * Paginate or all data.
62
+		 */
63
+		if ($perPage) {
64
+			return $report->paginate($perPage);
65
+		} else {
66
+			return $report->get();
67
+		}
68
+	}
69 69
 }
Please login to merge, or discard this patch.