@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | private function getStatusAccordingToExceptionTrace() |
39 | 39 | { |
40 | - if($this->app->has('exceptiontrace')) { |
|
40 | + if ($this->app->has('exceptiontrace')) { |
|
41 | 41 | $this->data['status'] = (int)$this->app['exceptiontrace']['callNamespace']->getCode(); |
42 | 42 | } |
43 | 43 | else { |
@@ -54,21 +54,21 @@ discard block |
||
54 | 54 | |
55 | 55 | $this->app->terminate('responseSuccess'); |
56 | 56 | $this->app->terminate('responseStatus'); |
57 | - $this->app->register('responseSuccess',(bool)false); |
|
58 | - $this->app->register('responseStatus',$this->data['status']); |
|
57 | + $this->app->register('responseSuccess', (bool)false); |
|
58 | + $this->app->register('responseStatus', $this->data['status']); |
|
59 | 59 | |
60 | 60 | |
61 | - $optionalException = str_replace("\\","\\\\",$this->app->namespace()->exception()); |
|
61 | + $optionalException = str_replace("\\", "\\\\", $this->app->namespace()->exception()); |
|
62 | 62 | |
63 | - if(preg_match('@'.$optionalException.'@is',$this->data['errType'])){ |
|
63 | + if (preg_match('@'.$optionalException.'@is', $this->data['errType'])) { |
|
64 | 64 | |
65 | 65 | //trace pattern |
66 | 66 | $trace = $this->data['errContext']['trace']; |
67 | - if(preg_match('@Stack trace:\n#0(.*)\n#1@is',$trace,$traceArray)){ |
|
67 | + if (preg_match('@Stack trace:\n#0(.*)\n#1@is', $trace, $traceArray)) { |
|
68 | 68 | |
69 | - $traceFile = str_replace(root,'',$traceArray[1]); |
|
69 | + $traceFile = str_replace(root, '', $traceArray[1]); |
|
70 | 70 | |
71 | - if(preg_match('@(.*)\((\d+)\)@is',$traceFile,$traceResolve)){ |
|
71 | + if (preg_match('@(.*)\((\d+)\)@is', $traceFile, $traceResolve)) { |
|
72 | 72 | $this->data['errFile'] = $traceResolve[1]; |
73 | 73 | $this->data['errLine'] = (int)$traceResolve[2]; |
74 | 74 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $this->data['errType'] = class_basename($this->data['errType']); |
79 | 79 | } |
80 | 80 | |
81 | - if(is_array($meta = config('response.meta'))){ |
|
81 | + if (is_array($meta = config('response.meta'))) { |
|
82 | 82 | |
83 | 83 | //set as the success object is false |
84 | 84 | $this->data['appExceptionSuccess'] = []; |
85 | 85 | } |
86 | - else{ |
|
86 | + else { |
|
87 | 87 | |
88 | 88 | //set as the success object is false |
89 | - $this->data['appExceptionSuccess'] = ['success'=>(bool)false,'status'=>$this->data['status']]; |
|
89 | + $this->data['appExceptionSuccess'] = ['success'=>(bool)false, 'status'=>$this->data['status']]; |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | //This function can be used for defining your own way of handling errors during runtime, |
109 | 109 | //for example in applications in which you need to do cleanup of data/files when a critical error happens, |
110 | 110 | //or when you need to trigger an error under certain conditions (using trigger_error()). |
111 | - set_error_handler([$this,'setErrorHandler']); |
|
111 | + set_error_handler([$this, 'setErrorHandler']); |
|
112 | 112 | |
113 | 113 | //Registers a callback to be executed after script execution finishes or exit() is called. |
114 | 114 | //Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as |
115 | 115 | //they were registered. If you call exit() within one registered shutdown function, |
116 | 116 | //processing will stop completely and no other registered shutdown functions will be called. |
117 | - register_shutdown_function([$this,'fatalErrorShutdownHandler']); |
|
117 | + register_shutdown_function([$this, 'fatalErrorShutdownHandler']); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param null|string $errLine |
128 | 128 | * @param null|string $errContext |
129 | 129 | */ |
130 | - public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null) |
|
130 | + public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null) |
|
131 | 131 | { |
132 | 132 | // in case of a deficiency, |
133 | 133 | // we need to boot our general needs to be needed for the exception. |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | //get lang message for exception |
155 | 155 | $this->getLangMessageForException(); |
156 | 156 | |
157 | - if($this->app->has('exceptiontrace')){ |
|
157 | + if ($this->app->has('exceptiontrace')) { |
|
158 | 158 | |
159 | 159 | $customExceptionTrace = $this->app['exceptiontrace']; |
160 | 160 | $this->data['errFile'] = $customExceptionTrace['file']; |
@@ -163,37 +163,36 @@ discard block |
||
163 | 163 | |
164 | 164 | $environment = $this->app->environment(); |
165 | 165 | |
166 | - $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']); |
|
166 | + $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']); |
|
167 | 167 | |
168 | - if(Str::startsWith($vendorDirectory,'vendor') |
|
169 | - && Str::startsWith($vendorDirectory,'vendor/php-resta')===false) |
|
168 | + if (Str::startsWith($vendorDirectory, 'vendor') |
|
169 | + && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false) |
|
170 | 170 | { |
171 | 171 | $externalMessage = ($environment==="production") ? |
172 | - 'An unexpected external error has occurred' : |
|
173 | - $this->data['errStrReal']; |
|
172 | + 'An unexpected external error has occurred' : $this->data['errStrReal']; |
|
174 | 173 | |
175 | - $this->result = $this->getAppException($environment,$externalMessage); |
|
174 | + $this->result = $this->getAppException($environment, $externalMessage); |
|
176 | 175 | |
177 | 176 | |
178 | 177 | //Get or Set the HTTP response code |
179 | 178 | http_response_code(500); |
180 | 179 | $this->app->terminate('responseStatus'); |
181 | - $this->app->register('responseStatus',500); |
|
180 | + $this->app->register('responseStatus', 500); |
|
182 | 181 | |
183 | 182 | |
184 | 183 | } |
185 | - else{ |
|
184 | + else { |
|
186 | 185 | |
187 | - $this->result = $this->getAppException($environment,$this->data['errStrReal']); |
|
186 | + $this->result = $this->getAppException($environment, $this->data['errStrReal']); |
|
188 | 187 | |
189 | 188 | //Get or Set the HTTP response code |
190 | 189 | http_response_code($this->data['status']); |
191 | 190 | } |
192 | 191 | |
193 | - if($environment==="production"){ |
|
192 | + if ($environment==="production") { |
|
194 | 193 | |
195 | - $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']); |
|
196 | - $this->app->register('productionLogMessage',$this->app->get('out')->outputFormatter($productionLogMessage)); |
|
194 | + $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']); |
|
195 | + $this->app->register('productionLogMessage', $this->app->get('out')->outputFormatter($productionLogMessage)); |
|
197 | 196 | } |
198 | 197 | |
199 | 198 | // exception extender The exception information |
@@ -202,17 +201,17 @@ discard block |
||
202 | 201 | |
203 | 202 | |
204 | 203 | //set json app exception |
205 | - $this->app->register('routerResult',$this->result); |
|
204 | + $this->app->register('routerResult', $this->result); |
|
206 | 205 | |
207 | 206 | $restaOutHandle = null; |
208 | 207 | |
209 | - if(!defined('responseApp')){ |
|
208 | + if (!defined('responseApp')) { |
|
210 | 209 | $restaOutHandle = $this->app->get('out')->handle(); |
211 | 210 | } |
212 | 211 | |
213 | 212 | header("HTTP/1.1 ".$this->data['status']); |
214 | 213 | |
215 | - if($restaOutHandle===null){ |
|
214 | + if ($restaOutHandle===null) { |
|
216 | 215 | |
217 | 216 | //header set and symfony response call |
218 | 217 | header('Content-type:application/json;charset=utf-8'); |
@@ -220,7 +219,7 @@ discard block |
||
220 | 219 | echo json_encode($this->app->get('out')->outputFormatter($this->result)); |
221 | 220 | exit(); |
222 | 221 | } |
223 | - else{ |
|
222 | + else { |
|
224 | 223 | echo $restaOutHandle; |
225 | 224 | exit(); |
226 | 225 | } |
@@ -230,7 +229,7 @@ discard block |
||
230 | 229 | * @param $environment |
231 | 230 | * @return mixed |
232 | 231 | */ |
233 | - private function getAppException($environment,$message) |
|
232 | + private function getAppException($environment, $message) |
|
234 | 233 | { |
235 | 234 | return $this->data['appExceptionSuccess']+$this->data['exception']::$environment( |
236 | 235 | $this->data['errNo'], |
@@ -250,7 +249,7 @@ discard block |
||
250 | 249 | private function getExceptionExtender() |
251 | 250 | { |
252 | 251 | return $this->app->resolve( |
253 | - $this->app->get('macro')->call('exceptionExtender',function(){ |
|
252 | + $this->app->get('macro')->call('exceptionExtender', function() { |
|
254 | 253 | return ExceptionExtender::class; |
255 | 254 | }), |
256 | 255 | ['result'=>$this->result])->getResult(); |
@@ -268,13 +267,13 @@ discard block |
||
268 | 267 | |
269 | 268 | $this->inStackTrace($last_error); |
270 | 269 | |
271 | - if(!is_null($last_error)){ |
|
270 | + if (!is_null($last_error)) { |
|
272 | 271 | |
273 | - if(!defined('methodName')){ |
|
274 | - define('methodName',null); |
|
272 | + if (!defined('methodName')) { |
|
273 | + define('methodName', null); |
|
275 | 274 | } |
276 | 275 | |
277 | - if($this->app->has('exceptionFile')){ |
|
276 | + if ($this->app->has('exceptionFile')) { |
|
278 | 277 | $last_error['file'] = $this->app['exceptionFile']; |
279 | 278 | $last_error['line'] = $this->app['exceptionLine']; |
280 | 279 | } |
@@ -294,13 +293,13 @@ discard block |
||
294 | 293 | */ |
295 | 294 | public function inStackTrace($error) |
296 | 295 | { |
297 | - if($this->app->has('urlComponent')){ |
|
298 | - if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file']) |
|
299 | - && !$this->app->has('exceptionFile')){ |
|
300 | - if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){ |
|
301 | - $errorMessage = explode(":",$result[1]); |
|
302 | - $this->app->register('exceptionFile',$errorMessage[0]); |
|
303 | - $this->app->register('exceptionLine',$errorMessage[1]); |
|
296 | + if ($this->app->has('urlComponent')) { |
|
297 | + if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file']) |
|
298 | + && !$this->app->has('exceptionFile')) { |
|
299 | + if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) { |
|
300 | + $errorMessage = explode(":", $result[1]); |
|
301 | + $this->app->register('exceptionFile', $errorMessage[0]); |
|
302 | + $this->app->register('exceptionLine', $errorMessage[1]); |
|
304 | 303 | } |
305 | 304 | } |
306 | 305 | } |
@@ -313,33 +312,33 @@ discard block |
||
313 | 312 | { |
314 | 313 | $clone = clone $this; |
315 | 314 | |
316 | - if($this->app->has('exceptionTranslate')){ |
|
315 | + if ($this->app->has('exceptionTranslate')) { |
|
317 | 316 | |
318 | 317 | $langMessage = trans('exception.'.$this->app->get('exceptionTranslate')); |
319 | 318 | |
320 | - if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){ |
|
319 | + if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) { |
|
321 | 320 | |
322 | - if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){ |
|
323 | - foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){ |
|
321 | + if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) { |
|
322 | + foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) { |
|
324 | 323 | |
325 | 324 | $valueLangName = !is_null(trans('default.'.$value)) ? trans('default.'.$value) : $value; |
326 | - $langMessage = preg_replace('@\('.$key.'\)@is',$valueLangName,$langMessage); |
|
325 | + $langMessage = preg_replace('@\('.$key.'\)@is', $valueLangName, $langMessage); |
|
327 | 326 | } |
328 | 327 | } |
329 | 328 | } |
330 | 329 | |
331 | - if($langMessage!==null){ |
|
330 | + if ($langMessage!==null) { |
|
332 | 331 | $this->data['errStrReal'] = $langMessage; |
333 | 332 | } |
334 | 333 | } |
335 | 334 | |
336 | - if(class_exists($this->data['errorClassNamespace']) |
|
335 | + if (class_exists($this->data['errorClassNamespace']) |
|
337 | 336 | && |
338 | - (Str::startsWith($this->data['errorClassNamespace'],'App') |
|
339 | - || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){ |
|
337 | + (Str::startsWith($this->data['errorClassNamespace'], 'App') |
|
338 | + || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) { |
|
340 | 339 | |
341 | 340 | ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) { |
342 | - if(property_exists($this,'lang')){ |
|
341 | + if (property_exists($this, 'lang')) { |
|
343 | 342 | $clone->setLang($this->lang); |
344 | 343 | } |
345 | 344 | }); |
@@ -349,7 +348,7 @@ discard block |
||
349 | 348 | |
350 | 349 | $langMessage = (!is_null($this->data['lang'])) ? trans('exception.'.$this->data['lang']) : null; |
351 | 350 | |
352 | - if($langMessage!==null){ |
|
351 | + if ($langMessage!==null) { |
|
353 | 352 | $this->data['errStrReal'] = $langMessage; |
354 | 353 | } |
355 | 354 | } |
@@ -363,14 +362,14 @@ discard block |
||
363 | 362 | { |
364 | 363 | // catch exception via preg match |
365 | 364 | // and then clear the Uncaught statement from inside. |
366 | - if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){ |
|
365 | + if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) { |
|
367 | 366 | |
368 | - $this->data['errType'] = trim(str_replace('Uncaught','',$errArr[1])); |
|
367 | + $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1])); |
|
369 | 368 | $this->data['errorClassNamespace'] = $this->data['errType']; |
370 | 369 | } |
371 | 370 | |
372 | - if(preg_match('@Uncaught@is',$this->data['errStrReal']) |
|
373 | - && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){ |
|
371 | + if (preg_match('@Uncaught@is', $this->data['errStrReal']) |
|
372 | + && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) { |
|
374 | 373 | $this->data['errStrReal'] = trim($errStrRealArray[2]); |
375 | 374 | } |
376 | 375 | |
@@ -390,7 +389,7 @@ discard block |
||
390 | 389 | /** |
391 | 390 | * @param null|string $lang |
392 | 391 | */ |
393 | - public function setLang($lang=null) |
|
392 | + public function setLang($lang = null) |
|
394 | 393 | { |
395 | 394 | $this->lang = $lang; |
396 | 395 | } |