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