@@ -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,40 +163,39 @@ 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(preg_match('@vendor.*\.php@is',$vendorDirectory,$vd)){
|
|
| 168 | + if (preg_match('@vendor.*\.php@is', $vendorDirectory, $vd)) {
|
|
| 169 | 169 | $vendorDirectory = $vd[0]; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if(Str::startsWith($vendorDirectory,'vendor') |
|
| 173 | - && Str::startsWith($vendorDirectory,'vendor/php-resta')===false) |
|
| 172 | + if (Str::startsWith($vendorDirectory, 'vendor') |
|
| 173 | + && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false) |
|
| 174 | 174 | {
|
| 175 | 175 | |
| 176 | 176 | $externalMessage = ($environment==="production") ? |
| 177 | - 'An unexpected external error has occurred' : |
|
| 178 | - $this->data['errStrReal']; |
|
| 177 | + 'An unexpected external error has occurred' : $this->data['errStrReal']; |
|
| 179 | 178 | |
| 180 | - $this->result = $this->getAppException($environment,$externalMessage); |
|
| 179 | + $this->result = $this->getAppException($environment, $externalMessage); |
|
| 181 | 180 | |
| 182 | 181 | |
| 183 | 182 | //Get or Set the HTTP response code |
| 184 | 183 | http_response_code(500); |
| 185 | 184 | $this->app->terminate('responseStatus');
|
| 186 | - $this->app->register('responseStatus',500);
|
|
| 185 | + $this->app->register('responseStatus', 500);
|
|
| 187 | 186 | |
| 188 | 187 | |
| 189 | 188 | } |
| 190 | - else{
|
|
| 189 | + else {
|
|
| 191 | 190 | |
| 192 | - if($environment=='production' && preg_match('@SQLSTATE@is',$this->data['errStrReal'])){
|
|
| 191 | + if ($environment=='production' && preg_match('@SQLSTATE@is', $this->data['errStrReal'])) {
|
|
| 193 | 192 | $externalMessage = 'An unexpected external error has occurred'; |
| 194 | 193 | } |
| 195 | - else{
|
|
| 194 | + else {
|
|
| 196 | 195 | $externalMessage = $this->data['errStrReal']; |
| 197 | 196 | } |
| 198 | 197 | |
| 199 | - $this->result = $this->getAppException($environment,$externalMessage); |
|
| 198 | + $this->result = $this->getAppException($environment, $externalMessage); |
|
| 200 | 199 | |
| 201 | 200 | //Get or Set the HTTP response code |
| 202 | 201 | http_response_code($this->data['status']); |
@@ -206,41 +205,41 @@ discard block |
||
| 206 | 205 | // that is presented as an extra to the exception result set. |
| 207 | 206 | $this->result = $this->getExceptionExtender(); |
| 208 | 207 | |
| 209 | - if($environment==="production"){
|
|
| 208 | + if ($environment==="production") {
|
|
| 210 | 209 | |
| 211 | - $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
|
|
| 212 | - $this->app->register('productionLogMessage',$this->app->get('out')->outputFormatter($productionLogMessage));
|
|
| 210 | + $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']);
|
|
| 211 | + $this->app->register('productionLogMessage', $this->app->get('out')->outputFormatter($productionLogMessage));
|
|
| 213 | 212 | } |
| 214 | 213 | |
| 215 | 214 | //set json app exception |
| 216 | - $this->app->register('routerResult',$this->result);
|
|
| 215 | + $this->app->register('routerResult', $this->result);
|
|
| 217 | 216 | |
| 218 | - if($this->app->has('exceptionContainer')){
|
|
| 217 | + if ($this->app->has('exceptionContainer')) {
|
|
| 219 | 218 | $exceptionContainer = $this->app->get('exceptionContainer');
|
| 220 | - $exceptionContainer($this->result,$this->data['status']); |
|
| 219 | + $exceptionContainer($this->result, $this->data['status']); |
|
| 221 | 220 | } |
| 222 | 221 | |
| 223 | - if($this->app->has('exceptionExtenderContainer')){
|
|
| 222 | + if ($this->app->has('exceptionExtenderContainer')) {
|
|
| 224 | 223 | $exceptionExtenderContainer = $this->app->get('exceptionExtenderContainer');
|
| 225 | 224 | $this->result = $exceptionExtenderContainer($this->result); |
| 226 | 225 | } |
| 227 | 226 | |
| 228 | 227 | $restaOutHandle = null; |
| 229 | 228 | |
| 230 | - if(!defined('responseApp')){
|
|
| 229 | + if (!defined('responseApp')) {
|
|
| 231 | 230 | $restaOutHandle = $this->app->get('out')->handle();
|
| 232 | 231 | } |
| 233 | 232 | |
| 234 | 233 | header("HTTP/1.1 ".$this->data['status']);
|
| 235 | 234 | |
| 236 | - if($restaOutHandle===null){
|
|
| 235 | + if ($restaOutHandle===null) {
|
|
| 237 | 236 | |
| 238 | 237 | //header set and symfony response call |
| 239 | 238 | header('Content-type:application/json;charset=utf-8');
|
| 240 | 239 | |
| 241 | 240 | echo json_encode($this->app->get('out')->outputFormatter($this->result));
|
| 242 | 241 | } |
| 243 | - else{
|
|
| 242 | + else {
|
|
| 244 | 243 | echo $restaOutHandle; |
| 245 | 244 | } |
| 246 | 245 | |
@@ -251,7 +250,7 @@ discard block |
||
| 251 | 250 | * @param $environment |
| 252 | 251 | * @return mixed |
| 253 | 252 | */ |
| 254 | - private function getAppException($environment,$message) |
|
| 253 | + private function getAppException($environment, $message) |
|
| 255 | 254 | {
|
| 256 | 255 | return $this->data['appExceptionSuccess']+$this->data['exception']::$environment( |
| 257 | 256 | $this->data['errNo'], |
@@ -271,7 +270,7 @@ discard block |
||
| 271 | 270 | private function getExceptionExtender() |
| 272 | 271 | {
|
| 273 | 272 | return $this->app->resolve( |
| 274 | - $this->app->get('macro')->call('exceptionExtender',function(){
|
|
| 273 | + $this->app->get('macro')->call('exceptionExtender', function() {
|
|
| 275 | 274 | return ExceptionExtender::class; |
| 276 | 275 | }), |
| 277 | 276 | ['result'=>$this->result])->getResult(); |
@@ -289,13 +288,13 @@ discard block |
||
| 289 | 288 | |
| 290 | 289 | $this->inStackTrace($last_error); |
| 291 | 290 | |
| 292 | - if(!is_null($last_error)){
|
|
| 291 | + if (!is_null($last_error)) {
|
|
| 293 | 292 | |
| 294 | - if(!defined('methodName')){
|
|
| 295 | - define('methodName',null);
|
|
| 293 | + if (!defined('methodName')) {
|
|
| 294 | + define('methodName', null);
|
|
| 296 | 295 | } |
| 297 | 296 | |
| 298 | - if($this->app->has('exceptionFile')){
|
|
| 297 | + if ($this->app->has('exceptionFile')) {
|
|
| 299 | 298 | $last_error['file'] = $this->app['exceptionFile']; |
| 300 | 299 | $last_error['line'] = $this->app['exceptionLine']; |
| 301 | 300 | } |
@@ -315,13 +314,13 @@ discard block |
||
| 315 | 314 | */ |
| 316 | 315 | public function inStackTrace($error) |
| 317 | 316 | {
|
| 318 | - if($this->app->has('urlComponent')){
|
|
| 319 | - if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file'])
|
|
| 320 | - && !$this->app->has('exceptionFile')){
|
|
| 321 | - if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
|
|
| 322 | - $errorMessage = explode(":",$result[1]);
|
|
| 323 | - $this->app->register('exceptionFile',$errorMessage[0]);
|
|
| 324 | - $this->app->register('exceptionLine',$errorMessage[1]);
|
|
| 317 | + if ($this->app->has('urlComponent')) {
|
|
| 318 | + if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file'])
|
|
| 319 | + && !$this->app->has('exceptionFile')) {
|
|
| 320 | + if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
|
|
| 321 | + $errorMessage = explode(":", $result[1]);
|
|
| 322 | + $this->app->register('exceptionFile', $errorMessage[0]);
|
|
| 323 | + $this->app->register('exceptionLine', $errorMessage[1]);
|
|
| 325 | 324 | } |
| 326 | 325 | } |
| 327 | 326 | } |
@@ -334,33 +333,33 @@ discard block |
||
| 334 | 333 | {
|
| 335 | 334 | $clone = clone $this; |
| 336 | 335 | |
| 337 | - if($this->app->has('exceptionTranslate')){
|
|
| 336 | + if ($this->app->has('exceptionTranslate')) {
|
|
| 338 | 337 | |
| 339 | 338 | $langMessage = trans('exception.'.$this->app->get('exceptionTranslate'));
|
| 340 | 339 | |
| 341 | - if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){
|
|
| 340 | + if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) {
|
|
| 342 | 341 | |
| 343 | - if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){
|
|
| 344 | - foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){
|
|
| 342 | + if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) {
|
|
| 343 | + foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) {
|
|
| 345 | 344 | |
| 346 | 345 | $valueLangName = !is_null(trans('default.'.$value)) ? trans('default.'.$value) : $value;
|
| 347 | - $langMessage = preg_replace('@\('.$key.'\)@is',$valueLangName,$langMessage);
|
|
| 346 | + $langMessage = preg_replace('@\('.$key.'\)@is', $valueLangName, $langMessage);
|
|
| 348 | 347 | } |
| 349 | 348 | } |
| 350 | 349 | } |
| 351 | 350 | |
| 352 | - if($langMessage!==null){
|
|
| 351 | + if ($langMessage!==null) {
|
|
| 353 | 352 | $this->data['errStrReal'] = $langMessage; |
| 354 | 353 | } |
| 355 | 354 | } |
| 356 | 355 | |
| 357 | - if(class_exists($this->data['errorClassNamespace']) |
|
| 356 | + if (class_exists($this->data['errorClassNamespace']) |
|
| 358 | 357 | && |
| 359 | - (Str::startsWith($this->data['errorClassNamespace'],'App') |
|
| 360 | - || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){
|
|
| 358 | + (Str::startsWith($this->data['errorClassNamespace'], 'App') |
|
| 359 | + || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) {
|
|
| 361 | 360 | |
| 362 | 361 | ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
|
| 363 | - if(property_exists($this,'lang')){
|
|
| 362 | + if (property_exists($this, 'lang')) {
|
|
| 364 | 363 | $clone->setLang($this->lang); |
| 365 | 364 | } |
| 366 | 365 | }); |
@@ -370,7 +369,7 @@ discard block |
||
| 370 | 369 | |
| 371 | 370 | $langMessage = (!is_null($this->data['lang'])) ? trans('exception.'.$this->data['lang']) : null;
|
| 372 | 371 | |
| 373 | - if($langMessage!==null){
|
|
| 372 | + if ($langMessage!==null) {
|
|
| 374 | 373 | $this->data['errStrReal'] = $langMessage; |
| 375 | 374 | } |
| 376 | 375 | } |
@@ -384,14 +383,14 @@ discard block |
||
| 384 | 383 | {
|
| 385 | 384 | // catch exception via preg match |
| 386 | 385 | // and then clear the Uncaught statement from inside. |
| 387 | - if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
|
|
| 386 | + if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
|
|
| 388 | 387 | |
| 389 | - $this->data['errType'] = trim(str_replace('Uncaught','',$errArr[1]));
|
|
| 388 | + $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
|
|
| 390 | 389 | $this->data['errorClassNamespace'] = $this->data['errType']; |
| 391 | 390 | } |
| 392 | 391 | |
| 393 | - if(preg_match('@Uncaught@is',$this->data['errStrReal'])
|
|
| 394 | - && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
|
|
| 392 | + if (preg_match('@Uncaught@is', $this->data['errStrReal'])
|
|
| 393 | + && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
|
|
| 395 | 394 | $this->data['errStrReal'] = trim($errStrRealArray[2]); |
| 396 | 395 | } |
| 397 | 396 | |
@@ -411,7 +410,7 @@ discard block |
||
| 411 | 410 | /** |
| 412 | 411 | * @param null|string $lang |
| 413 | 412 | */ |
| 414 | - public function setLang($lang=null) |
|
| 413 | + public function setLang($lang = null) |
|
| 415 | 414 | {
|
| 416 | 415 | $this->lang = $lang; |
| 417 | 416 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | * @param $urlRoute |
| 44 | 44 | * @return int|string |
| 45 | 45 | */ |
| 46 | - public static function checkArrayEqual($patterns,$urlRoute) |
|
| 46 | + public static function checkArrayEqual($patterns, $urlRoute) |
|
| 47 | 47 | {
|
| 48 | 48 | // calculates the equality difference between |
| 49 | 49 | // the route pattern and the urlRoute value. |
| 50 | - foreach ($patterns as $key=>$pattern){
|
|
| 50 | + foreach ($patterns as $key=>$pattern) {
|
|
| 51 | 51 | |
| 52 | - if(Utils::isArrayEqual($pattern,$urlRoute)){
|
|
| 52 | + if (Utils::isArrayEqual($pattern, $urlRoute)) {
|
|
| 53 | 53 | return $key; |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | {
|
| 69 | 69 | $route = self::getRouteResolve(); |
| 70 | 70 | |
| 71 | - if(isset($route['class'])){
|
|
| 71 | + if (isset($route['class'])) {
|
|
| 72 | 72 | return $route['class']; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | {
|
| 85 | 85 | $route = self::getRouteResolve(); |
| 86 | 86 | |
| 87 | - if(isset($route['method'])){
|
|
| 87 | + if (isset($route['method'])) {
|
|
| 88 | 88 | return $route['method']; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | {
|
| 101 | 101 | $route = self::getRouteResolve(); |
| 102 | 102 | |
| 103 | - if(isset($route['controller'],$route['namespace'])){
|
|
| 103 | + if (isset($route['controller'], $route['namespace'])) {
|
|
| 104 | 104 | return $route['controller'].'/'.$route['namespace']; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | // get routes data and the resolving pattern |
| 118 | 118 | // Both are interrelated. |
| 119 | 119 | $routes = self::getRoutes(); |
| 120 | - $patternResolve = app()->resolve(RouteMatching::class,['route'=>new self()])->getPatternResolve(); |
|
| 120 | + $patternResolve = app()->resolve(RouteMatching::class, ['route'=>new self()])->getPatternResolve(); |
|
| 121 | 121 | |
| 122 | 122 | // we set the route variables for the route assistant. |
| 123 | 123 | self::updateRouteParameters($patternResolve); |
| 124 | 124 | |
| 125 | 125 | //if routes data is available in pattern resolve. |
| 126 | - if(isset($routes['data'][$patternResolve])){
|
|
| 126 | + if (isset($routes['data'][$patternResolve])) {
|
|
| 127 | 127 | |
| 128 | 128 | // if the incoming http value is |
| 129 | 129 | // the same as the real request method, the data is processed. |
| 130 | - if($routes['data'][$patternResolve]['http'] == strtolower(httpMethod)){
|
|
| 130 | + if ($routes['data'][$patternResolve]['http']==strtolower(httpMethod)) {
|
|
| 131 | 131 | |
| 132 | 132 | // we are set the solved pattern to a variable. |
| 133 | 133 | $resolve = $routes['data'][$patternResolve]; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | 'http' => httpMethod(), |
| 141 | 141 | ]; |
| 142 | 142 | |
| 143 | - app()->register('routeResolvedData',$routeResolvedData);
|
|
| 143 | + app()->register('routeResolvedData', $routeResolvedData);
|
|
| 144 | 144 | |
| 145 | 145 | return $routeResolvedData; |
| 146 | 146 | } |
@@ -159,22 +159,22 @@ discard block |
||
| 159 | 159 | {
|
| 160 | 160 | $list = []; |
| 161 | 161 | |
| 162 | - if(isset(static::$routes['pattern'][$patternResolvedKey])){
|
|
| 162 | + if (isset(static::$routes['pattern'][$patternResolvedKey])) {
|
|
| 163 | 163 | |
| 164 | 164 | $routeParameters = static::$routes['pattern'][$patternResolvedKey]; |
| 165 | 165 | $route = route(); |
| 166 | 166 | |
| 167 | - foreach($routeParameters as $key=>$param){
|
|
| 167 | + foreach ($routeParameters as $key=>$param) {
|
|
| 168 | 168 | |
| 169 | - $param = Str::replaceWordArray(['{','}','?'],'',$param);
|
|
| 169 | + $param = Str::replaceWordArray(['{', '}', '?'], '', $param);
|
|
| 170 | 170 | |
| 171 | - if(isset($route[$key])){
|
|
| 171 | + if (isset($route[$key])) {
|
|
| 172 | 172 | $list[$param] = $route[$key]; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - app()->register('routeParams',$list);
|
|
| 177 | + app()->register('routeParams', $list);
|
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | * @param bool $endpoint |
| 184 | 184 | */ |
| 185 | - public function handle($endpoint=true) |
|
| 185 | + public function handle($endpoint = true) |
|
| 186 | 186 | {
|
| 187 | 187 | // we will record the path data for the route. |
| 188 | 188 | // We set the routeMapper variables and the route path. |
| 189 | - self::setPath(function(){
|
|
| 189 | + self::setPath(function() {
|
|
| 190 | 190 | |
| 191 | 191 | // we are sending |
| 192 | 192 | // the controller and routes.php path. |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | // in the paths data, |
| 200 | 200 | // we run the route mapper values and the route files one by one. |
| 201 | - foreach (self::$paths as $mapper=>$controller){
|
|
| 201 | + foreach (self::$paths as $mapper=>$controller) {
|
|
| 202 | 202 | core()->fileSystem->callFile($mapper); |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -209,11 +209,11 @@ discard block |
||
| 209 | 209 | * @param callable $callback |
| 210 | 210 | * @param bool $endpoint |
| 211 | 211 | */ |
| 212 | - public static function setPath(callable $callback,$endpoint=true) |
|
| 212 | + public static function setPath(callable $callback, $endpoint = true) |
|
| 213 | 213 | {
|
| 214 | 214 | $routeDefinitor = call_user_func($callback); |
| 215 | 215 | |
| 216 | - if(isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])){
|
|
| 216 | + if (isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])) {
|
|
| 217 | 217 | |
| 218 | 218 | //the route paths to be saved to the mappers static property. |
| 219 | 219 | static::$mappers['routePaths'][] = $routeDefinitor['routePath']; |
@@ -221,22 +221,22 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | // if there is endpoint, |
| 223 | 223 | // then only that endpoint is transferred into the path |
| 224 | - if(defined('endpoint') && $endpoint){
|
|
| 224 | + if (defined('endpoint') && $endpoint) {
|
|
| 225 | 225 | |
| 226 | 226 | $routeName = endpoint.'Route.php'; |
| 227 | 227 | $routeMapper = $routeDefinitor['routePath'].''.DIRECTORY_SEPARATOR.''.$routeName; |
| 228 | 228 | |
| 229 | - if(file_exists($routeMapper) && !isset(static::$paths[$routeMapper])){
|
|
| 229 | + if (file_exists($routeMapper) && !isset(static::$paths[$routeMapper])) {
|
|
| 230 | 230 | static::$paths[$routeMapper] = $routeDefinitor['controllerPath']; |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | - else{
|
|
| 233 | + else {
|
|
| 234 | 234 | |
| 235 | 235 | // if there is no endpoint, |
| 236 | 236 | // all files in the path of the route are transferred to path. |
| 237 | 237 | $allFilesInThatRoutePath = Utils::glob($routeDefinitor['routePath']); |
| 238 | 238 | |
| 239 | - foreach ($allFilesInThatRoutePath as $item){
|
|
| 239 | + foreach ($allFilesInThatRoutePath as $item) {
|
|
| 240 | 240 | static::$paths[$item] = $routeDefinitor['controllerPath']; |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * @param $function |
| 251 | 251 | * @param null $controller |
| 252 | 252 | */ |
| 253 | - public static function setRoute($params,$function,$controller=null) |
|
| 253 | + public static function setRoute($params, $function, $controller = null) |
|
| 254 | 254 | {
|
| 255 | - [$pattern,$route] = $params; |
|
| 256 | - [$class,$method] = explode("@",$route);
|
|
| 255 | + [$pattern, $route] = $params; |
|
| 256 | + [$class, $method] = explode("@", $route);
|
|
| 257 | 257 | |
| 258 | 258 | $patternList = array_values( |
| 259 | - array_filter(explode("/",$pattern),'strlen')
|
|
| 259 | + array_filter(explode("/", $pattern), 'strlen')
|
|
| 260 | 260 | ); |
| 261 | 261 | |
| 262 | 262 | static::$routes['pattern'][] = $patternList; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | 'http' => $function, |
| 267 | 267 | 'controller' => $controller, |
| 268 | 268 | 'namespace' => static::$namespace, |
| 269 | - 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName,'',static::$namespace)) |
|
| 269 | + 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName, '', static::$namespace)) |
|
| 270 | 270 | ]; |
| 271 | 271 | } |
| 272 | 272 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | * @param null $value |
| 277 | 277 | * @return bool |
| 278 | 278 | */ |
| 279 | - public static function isMatchVaribleRegexPattern($value=null) |
|
| 279 | + public static function isMatchVaribleRegexPattern($value = null) |
|
| 280 | 280 | {
|
| 281 | 281 | // determines if the variable that can be used |
| 282 | 282 | // in the route file meets the regex rule. |
| 283 | - return (preg_match('@\{(.*?)\}@is',$value)) ? true : false;
|
|
| 283 | + return (preg_match('@\{(.*?)\}@is', $value)) ? true : false;
|
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | * @param null $value |
| 291 | 291 | * @return bool |
| 292 | 292 | */ |
| 293 | - public static function isOptionalVaribleRegexPattern($value=null) |
|
| 293 | + public static function isOptionalVaribleRegexPattern($value = null) |
|
| 294 | 294 | {
|
| 295 | 295 | // determines if the variable that can be used |
| 296 | 296 | // in the route file meets the regex rule. |
| 297 | - return preg_match('@\{[a-z]+\?\}@is',$value) ? true : false;
|
|
| 297 | + return preg_match('@\{[a-z]+\?\}@is', $value) ? true : false;
|
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | $application->loadIfNotExistBoot(['middleware']); |
| 320 | 320 | $middlewareProvider = $application['middleware']; |
| 321 | 321 | |
| 322 | - foreach($routeData as $key=>$data) {
|
|
| 322 | + foreach ($routeData as $key=>$data) {
|
|
| 323 | 323 | |
| 324 | 324 | $middlewareProvider->setKeyOdds('endpoint', $data['endpoint']);
|
| 325 | 325 | $middlewareProvider->setKeyOdds('method', $data['method']);
|
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | $afterMiddleware = $middlewareProvider->getShow(); |
| 333 | 333 | |
| 334 | 334 | $endpoint = $data['endpoint']; |
| 335 | - $controllerNamespace = Utils::getNamespace($data['controller'] . '/' . $data['namespace'] . '/' . $data['class']); |
|
| 335 | + $controllerNamespace = Utils::getNamespace($data['controller'].'/'.$data['namespace'].'/'.$data['class']); |
|
| 336 | 336 | |
| 337 | 337 | $methodDocument = app()['reflection']($controllerNamespace)->reflectionMethodParams($data['method'])->document; |
| 338 | 338 | |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $mappings[$key]['endpoint'] = $endpoint . '/' . implode("/", $routePattern[$key]);
|
|
| 347 | + $mappings[$key]['endpoint'] = $endpoint.'/'.implode("/", $routePattern[$key]);
|
|
| 348 | 348 | $mappings[$key]['http'] = $data['http']; |
| 349 | 349 | $mappings[$key]['definition'] = $methodDefinition; |
| 350 | - $mappings[$key]['before'] = implode(",",$beforeMiddleware);
|
|
| 351 | - $mappings[$key]['after'] = implode(",",$afterMiddleware);
|
|
| 350 | + $mappings[$key]['before'] = implode(",", $beforeMiddleware);
|
|
| 351 | + $mappings[$key]['after'] = implode(",", $afterMiddleware);
|
|
| 352 | 352 | $mappings[$key]['doc'] = 'not available'; |
| 353 | 353 | |
| 354 | 354 | } |