Passed
Branchfeature/useWidgetsNamespaces (38e100)
by Robin
03:04
created
programs/Ctrl/AppController.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
 use Capwelton\LibApp\Exceptions\AppNotFoundException;
39 39
 use Capwelton\LibApp\Func_App;
40 40
 use Capwelton\LibApp\AppComponent;
41
-require_once $GLOBALS['babInstallPath'] . 'utilit/controller.class.php';
42
-require_once $GLOBALS['babInstallPath'] . 'utilit/json.php';
41
+require_once $GLOBALS['babInstallPath'].'utilit/controller.class.php';
42
+require_once $GLOBALS['babInstallPath'].'utilit/json.php';
43 43
 
44
-require_once dirname(__FILE__) . '/functions.php';
44
+require_once dirname(__FILE__).'/functions.php';
45 45
 
46 46
 /**
47 47
  * @method self proxy()
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function addReloadSelector($reloadSelector, $withSSE = false, $for = null)
74 74
     {
75 75
         $this->reloadSelectors[$reloadSelector] = $reloadSelector;
76
-        if($withSSE){
76
+        if ($withSSE) {
77 77
             $sseRecordSet = $this->getSSERecordSet();
78 78
             $sseRecordSet->newReloadSelector($reloadSelector, $for);
79 79
         }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function getSSERecordSet()
92 92
     {
93
-        if(isset($this->SSERecordSet)){
93
+        if (isset($this->SSERecordSet)) {
94 94
             return $this->SSERecordSet;
95 95
         }
96 96
         
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     public function __call($name, $arguments = array())
130 130
     {
131 131
         $component = $this->App()->getComponentByName($name);
132
-        if($component){
132
+        if ($component) {
133 133
             return call_user_func_array(array(
134 134
                 $component,
135 135
                 'controller'
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function isAjaxRequest()
174 174
     {
175
-        if(! isset($this->isAjaxRequest)){
175
+        if (!isset($this->isAjaxRequest)) {
176 176
             $this->isAjaxRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
177 177
         }
178 178
         return $this->isAjaxRequest;
@@ -184,14 +184,14 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function requireCredential($message = null)
186 186
     {
187
-        if($this->isAjaxRequest()){
187
+        if ($this->isAjaxRequest()) {
188 188
             $authType = 'Basic';
189 189
         }
190
-        else{
190
+        else {
191 191
             $authType = '';
192 192
         }
193 193
         
194
-        if(! isset($message)){
194
+        if (!isset($message)) {
195 195
             $message = $this->App()->translate('You must be logged in to access this page.');
196 196
         }
197 197
         
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
         list ($prefix) = explode('_', __CLASS__);
216 216
         $functionalityName = ucwords($prefix);
217 217
         /* @var $App Func_App */
218
-        $App = @\bab_functionality::get('App/' . $functionalityName);
218
+        $App = @\bab_functionality::get('App/'.$functionalityName);
219 219
         
