@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @var $data array |
| 26 | 26 | */ |
| 27 | - protected $data=array(); |
|
| 27 | + protected $data = array(); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @return mixed|string |
| 31 | 31 | */ |
| 32 | - private function getEnvironmentStatus(){
|
|
| 32 | + private function getEnvironmentStatus() {
|
|
| 33 | 33 | |
| 34 | 34 | // application key, but if it has a null value |
| 35 | 35 | // then we move the environment value to the production environment. |
@@ -39,41 +39,41 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @return void|mixed |
| 41 | 41 | */ |
| 42 | - private function getStatusFromContext(){
|
|
| 42 | + private function getStatusFromContext() {
|
|
| 43 | 43 | |
| 44 | - $exception=$this->exception; |
|
| 44 | + $exception = $this->exception; |
|
| 45 | 45 | |
| 46 | - if(isset(core()->exceptiontrace)) |
|
| 46 | + if (isset(core()->exceptiontrace)) |
|
| 47 | 47 | {
|
| 48 | 48 | $this->data['status'] = (int)core()->exceptiontrace['callNamespace']->getCode(); |
| 49 | 49 | } |
| 50 | 50 | else {
|
| 51 | 51 | |
| 52 | - $this->data['status']=(int)$exception::exceptionTypeCodes($this->data['errType']); |
|
| 52 | + $this->data['status'] = (int)$exception::exceptionTypeCodes($this->data['errType']); |
|
| 53 | 53 | } |
| 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 | //linux test |
| 66 | - $trace=$this->data['errContext']['trace']; |
|
| 67 | - if(preg_match('@Stack trace:\n#0(.*)\n#1@is',$trace,$traceArray)){
|
|
| 68 | - $traceFile=str_replace(root,'',$traceArray[1]); |
|
| 69 | - if(preg_match('@(.*)\((\d+)\)@is',$traceFile,$traceResolve)){
|
|
| 70 | - $this->data['errFile']=$traceResolve[1]; |
|
| 71 | - $this->data['errLine']=(int)$traceResolve[2]; |
|
| 66 | + $trace = $this->data['errContext']['trace']; |
|
| 67 | + if (preg_match('@Stack trace:\n#0(.*)\n#1@is', $trace, $traceArray)) {
|
|
| 68 | + $traceFile = str_replace(root, '', $traceArray[1]); |
|
| 69 | + if (preg_match('@(.*)\((\d+)\)@is', $traceFile, $traceResolve)) {
|
|
| 70 | + $this->data['errFile'] = $traceResolve[1]; |
|
| 71 | + $this->data['errLine'] = (int)$traceResolve[2]; |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
| 76 | - $this->data['errType']=class_basename($this->data['errType']); |
|
| 76 | + $this->data['errType'] = class_basename($this->data['errType']); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -89,18 +89,18 @@ discard block |
||
| 89 | 89 | // in general we will use the exception class |
| 90 | 90 | // in the store/config directory to make it possible |
| 91 | 91 | // to change the user-based exceptions. |
| 92 | - $this->exception=StaticPathModel::$store.'\Config\Exception'; |
|
| 92 | + $this->exception = StaticPathModel::$store.'\Config\Exception'; |
|
| 93 | 93 | |
| 94 | 94 | //This function can be used for defining your own way of handling errors during runtime, |
| 95 | 95 | //for example in applications in which you need to do cleanup of data/files when a critical error happens, |
| 96 | 96 | //or when you need to trigger an error under certain conditions (using trigger_error()). |
| 97 | - set_error_handler([$this,'setErrorHandler']); |
|
| 97 | + set_error_handler([$this, 'setErrorHandler']); |
|
| 98 | 98 | |
| 99 | 99 | //Registers a callback to be executed after script execution finishes or exit() is called. |
| 100 | 100 | //Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as |
| 101 | 101 | //they were registered. If you call exit() within one registered shutdown function, |
| 102 | 102 | //processing will stop completely and no other registered shutdown functions will be called. |
| 103 | - register_shutdown_function([$this,'fatalErrorShutdownHandler']); |
|
| 103 | + register_shutdown_function([$this, 'fatalErrorShutdownHandler']); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param null $errLine |
| 111 | 111 | * @param null $errContext |
| 112 | 112 | */ |
| 113 | - public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null) |
|
| 113 | + public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null) |
|
| 114 | 114 | {
|
| 115 | 115 | // in case of a deficiency, |
| 116 | 116 | // we need to boot our general needs to be needed for the exception. |
@@ -135,79 +135,78 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $this->getStatusFromContext(); |
| 137 | 137 | |
| 138 | - if(is_array($meta=config('response.meta'))){
|
|
| 138 | + if (is_array($meta = config('response.meta'))) {
|
|
| 139 | 139 | |
| 140 | 140 | //set as the success object is false |
| 141 | - $this->data['appExceptionSuccess']=[]; |
|
| 141 | + $this->data['appExceptionSuccess'] = []; |
|
| 142 | 142 | } |
| 143 | - else{
|
|
| 143 | + else {
|
|
| 144 | 144 | |
| 145 | 145 | //set as the success object is false |
| 146 | - $this->data['appExceptionSuccess']=['success'=>(bool)false,'status'=>$this->data['status']]; |
|
| 146 | + $this->data['appExceptionSuccess'] = ['success'=>(bool)false, 'status'=>$this->data['status']]; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | //get lang message for exception |
| 150 | 150 | $this->getLangMessageForException(); |
| 151 | 151 | |
| 152 | - if(property_exists(core(),'exceptiontrace')){
|
|
| 152 | + if (property_exists(core(), 'exceptiontrace')) {
|
|
| 153 | 153 | |
| 154 | - $customExceptionTrace=core()->exceptiontrace; |
|
| 155 | - $this->data['errFile']=$customExceptionTrace['file']; |
|
| 156 | - $this->data['errLine']=$customExceptionTrace['line']; |
|
| 154 | + $customExceptionTrace = core()->exceptiontrace; |
|
| 155 | + $this->data['errFile'] = $customExceptionTrace['file']; |
|
| 156 | + $this->data['errLine'] = $customExceptionTrace['line']; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $environment = $this->getEnvironmentStatus(); |
| 160 | 160 | |
| 161 | - $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']); |
|
| 161 | + $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']); |
|
| 162 | 162 | |
| 163 | - if(Str::startsWith($vendorDirectory,'vendor') |
|
| 164 | - && Str::startsWith($vendorDirectory,'vendor/php-resta')===false) |
|
| 163 | + if (Str::startsWith($vendorDirectory, 'vendor') |
|
| 164 | + && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false) |
|
| 165 | 165 | {
|
| 166 | 166 | $externalMessage = ($environment==="production") ? |
| 167 | - 'An unexpected external error has occurred' : |
|
| 168 | - $this->data['errStrReal']; |
|
| 167 | + 'An unexpected external error has occurred' : $this->data['errStrReal']; |
|
| 169 | 168 | |
| 170 | - $appException=$this->getAppException($environment,$externalMessage); |
|
| 169 | + $appException = $this->getAppException($environment, $externalMessage); |
|
| 171 | 170 | |
| 172 | 171 | |
| 173 | 172 | //Get or Set the HTTP response code |
| 174 | 173 | http_response_code(500); |
| 175 | 174 | $this->app->terminate('responseStatus');
|
| 176 | - $this->app->register('responseStatus',500);
|
|
| 175 | + $this->app->register('responseStatus', 500);
|
|
| 177 | 176 | |
| 178 | 177 | |
| 179 | 178 | } |
| 180 | - else{
|
|
| 179 | + else {
|
|
| 181 | 180 | |
| 182 | - $appException=$this->getAppException($environment,$this->data['errStrReal']); |
|
| 181 | + $appException = $this->getAppException($environment, $this->data['errStrReal']); |
|
| 183 | 182 | |
| 184 | 183 | //Get or Set the HTTP response code |
| 185 | 184 | http_response_code($this->data['status']); |
| 186 | 185 | } |
| 187 | 186 | |
| 188 | 187 | |
| 189 | - if($environment==="production"){
|
|
| 188 | + if ($environment==="production") {
|
|
| 190 | 189 | |
| 191 | - $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
|
|
| 192 | - $this->app->register('productionLogMessage',core()->out->outputFormatter($productionLogMessage));
|
|
| 190 | + $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']);
|
|
| 191 | + $this->app->register('productionLogMessage', core()->out->outputFormatter($productionLogMessage));
|
|
| 193 | 192 | } |
| 194 | 193 | |
| 195 | - if(app()->has('requestExpected') && config('app.requestWithError')===true){
|
|
| 194 | + if (app()->has('requestExpected') && config('app.requestWithError')===true) {
|
|
| 196 | 195 | $appException['request']['expected'] = app()->get('requestExpected');
|
| 197 | 196 | } |
| 198 | 197 | |
| 199 | 198 | |
| 200 | 199 | //set json app exception |
| 201 | - core()->routerResult=$appException; |
|
| 200 | + core()->routerResult = $appException; |
|
| 202 | 201 | |
| 203 | 202 | $restaOutHandle = null; |
| 204 | 203 | |
| 205 | - if(!defined('responseApp')){
|
|
| 204 | + if (!defined('responseApp')) {
|
|
| 206 | 205 | |
| 207 | - $restaOutHandle=core()->out->handle(); |
|
| 206 | + $restaOutHandle = core()->out->handle(); |
|
| 208 | 207 | } |
| 209 | 208 | |
| 210 | - if($restaOutHandle===null){
|
|
| 209 | + if ($restaOutHandle===null) {
|
|
| 211 | 210 | |
| 212 | 211 | //header set and symfony response call |
| 213 | 212 | header('Content-type:application/json;charset=utf-8');
|
@@ -215,7 +214,7 @@ discard block |
||
| 215 | 214 | echo json_encode(core()->out->outputFormatter($appException)); |
| 216 | 215 | exit(); |
| 217 | 216 | } |
| 218 | - else{
|
|
| 217 | + else {
|
|
| 219 | 218 | echo $restaOutHandle; |
| 220 | 219 | exit(); |
| 221 | 220 | } |
@@ -226,7 +225,7 @@ discard block |
||
| 226 | 225 | * @param $environment |
| 227 | 226 | * @return mixed |
| 228 | 227 | */ |
| 229 | - private function getAppException($environment,$message) |
|
| 228 | + private function getAppException($environment, $message) |
|
| 230 | 229 | {
|
| 231 | 230 | return $this->data['appExceptionSuccess']+$this->data['exception']::$environment( |
| 232 | 231 | $this->data['errNo'], |
@@ -244,18 +243,18 @@ discard block |
||
| 244 | 243 | public function fatalErrorShutdownHandler() |
| 245 | 244 | {
|
| 246 | 245 | //get fatal error |
| 247 | - $last_error =error_get_last(); |
|
| 246 | + $last_error = error_get_last(); |
|
| 248 | 247 | |
| 249 | 248 | $this->inStactTrace($last_error); |
| 250 | 249 | |
| 251 | - if($last_error!==null){
|
|
| 250 | + if ($last_error!==null) {
|
|
| 252 | 251 | |
| 253 | - if(!defined('methodName')){
|
|
| 252 | + if (!defined('methodName')) {
|
|
| 254 | 253 | |
| 255 | - define('methodName',null);
|
|
| 254 | + define('methodName', null);
|
|
| 256 | 255 | } |
| 257 | 256 | |
| 258 | - if(isset(core()->exceptionFile)){
|
|
| 257 | + if (isset(core()->exceptionFile)) {
|
|
| 259 | 258 | $last_error['file'] = core()->exceptionFile; |
| 260 | 259 | $last_error['line'] = core()->exceptionLine; |
| 261 | 260 | } |
@@ -275,12 +274,12 @@ discard block |
||
| 275 | 274 | */ |
| 276 | 275 | public function inStactTrace($error) |
| 277 | 276 | {
|
| 278 | - if(isset(core()->urlComponent)){
|
|
| 279 | - if(!preg_match('@'.core()->urlComponent['project'].'@',$error['file']) && !isset(core()->exceptionFile)){
|
|
| 280 | - if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
|
|
| 281 | - $errorMessage = explode(":",$result[1]);
|
|
| 282 | - $this->app->register('exceptionFile',$errorMessage[0]);
|
|
| 283 | - $this->app->register('exceptionLine',$errorMessage[1]);
|
|
| 277 | + if (isset(core()->urlComponent)) {
|
|
| 278 | + if (!preg_match('@'.core()->urlComponent['project'].'@', $error['file']) && !isset(core()->exceptionFile)) {
|
|
| 279 | + if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
|
|
| 280 | + $errorMessage = explode(":", $result[1]);
|
|
| 281 | + $this->app->register('exceptionFile', $errorMessage[0]);
|
|
| 282 | + $this->app->register('exceptionLine', $errorMessage[1]);
|
|
| 284 | 283 | } |
| 285 | 284 | } |
| 286 | 285 | } |
@@ -289,75 +288,75 @@ discard block |
||
| 289 | 288 | /** |
| 290 | 289 | * @return void|mixed |
| 291 | 290 | */ |
| 292 | - private function getLangMessageForException(){
|
|
| 291 | + private function getLangMessageForException() {
|
|
| 293 | 292 | |
| 294 | 293 | $clone = clone $this; |
| 295 | 294 | |
| 296 | - if(property_exists(core(),'exceptionTranslate')){
|
|
| 295 | + if (property_exists(core(), 'exceptionTranslate')) {
|
|
| 297 | 296 | |
| 298 | - $langMessage=trans('exception.'.core()->exceptionTranslate);
|
|
| 297 | + $langMessage = trans('exception.'.core()->exceptionTranslate);
|
|
| 299 | 298 | |
| 300 | - if(!is_null($langMessage) && property_exists(core(),'exceptionTranslateParams')){
|
|
| 299 | + if (!is_null($langMessage) && property_exists(core(), 'exceptionTranslateParams')) {
|
|
| 301 | 300 | |
| 302 | - if(count(core()->exceptionTranslateParams[core()->exceptionTranslate])){
|
|
| 303 | - foreach (core()->exceptionTranslateParams[core()->exceptionTranslate] as $key=>$value){
|
|
| 304 | - $langMessage=preg_replace('@\('.$key.'\)@is',$value,$langMessage);
|
|
| 301 | + if (count(core()->exceptionTranslateParams[core()->exceptionTranslate])) {
|
|
| 302 | + foreach (core()->exceptionTranslateParams[core()->exceptionTranslate] as $key=>$value) {
|
|
| 303 | + $langMessage = preg_replace('@\('.$key.'\)@is', $value, $langMessage);
|
|
| 305 | 304 | } |
| 306 | 305 | } |
| 307 | 306 | } |
| 308 | 307 | |
| 309 | - if($langMessage!==null){
|
|
| 310 | - $this->data['errStrReal']=$langMessage; |
|
| 308 | + if ($langMessage!==null) {
|
|
| 309 | + $this->data['errStrReal'] = $langMessage; |
|
| 311 | 310 | } |
| 312 | 311 | } |
| 313 | 312 | |
| 314 | - if(class_exists($this->data['errorClassNamespace'])){
|
|
| 313 | + if (class_exists($this->data['errorClassNamespace'])) {
|
|
| 315 | 314 | |
| 316 | 315 | ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
|
| 317 | - if(property_exists($this,'lang')){
|
|
| 318 | - $clone->lang=$this->lang; |
|
| 316 | + if (property_exists($this, 'lang')) {
|
|
| 317 | + $clone->lang = $this->lang; |
|
| 319 | 318 | } |
| 320 | 319 | }); |
| 321 | 320 | } |
| 322 | 321 | |
| 323 | - $this->data['lang']=$lang=$clone->lang; |
|
| 322 | + $this->data['lang'] = $lang = $clone->lang; |
|
| 324 | 323 | |
| 325 | - if($lang!==null){
|
|
| 326 | - $langMessage=trans('exception.'.$lang);
|
|
| 324 | + if ($lang!==null) {
|
|
| 325 | + $langMessage = trans('exception.'.$lang);
|
|
| 327 | 326 | } |
| 328 | - else{
|
|
| 329 | - $langMessage=null; |
|
| 327 | + else {
|
|
| 328 | + $langMessage = null; |
|
| 330 | 329 | } |
| 331 | 330 | |
| 332 | 331 | |
| 333 | - if($langMessage!==null){
|
|
| 334 | - $this->data['errStrReal']=$langMessage; |
|
| 332 | + if ($langMessage!==null) {
|
|
| 333 | + $this->data['errStrReal'] = $langMessage; |
|
| 335 | 334 | } |
| 336 | 335 | } |
| 337 | 336 | |
| 338 | 337 | /** |
| 339 | 338 | * @return void|mixed |
| 340 | 339 | */ |
| 341 | - private function getUncaughtProcess(){
|
|
| 340 | + private function getUncaughtProcess() {
|
|
| 342 | 341 | |
| 343 | 342 | // catch exception via preg match |
| 344 | 343 | // and then clear the Uncaught statement from inside. |
| 345 | - if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
|
|
| 344 | + if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
|
|
| 346 | 345 | |
| 347 | - $this->data['errType']=trim(str_replace('Uncaught','',$errArr[1]));
|
|
| 348 | - $this->data['errorClassNamespace']=$this->data['errType']; |
|
| 346 | + $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
|
|
| 347 | + $this->data['errorClassNamespace'] = $this->data['errType']; |
|
| 349 | 348 | } |
| 350 | 349 | |
| 351 | - if(preg_match('@Uncaught@is',$this->data['errStrReal'])
|
|
| 352 | - && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
|
|
| 353 | - $this->data['errStrReal']=trim($errStrRealArray[2]); |
|
| 350 | + if (preg_match('@Uncaught@is', $this->data['errStrReal'])
|
|
| 351 | + && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
|
|
| 352 | + $this->data['errStrReal'] = trim($errStrRealArray[2]); |
|
| 354 | 353 | } |
| 355 | 354 | |
| 356 | - if($this->data['errType']==="Undefined"){
|
|
| 357 | - $this->data['errStrReal']=$this->data['errStrReal']; |
|
| 355 | + if ($this->data['errType']==="Undefined") {
|
|
| 356 | + $this->data['errStrReal'] = $this->data['errStrReal']; |
|
| 358 | 357 | } |
| 359 | - else{
|
|
| 360 | - $this->data['errContext']['trace']=$this->data['errStrReal']; |
|
| 358 | + else {
|
|
| 359 | + $this->data['errContext']['trace'] = $this->data['errStrReal']; |
|
| 361 | 360 | } |
| 362 | 361 | } |
| 363 | 362 | |