Completed
Push — master ( 909472...a7ca1a )
by Thierry
01:50
created
src/Plugin/Manager.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -262,32 +262,32 @@  discard block
 block discarded – undo
262 262
     {
263 263
         $bIsAlert = ($xPlugin instanceof \Jaxon\Request\Interfaces\Alert);
264 264
         $bIsConfirm = ($xPlugin instanceof \Jaxon\Request\Interfaces\Confirm);
265
-        if($xPlugin instanceof Request)
265
+        if ($xPlugin instanceof Request)
266 266
         {
267 267
             // The name of a request plugin is used as key in the plugin table
268 268
             $this->aRequestPlugins[$xPlugin->getName()] = $xPlugin;
269 269
         }
270
-        elseif($xPlugin instanceof Response)
270
+        elseif ($xPlugin instanceof Response)
271 271
         {
272 272
             // The name of a response plugin is used as key in the plugin table
273 273
             $this->aResponsePlugins[$xPlugin->getName()] = $xPlugin;
274 274
         }
275
-        elseif(!$bIsConfirm && !$bIsAlert)
275
+        elseif (!$bIsConfirm && !$bIsAlert)
276 276
         {
277 277
             throw new \Jaxon\Exception\Error($this->trans('errors.register.invalid', array('name' => get_class($xPlugin))));
278 278
         }
279 279
         // This plugin implements the Alert interface
280
-        if($bIsAlert)
280
+        if ($bIsAlert)
281 281
         {
282 282
             $this->setAlert($xPlugin);
283 283
         }
284 284
         // This plugin implements the Confirm interface
285
-        if($bIsConfirm)
285
+        if ($bIsConfirm)
286 286
         {
287 287
             $this->setConfirm($xPlugin);
288 288
         }
289 289
         // Register the plugin as an event listener
290
-        if($xPlugin instanceof \Jaxon\Utils\Interfaces\EventListener)
290
+        if ($xPlugin instanceof \Jaxon\Utils\Interfaces\EventListener)
291 291
         {
292 292
             $this->addEventListener($xPlugin);
293 293
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     private function generateHash()
304 304
     {
305 305
         $sHash = $this->getVersion();
306
-        foreach($this->aPlugins as $xPlugin)
306
+        foreach ($this->aPlugins as $xPlugin)
307 307
         {
308 308
             $sHash .= $xPlugin->generateHash();
309 309
         }
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
      */
321 321
     public function canProcessRequest()
322 322
     {
323
-        foreach($this->aRequestPlugins as $xPlugin)
323
+        foreach ($this->aRequestPlugins as $xPlugin)
324 324
         {
325
-            if($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest())
325
+            if ($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest())
326 326
             {
327 327
                 return true;
328 328
             }
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
     public function processRequest()
342 342
     {
343 343
         $xUploadPlugin = $this->getRequestPlugin(Jaxon::FILE_UPLOAD);
344
-        foreach($this->aRequestPlugins as $xPlugin)
344
+        foreach ($this->aRequestPlugins as $xPlugin)
345 345
         {
346
-            if($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest())
346
+            if ($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest())
347 347
             {
348 348
                 // Process uploaded files
349
-                if($xUploadPlugin != null)
349
+                if ($xUploadPlugin != null)
350 350
                 {
351 351
                     $xUploadPlugin->processRequest();
352 352
                 }
@@ -370,10 +370,10 @@  discard block
 block discarded – undo
370 370
      */
371 371
     public function register($aArgs)
372 372
     {
373
-        foreach($this->aRequestPlugins as $xPlugin)
373
+        foreach ($this->aRequestPlugins as $xPlugin)
374 374
         {
375 375
             $mResult = $xPlugin->register($aArgs);
376
-            if($mResult instanceof \Jaxon\Request\Request || is_array($mResult) || $mResult === true)
376
+            if ($mResult instanceof \Jaxon\Request\Request || is_array($mResult) || $mResult === true)
377 377
             {
378 378
                 return $mResult;
379 379
             }
@@ -393,37 +393,37 @@  discard block
 block discarded – undo
393 393
      */
394 394
     public function addClassDir($sDirectory, $sNamespace = '', $sSeparator = '.', array $aProtected = array())
395 395
     {
396
-        if(!is_dir(($sDirectory = trim($sDirectory))))
396
+        if (!is_dir(($sDirectory = trim($sDirectory))))
397 397
         {
398 398
             return false;
399 399
         }
400 400
         // Only '.' and '_' are allowed to be used as separator. Any other value is ignored and '.' is used instead.
401
-        if(($sSeparator = trim($sSeparator)) != '_')
401
+        if (($sSeparator = trim($sSeparator)) != '_')
402 402
         {
403 403
             $sSeparator = '.';
404 404
         }
405
-        if(!($sNamespace = trim($sNamespace, ' \\')))
405
+        if (!($sNamespace = trim($sNamespace, ' \\')))
406 406
         {
407 407
             $sNamespace = '';
408 408
         }
409
-        if(($sNamespace))
409
+        if (($sNamespace))
410 410
         {
411 411
             // If there is an autoloader, register the dir with PSR4 autoloading
412
-            if(($this->xAutoloader))
412
+            if (($this->xAutoloader))
413 413
             {
414 414
                 $this->xAutoloader->setPsr4($sNamespace . '\\', $sDirectory);
415 415
             }
416 416
         }
417
-        elseif(($this->xAutoloader))
417
+        elseif (($this->xAutoloader))
418 418
         {
419 419
             // If there is an autoloader, register the dir with classmap autoloading
420 420
             $itDir = new RecursiveDirectoryIterator($sDirectory);
421 421
             $itFile = new RecursiveIteratorIterator($itDir);
422 422
             // Iterate on dir content
423
-            foreach($itFile as $xFile)
423
+            foreach ($itFile as $xFile)
424 424
             {
425 425
                 // skip everything except PHP files
426
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
426
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
427 427
                 {
428 428
                     continue;
429 429
                 }
@@ -459,33 +459,33 @@  discard block
 block discarded – undo
459 459
         $sClassPath = substr($xFile->getPath(), strlen($sDirectory));
460 460
         $sClassPath = str_replace($sDS, '\\', trim($sClassPath, $sDS));
461 461
         $sClassName = $xFile->getBasename('.php');
462
-        if(($sNamespace))
462
+        if (($sNamespace))
463 463
         {
464 464
             $sClassPath = ($sClassPath) ? $sNamespace . '\\' . $sClassPath : $sNamespace;
465 465
             $sClassName = '\\' . $sClassPath . '\\' . $sClassName;
466 466
         }
467 467
         // Require the file only if autoload is enabled but there is no autoloader
468
-        if(($this->bAutoloadEnabled) && !($this->xAutoloader))
468
+        if (($this->bAutoloadEnabled) && !($this->xAutoloader))
469 469
         {
470 470
             require_once($xFile->getPathname());
471 471
         }
472 472
         // Create and register an instance of the class
473
-        if(!array_key_exists('*', $aOptions) || !is_array($aOptions['*']))
473
+        if (!array_key_exists('*', $aOptions) || !is_array($aOptions['*']))
474 474
         {
475 475
             $aOptions['*'] = array();
476 476
         }
477 477
         $aOptions['*']['separator'] = $sSeparator;
478
-        if(($sNamespace))
478
+        if (($sNamespace))
479 479
         {
480 480
             $aOptions['*']['namespace'] = $sNamespace;
481 481
         }
482
-        if(($sClassPath))
482
+        if (($sClassPath))
483 483
         {
484 484
             $aOptions['*']['classpath'] = $sClassPath;
485 485
         }
486 486
         // Filter excluded methods
487
-        $aProtected = array_filter($aProtected, function ($sName) {return is_string($sName);});
488
-        if(count($aProtected) > 0)
487
+        $aProtected = array_filter($aProtected, function($sName) {return is_string($sName); });
488
+        if (count($aProtected) > 0)
489 489
         {
490 490
             $aOptions['*']['protected'] = $aProtected;
491 491
         }
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
         $sDS = DIRECTORY_SEPARATOR;
505 505
         // Change the keys in $aOptions to have "\" as separator
506 506
         $aNewOptions = array();
507
-        foreach($aOptions as $key => $aOption)
507
+        foreach ($aOptions as $key => $aOption)
508 508
         {
509 509
             $key = trim(str_replace(['.', '_'], ['\\', '\\'], $key), ' \\');
510 510
             $aNewOptions[$key] = $aOption;
511 511
         }
512 512
 
513
-        foreach($this->aClassDirs as $aClassDir)
513
+        foreach ($this->aClassDirs as $aClassDir)
514 514
         {
515 515
             // Get the directory
516 516
             $sDirectory = $aClassDir['directory'];
@@ -520,10 +520,10 @@  discard block
 block discarded – undo
520 520
             $itDir = new RecursiveDirectoryIterator($sDirectory);
521 521
             $itFile = new RecursiveIteratorIterator($itDir);
522 522
             // Iterate on dir content
523
-            foreach($itFile as $xFile)
523
+            foreach ($itFile as $xFile)
524 524
             {
525 525
                 // skip everything except PHP files
526
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
526
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
527 527
                 {
528 528
                     continue;
529 529
                 }
@@ -532,13 +532,13 @@  discard block
 block discarded – undo
532 532
                 $sClassPath = substr($xFile->getPath(), strlen($sDirectory));
533 533
                 $sClassPath = trim(str_replace($sDS, '\\', $sClassPath), '\\');
534 534
                 $sClassName = $sClassPath . '\\' . $xFile->getBasename('.php');
535
-                if(($sNamespace))
535
+                if (($sNamespace))
536 536
                 {
537 537
                     $sClassName = $sNamespace . '\\' . $sClassName;
538 538
                 }
539 539
                 // Get the class options
540 540
                 $aClassOptions = [];
541
-                if(array_key_exists($sClassName, $aNewOptions))
541
+                if (array_key_exists($sClassName, $aNewOptions))
542 542
                 {
543 543
                     $aClassOptions = $aNewOptions[$sClassName];
544 544
                 }
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      */
560 560
     public function registerClass($sClassName, array $aOptions = array())
561 561
     {
562
-        if(!($sClassName = trim($sClassName, ' \\._')))
562
+        if (!($sClassName = trim($sClassName, ' \\._')))
563 563
         {
564 564
             return false;
565 565
         }
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         // Replace "." and "_" with antislashes, and set the class path.
569 569
         $sClassName = str_replace(['.', '_'], ['\\', '\\'], $sClassName);
570 570
         $sClassPath = '';
571
-        if(($nLastSlashPosition = strrpos($sClassName, '\\')) !== false)
571
+        if (($nLastSlashPosition = strrpos($sClassName, '\\')) !== false)
572 572
         {
573 573
             $sClassPath = substr($sClassName, 0, $nLastSlashPosition);
574 574
             $sClassName = substr($sClassName, $nLastSlashPosition + 1);
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
         $sPartPath = str_replace('\\', $sDS, $sClassPath) . $sDS . $sClassName . '.php';
578 578
 
579 579
         // Search for the class file in all directories.
580
-        foreach($this->aClassDirs as $aClassDir)
580
+        foreach ($this->aClassDirs as $aClassDir)
581 581
         {
582 582
             // Get the separator
583 583
             $sSeparator = $aClassDir['separator'];
@@ -586,15 +586,15 @@  discard block
 block discarded – undo
586 586
             $nLen = strlen($sNamespace);
587 587
             $sFullPath = '';
588 588
             // Check if the class belongs to the namespace
589
-            if(($sNamespace) && substr($sClassPath, 0, $nLen) == $sNamespace)
589
+            if (($sNamespace) && substr($sClassPath, 0, $nLen) == $sNamespace)
590 590
             {
591 591
                 $sFullPath = $aClassDir['directory'] . $sDS . substr($sPartPath, $nLen + 1);
592 592
             }
593
-            elseif(!($sNamespace))
593
+            elseif (!($sNamespace))
594 594
             {
595 595
                 $sFullPath = $aClassDir['directory'] . $sDS . $sPartPath;
596 596
             }
597
-            if(($sFullPath) && is_file($sFullPath))
597
+            if (($sFullPath) && is_file($sFullPath))
598 598
             {
599 599
                 // Found the file in this directory
600 600
                 $xFileInfo = new \SplFileInfo($sFullPath);
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
     {
619 619
         $xObject = null; // The user registered object
620 620
         $xPlugin = $this->getRequestPlugin('CallableObject'); // The CallableObject plugin
621
-        if(($xPlugin))
621
+        if (($xPlugin))
622 622
         {
623 623
             $xObject = $xPlugin->getRegisteredObject($sClassName);
624 624
         }
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
      */
633 633
     private function getJsLibUri()
634 634
     {
635
-        if(!$this->hasOption('js.lib.uri'))
635
+        if (!$this->hasOption('js.lib.uri'))
636 636
         {
637 637
             // return 'https://cdn.jsdelivr.net/jaxon/1.2.0/';
638 638
             return 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist/';
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
         // The jsDelivr CDN only hosts minified files
656 656
         // if(($this->getOption('js.app.minify')) || substr($this->getJsLibUri(), 0, $nLen) == $jsDelivrUri)
657 657
         // Starting from version 2.0.0 of the js lib, the jsDelivr CDN also hosts non minified files.
658
-        if(($this->getOption('js.app.minify')))
658
+        if (($this->getOption('js.app.minify')))
659 659
         {
660 660
             return '.min.js';
661 661
         }
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
         // Check config options
673 673
         // - The js.app.extern option must be set to true
674 674
         // - The js.app.uri and js.app.dir options must be set to non null values
675
-        if(!$this->getOption('js.app.extern') ||
675
+        if (!$this->getOption('js.app.extern') ||
676 676
             !$this->getOption('js.app.uri') ||
677 677
             !$this->getOption('js.app.dir'))
678 678
         {
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         // Check dir access
682 682
         // - The js.app.dir must be writable
683 683
         $sJsAppDir = $this->getOption('js.app.dir');
684
-        if(!is_dir($sJsAppDir) || !is_writable($sJsAppDir))
684
+        if (!is_dir($sJsAppDir) || !is_writable($sJsAppDir))
685 685
         {
686 686
             return false;
687 687
         }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     private function setTemplateCacheDir()
697 697
     {
698
-        if($this->hasOption('core.template.cache_dir'))
698
+        if ($this->hasOption('core.template.cache_dir'))
699 699
         {
700 700
             $this->setCacheDir($this->getOption('core.template.cache_dir'));
701 701
         }
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 
718 718
         // Add component files to the javascript file array;
719 719
         $aJsFiles = array($sJsCoreUrl);
720
-        if($this->getOption('core.debug.on'))
720
+        if ($this->getOption('core.debug.on'))
721 721
         {
722 722
             $aJsFiles[] = $sJsDebugUrl;
723 723
             $aJsFiles[] = $sJsLanguageUrl;
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
             'sJsOptions' => $this->getOption('js.app.options'),
734 734
             'aUrls' => $aJsFiles,
735 735
         ));
736
-        foreach($this->aResponsePlugins as $xPlugin)
736
+        foreach ($this->aResponsePlugins as $xPlugin)
737 737
         {
738 738
             $sCode .= rtrim($xPlugin->getJs(), " \n") . "\n";
739 739
         }
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
         $this->setTemplateCacheDir();
752 752
 
753 753
         $sCode = '';
754
-        foreach($this->aResponsePlugins as $xPlugin)
754
+        foreach ($this->aResponsePlugins as $xPlugin)
755 755
         {
756 756
             $sCode .= rtrim($xPlugin->getCss(), " \n") . "\n";
757 757
         }
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
         ));*/
840 840
 
841 841
         $sPluginScript = '';
842
-        foreach($this->aResponsePlugins as $xPlugin)
842
+        foreach ($this->aResponsePlugins as $xPlugin)
843 843
         {
844 844
             $sPluginScript .= "\n" . trim($xPlugin->getScript(), " \n");
845 845
         }
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
     {
870 870
         // Get the config and plugins scripts
871 871
         $sScript = $this->getConfigScript() . "\n" . $this->getReadyScript() . "\n";
872
-        foreach($this->aRequestPlugins as $xPlugin)
872
+        foreach ($this->aRequestPlugins as $xPlugin)
873 873
         {
874 874
             $sScript .= "\n" . trim($xPlugin->getScript(), " \n");
875 875
         }
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
         // Set the template engine cache dir
892 892
         $this->setTemplateCacheDir();
893 893
 
894
-        if($this->canExportJavascript())
894
+        if ($this->canExportJavascript())
895 895
         {
896 896
             $sJsAppURI = rtrim($this->getOption('js.app.uri'), '/') . '/';
897 897
             $sJsAppDir = rtrim($this->getOption('js.app.dir'), '/') . '/';
@@ -900,13 +900,13 @@  discard block
 block discarded – undo
900 900
             $sHash = $this->generateHash();
901 901
             $sOutFile = $sHash . '.js';
902 902
             $sMinFile = $sHash . '.min.js';
903
-            if(!is_file($sJsAppDir . $sOutFile))
903
+            if (!is_file($sJsAppDir . $sOutFile))
904 904
             {
905 905
                 file_put_contents($sJsAppDir . $sOutFile, $this->getAllScripts());
906 906
             }
907
-            if(($this->getOption('js.app.minify')) && !is_file($sJsAppDir . $sMinFile))
907
+            if (($this->getOption('js.app.minify')) && !is_file($sJsAppDir . $sMinFile))
908 908
             {
909
-                if(($this->minify($sJsAppDir . $sOutFile, $sJsAppDir . $sMinFile)))
909
+                if (($this->minify($sJsAppDir . $sOutFile, $sJsAppDir . $sMinFile)))
910 910
                 {
911 911
                     $sOutFile = $sMinFile;
912 912
                 }
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
      */
940 940
     public function getResponsePlugin($sName)
941 941
     {
942
-        if(array_key_exists($sName, $this->aResponsePlugins))
942
+        if (array_key_exists($sName, $this->aResponsePlugins))
943 943
         {
944 944
             return $this->aResponsePlugins[$sName];
945 945
         }
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
      */
956 956
     public function getRequestPlugin($sName)
957 957
     {
958
-        if(array_key_exists($sName, $this->aRequestPlugins))
958
+        if (array_key_exists($sName, $this->aRequestPlugins))
959 959
         {
960 960
             return $this->aRequestPlugins[$sName];
961 961
         }
Please login to merge, or discard this patch.