Completed
Push — master ( e2d103...eb2586 )
by Sherif
01:46
created
src/Modules/Core/Console/Commands/GenerateDoc.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -199,7 +199,7 @@
 block discarded – undo
199 199
     /**
200 200
      * Get the given method body code.
201 201
      *
202
-     * @param  object $reflectionMethod
202
+     * @param  \ReflectionMethod $reflectionMethod
203 203
      * @return string
204 204
      */
205 205
     protected function getMethodBody($reflectionMethod)
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     protected function getRoutes()
81 81
     {
82
-        return collect(\Route::getRoutes())->map(function ($route) {
82
+        return collect(\Route::getRoutes())->map(function($route) {
83 83
             if (strpos($route->uri(), 'api/') !== false) {
84 84
                 return [
85 85
                     'method' => $route->methods()[0],
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         ];
111 111
 
112 112
 
113
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) {
113
+        if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) {
114 114
             $route['headers']['Authorization'] = 'Bearer {token}';
115 115
         }
116 116
     }
Please login to merge, or discard this 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/Utl/ApiConsumer.php 3 patches
Doc Comments   -16 removed lines patch added patch discarded remove patch
@@ -28,10 +28,6 @@  discard block
 block discarded – undo
28 28
     }
29 29
 
30 30
     /**
31
-     * @param  string $uri
32
-     * @param  array  $data
33
-     * @param  array  $headers
34
-     * @param  string $content
35 31
      * @return \Illuminate\Http\Response
36 32
      */
37 33
     public function get()
@@ -40,10 +36,6 @@  discard block
 block discarded – undo
40 36
     }
41 37
 
42 38
     /**
43
-     * @param  string $uri
44
-     * @param  array  $data
45
-     * @param  array  $headers
46
-     * @param  string $content
47 39
      * @return \Illuminate\Http\Response
48 40
      */
49 41
     public function post()
@@ -52,10 +44,6 @@  discard block
 block discarded – undo
52 44
     }
53 45
 
54 46
     /**
55
-     * @param  string $uri
56
-     * @param  array  $data
57
-     * @param  array  $headers
58
-     * @param  string $content
59 47
      * @return \Illuminate\Http\Response
60 48
      */
61 49
     public function put()
@@ -64,10 +52,6 @@  discard block
 block discarded – undo
64 52
     }
65 53
 
66 54
     /**
67
-     * @param  string $uri
68
-     * @param  array  $data
69
-     * @param  array  $headers
70
-     * @param  string $content
71 55
      * @return \Illuminate\Http\Response
72 56
      */
73 57
     public function delete()
Please login to merge, or discard this patch.
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -7,218 +7,218 @@
 block discarded – undo
7 7
 class ApiConsumer