220
-        if(!$App){
221
-            throw new AppException('Faild to autodetect functionality App/' . $functionalityName . ', the getInstance method is deprecated, use $App->ControllerProxy() instead');
220
+        if (!$App) {
221
+            throw new AppException('Faild to autodetect functionality App/'.$functionalityName.', the getInstance method is deprecated, use $App->ControllerProxy() instead');
222 222
         }
223 223
         
224 224
         $controller = $App->ControllerProxy($classname, $proxy);
@@ -236,39 +236,39 @@  discard block
 block discarded – undo
236 236
     static function getProxyInstance(Func_App $App, $classname)
237 237
     {
238 238
         $class = new \ReflectionClass($classname);
239
-        $proxyClassname = $class->getShortName() . self::PROXY_CLASS_SUFFIX;
240
-        if(! class_exists($proxyClassname)){
241
-            $classStr = 'class ' . $proxyClassname . ' extends ' . $class->name . ' {' . "\n";
239
+        $proxyClassname = $class->getShortName().self::PROXY_CLASS_SUFFIX;
240
+        if (!class_exists($proxyClassname)) {
241
+            $classStr = 'class '.$proxyClassname.' extends '.$class->name.' {'."\n";
242 242
             $methods = $class->getMethods();
243 243
             
244 244
             $classStr .= '	public function __construct(Func_App $App) {
245 245
                 $this->setApp($App);
246 246
             }' . "\n";
247 247
             
248
-            foreach ($methods as $method){
249
-                if($method->name === '__construct' || ! $method->isPublic() || $method->isStatic() || $method->isFinal() || $method->name === 'setApp' || $method->name === 'App' || $method->name === 'setCrm' || $method->name === 'Crm'){
248
+            foreach ($methods as $method) {
249
+                if ($method->name === '__construct' || !$method->isPublic() || $method->isStatic() || $method->isFinal() || $method->name === 'setApp' || $method->name === 'App' || $method->name === 'setCrm' || $method->name === 'Crm') {
250 250
                     continue;
251 251
                 }
252 252
                 
253
-                $classStr .= '	public function ' . $method->name . '(';
253
+                $classStr .= '	public function '.$method->name.'(';
254 254
                 $parameters = $method->getParameters();
255 255
                 $parametersStr = array();
256
-                foreach ($parameters as $parameter){
256
+                foreach ($parameters as $parameter) {
257 257
                     
258
-                    if($parameter->isDefaultValueAvailable()){
259
-                        $parametersStr[] = '$' . $parameter->name . ' = ' . var_export($parameter->getDefaultValue(), true);
258
+                    if ($parameter->isDefaultValueAvailable()) {
259
+                        $parametersStr[] = '$'.$parameter->name.' = '.var_export($parameter->getDefaultValue(), true);
260 260
                     }
261
-                    else{
262
-                        $parametersStr[] = '$' . $parameter->name;
261
+                    else {
262
+                        $parametersStr[] = '$'.$parameter->name;
263 263
                     }
264 264
                 }
265 265
                 $classStr .= implode(', ', $parametersStr);
266
-                $classStr .= ') {' . "\n";
267
-                $classStr .= '		$args = func_get_args();' . "\n";
268
-                $classStr .= '		return $this->getMethodAction(__FUNCTION__, $args);' . "\n";
269
-                $classStr .= '	}' . "\n";
266
+                $classStr .= ') {'."\n";
267
+                $classStr .= '		$args = func_get_args();'."\n";
268
+                $classStr .= '		return $this->getMethodAction(__FUNCTION__, $args);'."\n";
269
+                $classStr .= '	}'."\n";
270 270
             }
271
-            $classStr .= '}' . "\n";
271
+            $classStr .= '}'."\n";
272 272
             
273 273
             // We define the proxy class
274 274
             eval($classStr);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     protected function getObjectName($classname)
308 308
     {
309 309
         list ($objectname) = explode('Controller', $classname);
310
-        if($this->App()->getComponentByName($objectname)){
310
+        if ($this->App()->getComponentByName($objectname)) {
311 311
             return strtolower($objectname);
312 312
         }
313 313
         list (, $objectname) = explode('_Ctrl', $classname);
@@ -329,18 +329,18 @@  discard block
 block discarded – undo
329 329
         
330 330
         $reflector = new \ReflectionClass(get_class($this));
331 331
         $parent = $reflector->getParentClass();
332
-        if($parent){
332
+        if ($parent) {
333 333
             $parentMethod = $parent->getMethod('__construct');
334 334
             $docComment = $parentMethod->getDocComment();
335
-            if(strpos($docComment, '@isComponentController') !== false){
335
+            if (strpos($docComment, '@isComponentController') !== false) {
336 336
                 $fullClassName = $parent->getName();
337 337
             }
338 338
         }
339 339
         
340 340
         $rc = new \ReflectionClass($fullClassName);
341 341
         
342
-        if(! $rc->hasMethod($methodName)){
343
-            throw new \bab_InvalidActionException($fullClassName . '::' . $methodName);
342
+        if (!$rc->hasMethod($methodName)) {
343
+            throw new \bab_InvalidActionException($fullClassName.'::'.$methodName);
344 344
         }
345 345
         $method = new \ReflectionMethod($fullClassName, $methodName);
346 346
         
@@ -349,32 +349,32 @@  discard block
 block discarded – undo
349 349
         $parameters = $method->getParameters();
350 350
         $actionParams = array();
351 351
         $argNumber = 0;
352
-        foreach ($parameters as $parameter){
352
+        foreach ($parameters as $parameter) {
353 353
             $parameterName = $parameter->getName();
354
-            if(isset($args[$argNumber])){
354
+            if (isset($args[$argNumber])) {
355 355
                 $actionParams[$parameterName] = $args[$argNumber];
356 356
             }
357
-            elseif($parameter->isDefaultValueAvailable()){
357
+            elseif ($parameter->isDefaultValueAvailable()) {
358 358
                 $actionParams[$parameterName] = $parameter->getDefaultValue();
359 359
             }
360
-            else{
360
+            else {
361 361
                 $actionParams[$parameterName] = null;
362 362
             }
363
-            $argNumber ++;
363
+            $argNumber++;
364 364
         }
365 365
         
366 366
         $action = new WidgetAction();
367 367
         
368
-        $action->setMethod($this->getControllerTg(), $objectName . '.' . $methodName, $actionParams);
368
+        $action->setMethod($this->getControllerTg(), $objectName.'.'.$methodName, $actionParams);
369 369
         
370 370
         $docComment = $method->getDocComment();
371
-        if(strpos($docComment, '@ajax') !== false){
371
+        if (strpos($docComment, '@ajax') !== false) {
372 372
             $action->setAjax(true);
373 373
         }
374
-        if(strpos($docComment, '@requireSaveMethod') !== false && method_exists($action, 'setRequireSaveMethod')){
374
+        if (strpos($docComment, '@requireSaveMethod') !== false && method_exists($action, 'setRequireSaveMethod')) {
375 375
             $action->setRequireSaveMethod(true);
376 376
         }
377
-        if(strpos($docComment, '@requireDeleteMethod') !== false && method_exists($action, 'setRequireDeleteMethod')){
377
+        if (strpos($docComment, '@requireDeleteMethod') !== false && method_exists($action, 'setRequireDeleteMethod')) {
378 378
             $action->setRequireDeleteMethod(true);
379 379
         }
380 380
         
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
         
404 404
         $action->setParameters($actionParams);
405 405
         
406
-        list (, , $file) = explode('/', $App->controllerTg);
406
+        list (,, $file) = explode('/', $App->controllerTg);
407 407
         
408
-        $action->setParameter('addon', $App->getAddonName() . '.' . $file);
408
+        $action->setParameter('addon', $App->getAddonName().'.'.$file);
409 409
         $action->setParameter('idx', $idx);
410 410
         
411 411
         return $action;
@@ -423,44 +423,44 @@  discard block
 block discarded – undo
423 423
         
424 424
         $method = $action->getMethod();
425 425
         
426
-        if(! isset($method) || '' === $method){
426
+        if (!isset($method) || '' === $method) {
427 427
             return false;
428 428
         }
429 429
         
430 430
         list ($objectName,) = explode('.', $method);
431 431
         
432
-        if(! method_exists($this, $objectName)){
432
+        if (!method_exists($this, $objectName)) {
433 433
             /* @var $component AppComponent */
434 434
             $component = $this->app->getComponentByName($objectName);
435
-            if($component){
435
+            if ($component) {
436 436
                 $this->app->setCurrentComponent($component);
437 437
                 $objectController = $component->controller(false);
438 438
             }
439
-            else{
439
+            else {
440 440
                 header('HTTP/1.0 400 Bad Request');
441 441
                 throw new AppUnknownActionException($action);
442 442
             }
443 443
         }
444 444
         
445
-        if(! isset($component)){
445
+        if (!isset($component)) {
446 446
             $objectController = $this->{$objectName}(false);
447
-            if(! ($objectController instanceof AppController)){
447
+            if (!($objectController instanceof AppController)) {
448 448
                 return false;
449 449
             }
450 450
         }
451 451
         
452
-        try{
452
+        try {
453 453
             $returnedValue = $objectController->execAction($action);
454 454
         }
455
-        catch (AppAccessException $e){
455
+        catch (AppAccessException $e) {
456 456
             
457
-            if(! bab_isUserLogged() && $e->requireCredential){
457
+            if (!bab_isUserLogged() && $e->requireCredential) {
458 458
                 bab_requireCredential($e->getMessage());
459 459
             }
460
-            else{
461
-                if($this->isAjaxRequest()){
460
+            else {
461
+                if ($this->isAjaxRequest()) {
462 462
                     
463
-                    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden', true, 403);
463
+                    header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden', true, 403);
464 464
                     
465 465
                     die(bab_json_encode(array(
466 466
                         'exception' => 'app_AccessException',
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
                 $this->accessPage($e);
472 472
             }
473 473
         }
474
-        catch (AppSaveException $e){
474
+        catch (AppSaveException $e) {
475 475
             
476
-            if($this->isAjaxRequest()){
477
-                header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden', true, 403);
476
+            if ($this->isAjaxRequest()) {
477
+                header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden', true, 403);
478 478
                 header('Cache-Control: no-cache, must-revalidate');
479 479
                 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
480 480
                 header('Content-type: application/json');
@@ -486,32 +486,32 @@  discard block
 block discarded – undo
486 486
                 )));
487 487
             }
488 488
         }
489
-        catch (AppDeletedRecordException $e){
489
+        catch (AppDeletedRecordException $e) {
490 490
             $this->deletedItemPage($action, $e);
491 491
         }
492
-        catch (AppNotFoundException $e){
492
+        catch (AppNotFoundException $e) {
493 493
             $this->notFoundPage($action, $e);
494 494
         }
495
-        catch (\ORM_Exception $e){
495
+        catch (\ORM_Exception $e) {
496 496
             $this->errorPage($e);
497 497
         }
498
-        catch (\Exception $e){
498
+        catch (\Exception $e) {
499 499
             $this->unexpectedErrorPage($e);
500 500
         }
501 501
         
502 502
         $W = bab_Widgets();
503 503
         
504
-        if($returnedValue instanceof WidgetDisplayableInterface){
504
+        if ($returnedValue instanceof WidgetDisplayableInterface) {
505 505
             
506
-            if($returnedValue instanceof WidgetBabPage && ! $this->isAjaxRequest()){
506
+            if ($returnedValue instanceof WidgetBabPage && !$this->isAjaxRequest()) {
507 507
                 
508 508
                 // If the action returned a page, we display it.
509 509
                 $returnedValue->displayHtml();
510 510
             }
511
-            else{
511
+            else {
512 512
                 
513 513
                 $htmlCanvas = $W->HtmlCanvas();
514
-                if(self::$acceptJson){
514
+                if (self::$acceptJson) {
515 515
                     $itemId = $returnedValue->getId();
516 516
                     $returnArray = array(
517 517
                         $itemId => $returnedValue->display($htmlCanvas)
@@ -521,18 +521,18 @@  discard block
 block discarded – undo
521 521
                     header('Content-type: application/json');
522 522
                     die(bab_json_encode($returnArray));
523 523
                 }
524
-                else{
524
+                else {
525 525
                     header('Cache-Control: no-cache, must-revalidate');
526 526
                     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
527 527
                     header('Content-type: text/html');
528
-                    if($returnedValue instanceof WidgetPage && method_exists($returnedValue, 'getPageTitle')){
528
+                    if ($returnedValue instanceof WidgetPage && method_exists($returnedValue, 'getPageTitle')) {
529 529
                         $pageTitle = $returnedValue->getPageTitle();
530 530
                         
531
-                        if(method_exists($htmlCanvas, 'sendPageTitle')){
531
+                        if (method_exists($htmlCanvas, 'sendPageTitle')) {
532 532
                             $htmlCanvas->sendPageTitle($pageTitle);
533 533
                         }
534
-                        else{
535
-                            header('X-Cto-PageTitle: ' . $pageTitle);
534
+                        else {
535
+                            header('X-Cto-PageTitle: '.$pageTitle);
536 536
                         }
537 537
                     }
538 538
                     $html = $returnedValue->display($htmlCanvas);
@@ -540,15 +540,15 @@  discard block
 block discarded – undo
540 540
                 }
541 541
             }
542 542
         }
543
-        elseif(is_array($returnedValue)){
543
+        elseif (is_array($returnedValue)) {
544 544
             
545 545
             $htmlCanvas = $W->HtmlCanvas();
546 546
             $returnedArray = array();
547
-            foreach ($returnedValue as $key => &$item){
548
-                if($item instanceof WidgetDisplayableInterface){
547
+            foreach ($returnedValue as $key => &$item) {
548
+                if ($item instanceof WidgetDisplayableInterface) {
549 549
                     $returnedArray[$item->getId()] = $item->display($htmlCanvas);
550 550
                 }
551
-                else{
551
+                else {
552 552
                     $returnedArray[$key] = $item;
553 553
                 }
554 554
             }
@@ -557,9 +557,9 @@  discard block
 block discarded – undo
557 557
             header('Content-type: application/json');
558 558
             die(bab_convertStringFromDatabase(bab_json_encode($returnedArray), \bab_charset::UTF_8));
559 559
         }
560
-        elseif(true === $returnedValue || is_string($returnedValue)){
560
+        elseif (true === $returnedValue || is_string($returnedValue)) {
561 561
             
562
-            if($this->isAjaxRequest()){
562
+            if ($this->isAjaxRequest()) {
563 563
                 $body = bab_getBody();
564 564
                 $json = array();
565 565
                 $json['messages'] = array();
@@ -567,21 +567,21 @@  discard block
 block discarded – undo
567 567
                 unset($body->messages['toasts']);
568 568
                 $messages = $body->messages;
569 569
                 $errors = $body->errors;
570
-                foreach ($messages as $message){
570
+                foreach ($messages as $message) {
571 571
                     $json['messages'][] = array(
572 572
                         'level' => 'info',
573 573
                         'content' => $message,
574 574
                         'time' => 4000
575 575
                     );
576 576
                 }
577
-                foreach ($errors as $message){
577
+                foreach ($errors as $message) {
578 578
                     $json['messages'][] = array(
579 579
                         'level' => 'danger',
580 580
                         'content' => $message
581 581
                     );
582 582
                 }
583 583
                 $json['toasts'] = $toasts;
584
-                if($objectController->getReloadSelectors()){
584
+                if ($objectController->getReloadSelectors()) {
585 585
                     $json['reloadSelector'] = implode(',', $objectController->getReloadSelectors());
586 586
                 }
587 587
                 echo bab_json_encode($json);
@@ -594,8 +594,8 @@  discard block
 block discarded – undo
594 594
     
595 595
     private function deletedItemPage(WidgetAction $action, AppDeletedRecordException $e)
596 596
     {
597
-        if($this->isAjaxRequest()){
598
-            header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden', true, 403);
597
+        if ($this->isAjaxRequest()) {
598
+            header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden', true, 403);
599 599
             header('Cache-Control: no-cache, must-revalidate');
600 600
             header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
601 601
             header('Content-type: application/json');
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
                 'errorMessage' => bab_convertStringFromDatabase($e->getMessage(), 'UTF-8')
608 608
             )));
609 609
         }
610
-        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
610
+        header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
611 611
         
612 612
         $App = app_App();
613 613
         $W = bab_Widgets();
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
             ->setAlignItems(WidgetFlexLayout::FLEX_ALIGN_ITEMS_CENTER));
630 630
         $section->addItems($W->Title($App->translate('Error'), 1), $W->Title(sprintf($App->translate('This %s has been deleted'), $e->getObjectTitle())));
631 631
         
632
-        if($e instanceof AppDeletedRecordException){
632
+        if ($e instanceof AppDeletedRecordException) {
633 633
             $section->addItems($e->getDeletedBy(), $e->getDeletedOn());
634 634
         }
635 635
         
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
     
639 639
     private function notFoundPage(WidgetAction $action, AppNotFoundException $e)
640 640
     {
641
-        if($this->isAjaxRequest()){
642
-            $message = sprintf(app_translate('This %s does not exists'), $e->getObjectTitle() . ' (' . $e->getId() . ')');
641
+        if ($this->isAjaxRequest()) {
642
+            $message = sprintf(app_translate('This %s does not exists'), $e->getObjectTitle().' ('.$e->getId().')');
643 643
             $json = array(
644 644
                 'messages' => array(
645 645
                     array(
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
             echo bab_json_encode($json);
652 652
             die();
653 653
         }
654
-        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
654
+        header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
655 655
         header('Cache-Control: no-cache, must-revalidate');
656 656
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
657 657
         
@@ -680,8 +680,8 @@  discard block
 block discarded – undo
680 680
     
681 681
     private function unexpectedErrorPage(\Exception $e)
682 682
     {
683
-        if($this->isAjaxRequest()){
684
-            $message = sprintf(app_translate('An unexpected error occured') . ':' . '%s', $e->getMessage());
683
+        if ($this->isAjaxRequest()) {
684
+            $message = sprintf(app_translate('An unexpected error occured').':'.'%s', $e->getMessage());
685 685
             $json = array(
686 686
                 'messages' => array(
687 687
                     array(
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
             echo bab_json_encode($json);
694 694
             die();
695 695
         }
696
-        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal server error', true, 500);
696
+        header($_SERVER['SERVER_PROTOCOL'].' 500 Internal server error', true, 500);
697 697
         header('Cache-Control: no-cache, must-revalidate');
698 698
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
699 699
         
@@ -717,25 +717,25 @@  discard block
 block discarded – undo
717 717
             ->addClass('widget-50pc alert alert-danger')
718 718
             ->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL));
719 719
         
720
-        $logCode = '#' . hrtime(true);
720
+        $logCode = '#'.hrtime(true);
721 721
         $message = addcslashes($e->getMessage(), "\000..\037\177..\377\\");
722 722
         $trace = addcslashes($e->getTraceAsString(), "\000..\037\177..\377\\");
723 723
         
724
-        error_log(sprintf('Error %s : %s', $logCode, $message) . PHP_EOL . $trace);
724
+        error_log(sprintf('Error %s : %s', $logCode, $message).PHP_EOL.$trace);
725 725
         
726 726
         $section->addItems($W->Title($App->translate('Error'), 1), $W->Title($App->translate('An unexpected error occured')), $W->Label(sprintf($App->translate('It has been logged with the following error code : %s'), $logCode)));
727 727
         
728
-        if(bab_isUserAdministrator()){
728
+        if (bab_isUserAdministrator()) {
729 729
             $contentBox->addItem($W->Section('Stack trace', $stackTraceBox = $W->FlexItems($W->Label($message)
730 730
                 ->addClass('widget-description'))
731 731
                 ->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL))
732 732
                 ->setFoldable(true, true));
733 733
             $traces = explode("\n", $e->getTraceAsString());
734
-            foreach ($traces as $trace){
734
+            foreach ($traces as $trace) {
735 735
                 $stackTraceBox->addItem($W->Label($trace));
736 736
             }
737 737
         }
738
-        else{
738
+        else {
739 739
             $section->addItem($W->Label($App->translate('Please contact the administrator')));
740 740
         }
741 741
         
@@ -744,8 +744,8 @@  discard block
 block discarded – undo
744 744
     
745 745
     private function errorPage(\Exception $e)
746 746
     {
747
-        if($this->isAjaxRequest()){
748
-            $message = sprintf(app_translate('An unexpected error occured') . ':' . '%s', $e->getMessage());
747
+        if ($this->isAjaxRequest()) {
748
+            $message = sprintf(app_translate('An unexpected error occured').':'.'%s', $e->getMessage());
749 749
             $json = array(
750 750
                 'messages' => array(
751 751
                     array(
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
             echo bab_json_encode($json);
758 758
             die();
759 759
         }
760
-        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal server error', true, 500);
760
+        header($_SERVER['SERVER_PROTOCOL'].' 500 Internal server error', true, 500);
761 761
         header('Cache-Control: no-cache, must-revalidate');
762 762
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
763 763
         
@@ -781,25 +781,25 @@  discard block
 block discarded – undo
781 781
             ->addClass('widget-50pc alert alert-danger')
782 782
             ->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL));
783 783
         
784
-        $logCode = '#' . hrtime(true);
784
+        $logCode = '#'.hrtime(true);
785 785
         $message = addcslashes($e->getMessage(), "\000..\037\177..\377\\");
786 786
         $trace = addcslashes($e->getTraceAsString(), "\000..\037\177..\377\\");
787 787
         
788
-        error_log(sprintf('Error %s : %s', $logCode, $message) . PHP_EOL . $trace);
788
+        error_log(sprintf('Error %s : %s', $logCode, $message).PHP_EOL.$trace);
789 789
         
790 790
         $section->addItems($W->Title($App->translate('Error'), 1), $W->Title($App->translate('An unexpected error occured')), $W->Label(sprintf($App->translate('It has been logged with the following error code : %s'), $logCode)));
791 791
         
792
-        if(bab_isUserAdministrator()){
792
+        if (bab_isUserAdministrator()) {
793 793
             $contentBox->addItem($W->Section('Stack trace', $stackTraceBox = $W->FlexItems($W->Label($message)
794 794
                 ->addClass('widget-description'))
795 795
                 ->setDirection(WidgetFlexLayout::FLEX_DIRECTION_COL))
796 796
                 ->setFoldable(true, true));
797 797
             $traces = explode("\n", $e->getTraceAsString());
798
-            foreach ($traces as $trace){
798
+            foreach ($traces as $trace) {
799 799
                 $stackTraceBox->addItem($W->Label($trace));
800 800
             }
801 801
         }
802
-        else{
802
+        else {
803 803
             $section->addItem($W->Label($App->translate('Please contact the administrator')));
804 804
         }
805 805
         
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
     
809 809
     private function accessPage(\Exception $e)
810 810
     {
811
-        if($this->isAjaxRequest()){
811
+        if ($this->isAjaxRequest()) {
812 812
             $message = $e->getMessage();
813 813
             $json = array(
814 814
                 'messages' => array(
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
             echo bab_json_encode($json);
822 822
             die();
823 823
         }
824
-        header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden', true, 403);
824
+        header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden', true, 403);
825 825
         header('Cache-Control: no-cache, must-revalidate');
826 826
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
827 827
         
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
      */
859 859
     public function requireSaveMethod()
860 860
     {
861
-        if('GET' === $_SERVER['REQUEST_METHOD']){
861
+        if ('GET' === $_SERVER['REQUEST_METHOD']) {
862 862
             throw new AppException('Method not allowed');
863 863
         }
864 864
         
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
      */
874 874
     public function requireDeleteMethod()
875 875
     {
876
-        if('GET' === $_SERVER['REQUEST_METHOD']){
876
+        if ('GET' === $_SERVER['REQUEST_METHOD']) {
877 877
             throw new AppException('Method not allowed');
878 878
         }
879 879
         
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
             'position' => $position
906 906
         );
907 907
         $babBody = bab_getBody();
908
-        if(! isset($babBody->messages['toasts'])){
908
+        if (!isset($babBody->messages['toasts'])) {
909 909
             $babBody->messages['toasts'] = array();
910 910
         }
911 911
         $babBody->messages['toasts'][] = $toast;
Please login to merge, or discard this patch.