@@ -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 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param null|string $errLine |
| 127 | 127 | * @param null|string $errContext |
| 128 | 128 | */ |
| 129 | - public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null) |
|
| 129 | + public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null) |
|
| 130 | 130 | {
|
| 131 | 131 | // in case of a deficiency, |
| 132 | 132 | // we need to boot our general needs to be needed for the exception. |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | //get lang message for exception |
| 154 | 154 | $this->getLangMessageForException(); |
| 155 | 155 | |
| 156 | - if($this->app->has('exceptiontrace')){
|
|
| 156 | + if ($this->app->has('exceptiontrace')) {
|
|
| 157 | 157 | |
| 158 | 158 | $customExceptionTrace = $this->app['exceptiontrace']; |
| 159 | 159 | $this->data['errFile'] = $customExceptionTrace['file']; |
@@ -162,37 +162,36 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $environment = $this->app->environment(); |
| 164 | 164 | |
| 165 | - $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']); |
|
| 165 | + $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']); |
|
| 166 | 166 | |
| 167 | - if(Str::startsWith($vendorDirectory,'vendor') |
|
| 168 | - && Str::startsWith($vendorDirectory,'vendor/php-resta')===false) |
|
| 167 | + if (Str::startsWith($vendorDirectory, 'vendor') |
|
| 168 | + && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false) |
|
| 169 | 169 | {
|
| 170 | 170 | $externalMessage = ($environment==="production") ? |
| 171 | - 'An unexpected external error has occurred' : |
|
| 172 | - $this->data['errStrReal']; |
|
| 171 | + 'An unexpected external error has occurred' : $this->data['errStrReal']; |
|
| 173 | 172 | |
| 174 | - $this->result = $this->getAppException($environment,$externalMessage); |
|
| 173 | + $this->result = $this->getAppException($environment, $externalMessage); |
|
| 175 | 174 | |
| 176 | 175 | |
| 177 | 176 | //Get or Set the HTTP response code |
| 178 | 177 | http_response_code(500); |
| 179 | 178 | $this->app->terminate('responseStatus');
|
| 180 | - $this->app->register('responseStatus',500);
|
|
| 179 | + $this->app->register('responseStatus', 500);
|
|
| 181 | 180 | |
| 182 | 181 | |
| 183 | 182 | } |
| 184 | - else{
|
|
| 183 | + else {
|
|
| 185 | 184 | |
| 186 | - $this->result = $this->getAppException($environment,$this->data['errStrReal']); |
|
| 185 | + $this->result = $this->getAppException($environment, $this->data['errStrReal']); |
|
| 187 | 186 | |
| 188 | 187 | //Get or Set the HTTP response code |
| 189 | 188 | http_response_code($this->data['status']); |
| 190 | 189 | } |
| 191 | 190 | |
| 192 | - if($environment==="production"){
|
|
| 191 | + if ($environment==="production") {
|
|
| 193 | 192 | |
| 194 | - $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
|
|
| 195 | - $this->app->register('productionLogMessage',$this->app->get('out')->outputFormatter($productionLogMessage));
|
|
| 193 | + $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']);
|
|
| 194 | + $this->app->register('productionLogMessage', $this->app->get('out')->outputFormatter($productionLogMessage));
|
|
| 196 | 195 | } |
| 197 | 196 | |
| 198 | 197 | // exception extender The exception information |
@@ -201,15 +200,15 @@ discard block |
||
| 201 | 200 | |
| 202 | 201 | |
| 203 | 202 | //set json app exception |
| 204 | - $this->app->register('routerResult',$this->result);
|
|
| 203 | + $this->app->register('routerResult', $this->result);
|
|
| 205 | 204 | |
| 206 | 205 | $restaOutHandle = null; |
| 207 | 206 | |
| 208 | - if(!defined('responseApp')){
|
|
| 207 | + if (!defined('responseApp')) {
|
|
| 209 | 208 | $restaOutHandle = $this->app->get('out')->handle();
|
| 210 | 209 | } |
| 211 | 210 | |
| 212 | - if($restaOutHandle===null){
|
|
| 211 | + if ($restaOutHandle===null) {
|
|
| 213 | 212 | |
| 214 | 213 | //header set and symfony response call |
| 215 | 214 | header('Content-type:application/json;charset=utf-8');
|
@@ -217,7 +216,7 @@ discard block |
||
| 217 | 216 | echo json_encode($this->app->get('out')->outputFormatter($this->result));
|
| 218 | 217 | exit(); |
| 219 | 218 | } |
| 220 | - else{
|
|
| 219 | + else {
|
|
| 221 | 220 | echo $restaOutHandle; |
| 222 | 221 | exit(); |
| 223 | 222 | } |
@@ -227,7 +226,7 @@ discard block |
||
| 227 | 226 | * @param $environment |
| 228 | 227 | * @return mixed |
| 229 | 228 | */ |
| 230 | - private function getAppException($environment,$message) |
|
| 229 | + private function getAppException($environment, $message) |
|
| 231 | 230 | {
|
| 232 | 231 | return $this->data['appExceptionSuccess']+$this->data['exception']::$environment( |
| 233 | 232 | $this->data['errNo'], |
@@ -247,7 +246,7 @@ discard block |
||
| 247 | 246 | private function getExceptionExtender() |
| 248 | 247 | {
|
| 249 | 248 | return $this->app->resolve( |
| 250 | - $this->app->get('macro')->call('exceptionExtender',function(){
|
|
| 249 | + $this->app->get('macro')->call('exceptionExtender', function() {
|
|
| 251 | 250 | return ExceptionExtender::class; |
| 252 | 251 | }), |
| 253 | 252 | ['result'=>$this->result])->getResult(); |
@@ -265,13 +264,13 @@ discard block |
||
| 265 | 264 | |
| 266 | 265 | $this->inStackTrace($last_error); |
| 267 | 266 | |
| 268 | - if(!is_null($last_error)){
|
|
| 267 | + if (!is_null($last_error)) {
|
|
| 269 | 268 | |
| 270 | - if(!defined('methodName')){
|
|
| 271 | - define('methodName',null);
|
|
| 269 | + if (!defined('methodName')) {
|
|
| 270 | + define('methodName', null);
|
|
| 272 | 271 | } |
| 273 | 272 | |
| 274 | - if($this->app->has('exceptionFile')){
|
|
| 273 | + if ($this->app->has('exceptionFile')) {
|
|
| 275 | 274 | $last_error['file'] = $this->app['exceptionFile']; |
| 276 | 275 | $last_error['line'] = $this->app['exceptionLine']; |
| 277 | 276 | } |
@@ -291,13 +290,13 @@ discard block |
||
| 291 | 290 | */ |
| 292 | 291 | public function inStackTrace($error) |
| 293 | 292 | {
|
| 294 | - if($this->app->has('urlComponent')){
|
|
| 295 | - if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file'])
|
|
| 296 | - && !$this->app->has('exceptionFile')){
|
|
| 297 | - if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
|
|
| 298 | - $errorMessage = explode(":",$result[1]);
|
|
| 299 | - $this->app->register('exceptionFile',$errorMessage[0]);
|
|
| 300 | - $this->app->register('exceptionLine',$errorMessage[1]);
|
|
| 293 | + if ($this->app->has('urlComponent')) {
|
|
| 294 | + if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file'])
|
|
| 295 | + && !$this->app->has('exceptionFile')) {
|
|
| 296 | + if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
|
|
| 297 | + $errorMessage = explode(":", $result[1]);
|
|
| 298 | + $this->app->register('exceptionFile', $errorMessage[0]);
|
|
| 299 | + $this->app->register('exceptionLine', $errorMessage[1]);
|
|
| 301 | 300 | } |
| 302 | 301 | } |
| 303 | 302 | } |
@@ -310,33 +309,33 @@ discard block |
||
| 310 | 309 | {
|
| 311 | 310 | $clone = clone $this; |
| 312 | 311 | |
| 313 | - if($this->app->has('exceptionTranslate')){
|
|
| 312 | + if ($this->app->has('exceptionTranslate')) {
|
|
| 314 | 313 | |
| 315 | 314 | $langMessage = trans('exception.'.$this->app->get('exceptionTranslate'));
|
| 316 | 315 | |
| 317 | - if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){
|
|
| 316 | + if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) {
|
|
| 318 | 317 | |
| 319 | - if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){
|
|
| 320 | - foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){
|
|
| 318 | + if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) {
|
|
| 319 | + foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) {
|
|
| 321 | 320 | |
| 322 | 321 | $valueLangName = !is_null(trans('default.'.$value)) ? trans('default.'.$value) : $value;
|
| 323 | - $langMessage = preg_replace('@\('.$key.'\)@is',$valueLangName,$langMessage);
|
|
| 322 | + $langMessage = preg_replace('@\('.$key.'\)@is', $valueLangName, $langMessage);
|
|
| 324 | 323 | } |
| 325 | 324 | } |
| 326 | 325 | } |
| 327 | 326 | |
| 328 | - if($langMessage!==null){
|
|
| 327 | + if ($langMessage!==null) {
|
|
| 329 | 328 | $this->data['errStrReal'] = $langMessage; |
| 330 | 329 | } |
| 331 | 330 | } |
| 332 | 331 | |
| 333 | - if(class_exists($this->data['errorClassNamespace']) |
|
| 332 | + if (class_exists($this->data['errorClassNamespace']) |
|
| 334 | 333 | && |
| 335 | - (Str::startsWith($this->data['errorClassNamespace'],'App') |
|
| 336 | - || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){
|
|
| 334 | + (Str::startsWith($this->data['errorClassNamespace'], 'App') |
|
| 335 | + || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) {
|
|
| 337 | 336 | |
| 338 | 337 | ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
|
| 339 | - if(property_exists($this,'lang')){
|
|
| 338 | + if (property_exists($this, 'lang')) {
|
|
| 340 | 339 | $clone->setLang($this->lang); |
| 341 | 340 | } |
| 342 | 341 | }); |
@@ -346,7 +345,7 @@ discard block |
||
| 346 | 345 | |
| 347 | 346 | $langMessage = (!is_null($this->data['lang'])) ? trans('exception.'.$this->data['lang']) : null;
|
| 348 | 347 | |
| 349 | - if($langMessage!==null){
|
|
| 348 | + if ($langMessage!==null) {
|
|
| 350 | 349 | $this->data['errStrReal'] = $langMessage; |
| 351 | 350 | } |
| 352 | 351 | } |
@@ -360,14 +359,14 @@ discard block |
||
| 360 | 359 | {
|
| 361 | 360 | // catch exception via preg match |
| 362 | 361 | // and then clear the Uncaught statement from inside. |
| 363 | - if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
|
|
| 362 | + if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
|
|
| 364 | 363 | |
| 365 | - $this->data['errType'] = trim(str_replace('Uncaught','',$errArr[1]));
|
|
| 364 | + $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
|
|
| 366 | 365 | $this->data['errorClassNamespace'] = $this->data['errType']; |
| 367 | 366 | } |
| 368 | 367 | |
| 369 | - if(preg_match('@Uncaught@is',$this->data['errStrReal'])
|
|
| 370 | - && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
|
|
| 368 | + if (preg_match('@Uncaught@is', $this->data['errStrReal'])
|
|
| 369 | + && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
|
|
| 371 | 370 | $this->data['errStrReal'] = trim($errStrRealArray[2]); |
| 372 | 371 | } |
| 373 | 372 | |
@@ -387,7 +386,7 @@ discard block |
||
| 387 | 386 | /** |
| 388 | 387 | * @param null|string $lang |
| 389 | 388 | */ |
| 390 | - public function setLang($lang=null) |
|
| 389 | + public function setLang($lang = null) |
|
| 391 | 390 | {
|
| 392 | 391 | $this->lang = $lang; |
| 393 | 392 | } |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | * @param callable $callback |
| 33 | 33 | * @return mixed|null |
| 34 | 34 | */ |
| 35 | - public function call($macro,callable $callback) |
|
| 35 | + public function call($macro, callable $callback) |
|
| 36 | 36 | {
|
| 37 | - if(!is_null($macro)){
|
|
| 37 | + if (!is_null($macro)) {
|
|
| 38 | 38 | |
| 39 | 39 | //get macro class from kernel macros |
| 40 | 40 | $macroCall = config('kernel.macros.'.$macro);
|
| 41 | 41 | |
| 42 | 42 | //if macroCall class is available and an object. |
| 43 | - if(!is_null($macroCall) && Utils::isNamespaceExists($macroCall)){
|
|
| 43 | + if (!is_null($macroCall) && Utils::isNamespaceExists($macroCall)) {
|
|
| 44 | 44 | return $macroCall; |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param bool $static |
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | - protected function checkMacroConditions($static=false) |
|
| 57 | + protected function checkMacroConditions($static = false) |
|
| 58 | 58 | {
|
| 59 | 59 | return is_string($this->macro) && |
| 60 | 60 | Utils::isNamespaceExists($this->macro) && |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @param bool $static |
| 68 | 68 | * @return bool |
| 69 | 69 | */ |
| 70 | - protected function checkMacroInstanceOf($static=false) |
|
| 70 | + protected function checkMacroInstanceOf($static = false) |
|
| 71 | 71 | {
|
| 72 | - if($static){
|
|
| 72 | + if ($static) {
|
|
| 73 | 73 | return true; |
| 74 | 74 | } |
| 75 | 75 | return $this->app->resolve($this->macro) instanceof MacroAbleContracts; |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | * @param callable $callback |
| 83 | 83 | * @return mixed |
| 84 | 84 | */ |
| 85 | - public function get($method,callable $callback) |
|
| 85 | + public function get($method, callable $callback) |
|
| 86 | 86 | {
|
| 87 | - if($this->isMacro){
|
|
| 87 | + if ($this->isMacro) {
|
|
| 88 | 88 | |
| 89 | - if(method_exists($resolve = $this->app->resolve($this->macro),$method)){
|
|
| 89 | + if (method_exists($resolve = $this->app->resolve($this->macro), $method)) {
|
|
| 90 | 90 | return $resolve->macro($this->class); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * @param $class |
| 111 | 111 | * @return $this |
| 112 | 112 | */ |
| 113 | - public function isMacro($class,$static=false) |
|
| 113 | + public function isMacro($class, $static = false) |
|
| 114 | 114 | {
|
| 115 | 115 | // if the macro class is a valid object, |
| 116 | 116 | // then this macro will return a boolean value if it has the specified methode. |
| 117 | - if($this->checkMacroConditions($static)){
|
|
| 117 | + if ($this->checkMacroConditions($static)) {
|
|
| 118 | 118 | |
| 119 | 119 | $this->isMacro = true; |
| 120 | 120 | $this->class = $class; |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * @param $method |
| 143 | 143 | * @return mixed |
| 144 | 144 | */ |
| 145 | - public function with($macro,$concrete,$method=null) |
|
| 145 | + public function with($macro, $concrete, $method = null) |
|
| 146 | 146 | {
|
| 147 | - if($this->macro === null){
|
|
| 148 | - return $this($macro)->isMacro($concrete)->get($method,function() use($concrete){
|
|
| 147 | + if ($this->macro===null) {
|
|
| 148 | + return $this($macro)->isMacro($concrete)->get($method, function() use($concrete){
|
|
| 149 | 149 | return $concrete; |
| 150 | 150 | }); |
| 151 | 151 | } |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * @param $method |
| 160 | 160 | * @return mixed |
| 161 | 161 | */ |
| 162 | - public function withStatic($macro,$concrete) |
|
| 162 | + public function withStatic($macro, $concrete) |
|
| 163 | 163 | {
|
| 164 | - return $this($macro)->isMacro($concrete,true)->get(null,is_callable($concrete) ? |
|
| 164 | + return $this($macro)->isMacro($concrete, true)->get(null, is_callable($concrete) ? |
|
| 165 | 165 | $concrete : function() use($concrete){
|
| 166 | 166 | return $concrete; |
| 167 | 167 | }); |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | * @param null|string $macro |
| 174 | 174 | * @return $this |
| 175 | 175 | */ |
| 176 | - public function __invoke($macro=null) |
|
| 176 | + public function __invoke($macro = null) |
|
| 177 | 177 | {
|
| 178 | - if($macro!==null){
|
|
| 178 | + if ($macro!==null) {
|
|
| 179 | 179 | $this->macro = $macro; |
| 180 | 180 | } |
| 181 | 181 | return $this; |