8 8
 {
9 9
 
10
-    private $app;
11
-
12
-    private $router;
13
-
14
-    private $request;
15
-
16
-    private $disableMiddleware = false;
17
-
18
-    /**
19
-     * @param \Illuminate\Foundation\Application $app
20
-     * @param \Illuminate\Http\Request $request,
21
-     * @param \Illuminate\Routing\Router $router
22
-     */
23
-    public function __construct(Application $app, Request $request, LaravelRouter $router)
24
-    {
25
-        $this->app = $app;
26
-        $this->request = $request;
27
-        $this->router = $router;
28
-    }
29
-
30
-    /**
31
-     * @param  string $uri
32
-     * @param  array  $data
33
-     * @param  array  $headers
34
-     * @param  string $content
35
-     * @return \Illuminate\Http\Response
36
-     */
37
-    public function get()
38
-    {
39
-        return $this->quickCall('GET', func_get_args());
40
-    }
41
-
42
-    /**
43
-     * @param  string $uri
44
-     * @param  array  $data
45
-     * @param  array  $headers
46
-     * @param  string $content
47
-     * @return \Illuminate\Http\Response
48
-     */
49
-    public function post()
50
-    {
51
-        return $this->quickCall('POST', func_get_args());
52
-    }
53
-
54
-    /**
55
-     * @param  string $uri
56
-     * @param  array  $data
57
-     * @param  array  $headers
58
-     * @param  string $content
59
-     * @return \Illuminate\Http\Response
60
-     */
61
-    public function put()
62
-    {
63
-        return $this->quickCall('PUT', func_get_args());
64
-    }
65
-
66
-    /**
67
-     * @param  string $uri
68
-     * @param  array  $data
69
-     * @param  array  $headers
70
-     * @param  string $content
71
-     * @return \Illuminate\Http\Response
72
-     */
73
-    public function delete()
74
-    {
75
-        return $this->quickCall('DELETE', func_get_args());
76
-    }
77
-
78
-    /**
79
-     * @param  array $requests An array of requests
80
-     * @return array
81
-     */
82
-    public function batchRequest(array $requests)
83
-    {
84
-        foreach ($requests as $i => $request) {
85
-            $requests[$i] = call_user_func_array([$this, 'singleRequest'], $request);
86
-        }
87
-
88
-        return $requests;
89
-    }
90
-
91
-    /**
92
-     * @param  string $method
93
-     * @param  array  $args
94
-     * @return \Illuminate\Http\Response
95
-     */
96
-    public function quickCall($method, array $args)
97
-    {
98
-        array_unshift($args, $method);
99
-        return call_user_func_array([$this, "singleRequest"], $args);
100
-    }
101
-
102
-    /**
103
-     * @param  string $method
104
-     * @param  string $uri
105
-     * @param  array  $data
106
-     * @param  array  $headers
107
-     * @param  string $content
108
-     * @return \Illuminate\Http\Response
109
-     */
110
-    public function singleRequest($method, $uri, array $data = [], array $headers = [], $content = null)
111
-    {
112
-        // Save the current request so we can reset the router back to it
113
-        // after we've completed our internal request.
114
-        $currentRequest = $this->request->instance()->duplicate();
115
-
116
-        $headers = $this->overrideHeaders($currentRequest->server->getHeaders(), $headers);
117
-
118
-        if ($this->disableMiddleware) {
119
-            $this->app->instance('middleware.disable', true);
120
-        }
121
-
122
-        $response = $this->request($method, $uri, $data, $headers, $content);
123
-
124
-        if ($this->disableMiddleware) {
125
-            $this->app->instance('middleware.disable', false);
126
-        }
127
-
128
-        // Once the request has completed we reset the currentRequest of the router
129
-        // to match the original request.
130
-        $this->request->instance()->initialize(
131
-            $currentRequest->query->all(),
132
-            $currentRequest->request->all(),
133
-            $currentRequest->attributes->all(),
134
-            $currentRequest->cookies->all(),
135
-            $currentRequest->files->all(),
136
-            $currentRequest->server->all(),
137
-            $currentRequest->content
138
-        );
139
-
140
-        return $response;
141
-    }
142
-
143
-    private function overrideHeaders(array $default, array $headers)
144
-    {
145
-        $headers = $this->transformHeadersToUppercaseUnderscoreType($headers);
146
-        return array_merge($default, $headers);
147
-    }
148
-
149
-    public function enableMiddleware()
150
-    {
151
-        $this->disableMiddleware = false;
152
-    }
153
-
154
-    public function disableMiddleware()
155
-    {
156
-        $this->disableMiddleware = true;
157
-    }
158
-
159
-    /**
160
-     * @param  string $method
161
-     * @param  string $uri
162
-     * @param  array  $data
163
-     * @param  array  $headers
164
-     * @param  string $content
165
-     * @return \Illuminate\Http\Response
166
-     */
167
-    private function request($method, $uri, array $data = [], array $headers = [], $content = null)
168
-    {
169
-        // Create a new request object for the internal request
170
-        $request = $this->createRequest($method, $uri, $data, $headers, $content);
171
-
172
-        // Handle the request in the kernel and prepare a response
173
-        $response = $this->router->prepareResponse($request, $this->app->handle($request));
174
-
175
-        return $response;
176
-    }
177
-
178
-    /**
179
-     * @param  string $method
180
-     * @param  string $uri
181
-     * @param  array  $data
182
-     * @param  array  $headers
183
-     * @param  string $content
184
-     * @return \Illuminate\Http\Request
185
-     */
186
-    private function createRequest($method, $uri, array $data = [], array $headers = [], $content = null)
187
-    {
188
-        $server = $this->transformHeadersToServerVariables($headers);
189
-
190
-        return $this->request->create($uri, $method, $data, [], [], $server, $content);
191
-    }
192
-
193
-    private function transformHeadersToUppercaseUnderscoreType($headers)
194
-    {
195
-        $transformed = [];
196
-
197
-        foreach ($headers as $headerType => $headerValue) {
198
-            $headerType = strtoupper(str_replace('-', '_', $headerType));
199
-
200
-            $transformed[$headerType] = $headerValue;
201
-        }
202
-
203
-        return $transformed;
204
-    }
205
-
206
-    /**
207
-     * https://github.com/symfony/symfony/issues/5074
208
-     *
209
-     * @param  array $headers
210
-     * @return array
211
-     */
212
-    private function transformHeadersToServerVariables($headers)
213
-    {
214
-        $server = [];
215
-
216
-        foreach ($headers as $headerType => $headerValue) {
217
-            $headerType = 'HTTP_' . $headerType;
218
-
219
-            $server[$headerType] = $headerValue;
220
-        }
221
-
222
-        return $server;
223
-    }
10
+	private $app;
11
+
12
+	private $router;
13
+
14
+	private $request;
15
+
16
+	private $disableMiddleware = false;
17
+
18
+	/**
19
+	 * @param \Illuminate\Foundation\Application $app
20
+	 * @param \Illuminate\Http\Request $request,
21
+	 * @param \Illuminate\Routing\Router $router
22
+	 */
23
+	public function __construct(Application $app, Request $request, LaravelRouter $router)
24
+	{
25
+		$this->app = $app;
26
+		$this->request = $request;
27
+		$this->router = $router;
28
+	}
29
+
30
+	/**
31
+	 * @param  string $uri
32
+	 * @param  array  $data
33
+	 * @param  array  $headers
34
+	 * @param  string $content
35
+	 * @return \Illuminate\Http\Response
36
+	 */
37
+	public function get()
38
+	{
39
+		return $this->quickCall('GET', func_get_args());
40
+	}
41
+
42
+	/**
43
+	 * @param  string $uri
44
+	 * @param  array  $data
45
+	 * @param  array  $headers
46
+	 * @param  string $content
47
+	 * @return \Illuminate\Http\Response
48
+	 */
49
+	public function post()
50
+	{
51
+		return $this->quickCall('POST', func_get_args());
52
+	}
53
+
54
+	/**
55
+	 * @param  string $uri
56
+	 * @param  array  $data
57
+	 * @param  array  $headers
58
+	 * @param  string $content
59
+	 * @return \Illuminate\Http\Response
60
+	 */
61
+	public function put()
62
+	{
63
+		return $this->quickCall('PUT', func_get_args());
64
+	}
65
+
66
+	/**
67
+	 * @param  string $uri
68
+	 * @param  array  $data
69
+	 * @param  array  $headers
70
+	 * @param  string $content
71
+	 * @return \Illuminate\Http\Response
72
+	 */
73
+	public function delete()
74
+	{
75
+		return $this->quickCall('DELETE', func_get_args());
76
+	}
77
+
78
+	/**
79
+	 * @param  array $requests An array of requests
80
+	 * @return array
81
+	 */
82
+	public function batchRequest(array $requests)
83
+	{
84
+		foreach ($requests as $i => $request) {
85
+			$requests[$i] = call_user_func_array([$this, 'singleRequest'], $request);
86
+		}
87
+
88
+		return $requests;
89
+	}
90
+
91
+	/**
92
+	 * @param  string $method
93
+	 * @param  array  $args
94
+	 * @return \Illuminate\Http\Response
95
+	 */
96
+	public function quickCall($method, array $args)
97
+	{
98
+		array_unshift($args, $method);
99
+		return call_user_func_array([$this, "singleRequest"], $args);
100
+	}
101
+
102
+	/**
103
+	 * @param  string $method
104
+	 * @param  string $uri
105
+	 * @param  array  $data
106
+	 * @param  array  $headers
107
+	 * @param  string $content
108
+	 * @return \Illuminate\Http\Response
109
+	 */
110
+	public function singleRequest($method, $uri, array $data = [], array $headers = [], $content = null)
111
+	{
112
+		// Save the current request so we can reset the router back to it
113
+		// after we've completed our internal request.
114
+		$currentRequest = $this->request->instance()->duplicate();
115
+
116
+		$headers = $this->overrideHeaders($currentRequest->server->getHeaders(), $headers);
117
+
118
+		if ($this->disableMiddleware) {
119
+			$this->app->instance('middleware.disable', true);
120
+		}
121
+
122
+		$response = $this->request($method, $uri, $data, $headers, $content);
123
+
124
+		if ($this->disableMiddleware) {
125
+			$this->app->instance('middleware.disable', false);
126
+		}
127
+
128
+		// Once the request has completed we reset the currentRequest of the router
129
+		// to match the original request.
130
+		$this->request->instance()->initialize(
131
+			$currentRequest->query->all(),
132
+			$currentRequest->request->all(),
133
+			$currentRequest->attributes->all(),
134
+			$currentRequest->cookies->all(),
135
+			$currentRequest->files->all(),
136
+			$currentRequest->server->all(),
137
+			$currentRequest->content
138
+		);
139
+
140
+		return $response;
141
+	}
142
+
143
+	private function overrideHeaders(array $default, array $headers)
144
+	{
145
+		$headers = $this->transformHeadersToUppercaseUnderscoreType($headers);
146
+		return array_merge($default, $headers);
147
+	}
148
+
149
+	public function enableMiddleware()
150
+	{
151
+		$this->disableMiddleware = false;
152
+	}
153
+
154
+	public function disableMiddleware()
155
+	{
156
+		$this->disableMiddleware = true;
157
+	}
158
+
159
+	/**
160
+	 * @param  string $method
161
+	 * @param  string $uri
162
+	 * @param  array  $data
163
+	 * @param  array  $headers
164
+	 * @param  string $content
165
+	 * @return \Illuminate\Http\Response
166
+	 */
167
+	private function request($method, $uri, array $data = [], array $headers = [], $content = null)
168
+	{
169
+		// Create a new request object for the internal request
170
+		$request = $this->createRequest($method, $uri, $data, $headers, $content);
171
+
172
+		// Handle the request in the kernel and prepare a response
173
+		$response = $this->router->prepareResponse($request, $this->app->handle($request));
174
+
175
+		return $response;
176
+	}
177
+
178
+	/**
179
+	 * @param  string $method
180
+	 * @param  string $uri
181
+	 * @param  array  $data
182
+	 * @param  array  $headers
183
+	 * @param  string $content
184
+	 * @return \Illuminate\Http\Request
185
+	 */
186
+	private function createRequest($method, $uri, array $data = [], array $headers = [], $content = null)
187
+	{
188
+		$server = $this->transformHeadersToServerVariables($headers);
189
+
190
+		return $this->request->create($uri, $method, $data, [], [], $server, $content);
191
+	}
192
+
193
+	private function transformHeadersToUppercaseUnderscoreType($headers)
194
+	{
195
+		$transformed = [];
196
+
197
+		foreach ($headers as $headerType => $headerValue) {
198
+			$headerType = strtoupper(str_replace('-', '_', $headerType));
199
+
200
+			$transformed[$headerType] = $headerValue;
201
+		}
202
+
203
+		return $transformed;
204
+	}
205
+
206
+	/**
207
+	 * https://github.com/symfony/symfony/issues/5074
208
+	 *
209
+	 * @param  array $headers
210
+	 * @return array
211
+	 */
212
+	private function transformHeadersToServerVariables($headers)
213
+	{
214
+		$server = [];
215
+
216
+		foreach ($headers as $headerType => $headerValue) {
217
+			$headerType = 'HTTP_' . $headerType;
218
+
219
+			$server[$headerType] = $headerValue;
220
+		}
221
+
222
+		return $server;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -214,7 +214,7 @@
 block discarded – undo
214 214
         $server = [];
215 215
 
216 216
         foreach ($headers as $headerType => $headerValue) {
217
-            $headerType = 'HTTP_' . $headerType;
217
+            $headerType = 'HTTP_'.$headerType;
218 218
 
219 219
             $server[$headerType] = $headerValue;
220 220
         }
Please login to merge, or discard this patch.
src/Modules/Notifications/Notification.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -5,23 +5,23 @@
 block discarded – undo
5 5
 class Notification extends DatabaseNotification
6 6
 {
7 7
 
8
-    public function getCreatedAtAttribute($value)
9
-    {
10
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
11
-    }
8
+	public function getCreatedAtAttribute($value)
9
+	{
10
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
11
+	}
12 12
 
13
-    public function getUpdatedAtAttribute($value)
14
-    {
15
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
16
-    }
13
+	public function getUpdatedAtAttribute($value)
14
+	{
15
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
16
+	}
17 17
 
18
-    public function getDeletedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
-    }
18
+	public function getDeletedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
+	}
22 22
 
23
-    public function getReadAtAttribute($value)
24
-    {
25
-        return ! $value ? false : \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
26
-    }
23
+	public function getReadAtAttribute($value)
24
+	{
25
+		return ! $value ? false : \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
26
+	}
27 27
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Factories/NotificationFactory.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $factory->define(App\Modules\Notifications\Notification::class, function (Faker\Generator $faker) {
4
-    return [
5
-        'type'            => '',
6
-        'notifiable_type' => '',
7
-        'notifiable_id'   => '',
8
-        'data'            => '',
9
-        'read_at'         => null,
10
-        'created_at'      => $faker->dateTimeBetween('-1 years', 'now'),
11
-        'updated_at'      => $faker->dateTimeBetween('-1 years', 'now')
12
-    ];
4
+	return [
5
+		'type'            => '',
6
+		'notifiable_type' => '',
7
+		'notifiable_id'   => '',
8
+		'data'            => '',
9
+		'read_at'         => null,
10
+		'created_at'      => $faker->dateTimeBetween('-1 years', 'now'),
11
+		'updated_at'      => $faker->dateTimeBetween('-1 years', 'now')
12
+	];
13 13
 });
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$factory->define(App\Modules\Notifications\Notification::class, function (Faker\Generator $faker) {
3
+$factory->define(App\Modules\Notifications\Notification::class, function(Faker\Generator $faker) {
4 4
     return [
5 5
         'type'            => '',
6 6
         'notifiable_type' => '',
Please login to merge, or discard this patch.
Modules/Notifications/Database/Factories/PushNotificationDeviceFactory.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $factory->define(App\Modules\Notifications\PushNotificationDevice::class, function (Faker\Generator $faker) {
4
-    return [
5
-        'device_token' => $faker->sha1(),
6
-        'user_id'      => $faker->randomDigitNotNull(),
7
-        'created_at'   => $faker->dateTimeBetween('-1 years', 'now'),
8
-        'updated_at'   => $faker->dateTimeBetween('-1 years', 'now')
9
-    ];
4
+	return [
5
+		'device_token' => $faker->sha1(),
6
+		'user_id'      => $faker->randomDigitNotNull(),
7
+		'created_at'   => $faker->dateTimeBetween('-1 years', 'now'),
8
+		'updated_at'   => $faker->dateTimeBetween('-1 years', 'now')
9
+	];
10 10
 });
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$factory->define(App\Modules\Notifications\PushNotificationDevice::class, function (Faker\Generator $faker) {
3
+$factory->define(App\Modules\Notifications\PushNotificationDevice::class, function(Faker\Generator $faker) {
4 4
     return [
5 5
         'device_token' => $faker->sha1(),
6 6
         'user_id'      => $faker->randomDigitNotNull(),
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Seeds/AssignRelationsSeeder.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin group.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) {
22
-            \DB::table('groups_permissions')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'group_id'      => $adminGroupId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin group.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) {
22
+			\DB::table('groups_permissions')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'group_id'      => $adminGroupId,
26
+				'created_at'    => \DB::raw('NOW()'),
27
+				'updated_at'    => \DB::raw('NOW()')
28
+				]
29
+			);
30
+		});
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         /**
19 19
          * Assign the permissions to the admin group.
20 20
          */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) {
21
+        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function($permission) use ($adminGroupId) {
22 22
             \DB::table('groups_permissions')->insert(
23 23
                 [
24 24
                 'permission_id' => $permission->id,
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Seeds/NotificationsDatabaseSeeder.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@
 block discarded – undo
6 6
 
7 7
 class NotificationsDatabaseSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $this->call(ClearDataSeeder::class);
17
-        $this->call(NotificationsTableSeeder::class);
18
-        $this->call(PushNotificationsDevicesTableSeeder::class);
19
-        $this->call(AssignRelationsSeeder::class);
20
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$this->call(ClearDataSeeder::class);
17
+		$this->call(NotificationsTableSeeder::class);
18
+		$this->call(PushNotificationsDevicesTableSeeder::class);
19
+		$this->call(AssignRelationsSeeder::class);
20
+	}
21 21
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Seeds/NotificationsTableSeeder.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -6,46 +6,46 @@
 block discarded – undo
6 6
 
7 7
 class NotificationsTableSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        /**
17
-         * Insert the permissions related to settings table.
18
-         */
19
-        \DB::table('permissions')->insert(
20
-            [
21
-                /**
22
-                 * notifications model permissions.
23
-                 */
24
-                [
25
-                'name'       => 'all',
26
-                'model'      => 'notifications',
27
-                'created_at' => \DB::raw('NOW()'),
28
-                'updated_at' => \DB::raw('NOW()')
29
-                ],
30
-                [
31
-                'name'       => 'unread',
32
-                'model'      => 'notifications',
33
-                'created_at' => \DB::raw('NOW()'),
34
-                'updated_at' => \DB::raw('NOW()')
35
-                ],
36
-                [
37
-                'name'       => 'markAsRead',
38
-                'model'      => 'notifications',
39
-                'created_at' => \DB::raw('NOW()'),
40
-                'updated_at' => \DB::raw('NOW()')
41
-                ],
42
-                [
43
-                'name'       => 'markAllAsRead',
44
-                'model'      => 'notifications',
45
-                'created_at' => \DB::raw('NOW()'),
46
-                'updated_at' => \DB::raw('NOW()')
47
-                ]
48
-            ]
49
-        );
50
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		/**
17
+		 * Insert the permissions related to settings table.
18
+		 */
19
+		\DB::table('permissions')->insert(
20
+			[
21
+				/**
22
+				 * notifications model permissions.
23
+				 */
24
+				[
25
+				'name'       => 'all',
26
+				'model'      => 'notifications',
27
+				'created_at' => \DB::raw('NOW()'),
28
+				'updated_at' => \DB::raw('NOW()')
29
+				],
30
+				[
31
+				'name'       => 'unread',
32
+				'model'      => 'notifications',
33
+				'created_at' => \DB::raw('NOW()'),
34
+				'updated_at' => \DB::raw('NOW()')
35
+				],
36
+				[
37
+				'name'       => 'markAsRead',
38
+				'model'      => 'notifications',
39
+				'created_at' => \DB::raw('NOW()'),
40
+				'updated_at' => \DB::raw('NOW()')
41
+				],
42
+				[
43
+				'name'       => 'markAllAsRead',
44
+				'model'      => 'notifications',
45
+				'created_at' => \DB::raw('NOW()'),
46
+				'updated_at' => \DB::raw('NOW()')
47
+				]
48
+			]
49
+		);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Seeds/ClearDataSeeder.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 
7 7
 class ClearDataSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']);
17
-        \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
-        $permissions->delete();
19
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']);
17
+		\DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.