Completed
Push — master ( 7c1799...0d79ac )
by Thierry
01:43
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->canProcessRequest())
325
+            if ($xPlugin->canProcessRequest())
326 326
             {
327 327
                 return true;
328 328
             }
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public function processRequest()
342 342
     {
343
-        foreach($this->aRequestPlugins as $xPlugin)
343
+        foreach ($this->aRequestPlugins as $xPlugin)
344 344
         {
345
-            if($xPlugin->canProcessRequest())
345
+            if ($xPlugin->canProcessRequest())
346 346
             {
347 347
                 return $xPlugin->processRequest();
348 348
             }
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
      */
364 364
     public function register($aArgs)
365 365
     {
366
-        foreach($this->aRequestPlugins as $xPlugin)
366
+        foreach ($this->aRequestPlugins as $xPlugin)
367 367
         {
368 368
             $mResult = $xPlugin->register($aArgs);
369
-            if($mResult instanceof \Jaxon\Request\Request || is_array($mResult) || $mResult === true)
369
+            if ($mResult instanceof \Jaxon\Request\Request || is_array($mResult) || $mResult === true)
370 370
             {
371 371
                 return $mResult;
372 372
             }
@@ -386,37 +386,37 @@  discard block
 block discarded – undo
386 386
      */
387 387
     public function addClassDir($sDirectory, $sNamespace = '', $sSeparator = '.', array $aProtected = array())
388 388
     {
389
-        if(!is_dir(($sDirectory = trim($sDirectory))))
389
+        if (!is_dir(($sDirectory = trim($sDirectory))))
390 390
         {
391 391
             return false;
392 392
         }
393 393
         // Only '.' and '_' are allowed to be used as separator. Any other value is ignored and '.' is used instead.
394
-        if(($sSeparator = trim($sSeparator)) != '_')
394
+        if (($sSeparator = trim($sSeparator)) != '_')
395 395
         {
396 396
             $sSeparator = '.';
397 397
         }
398
-        if(!($sNamespace = trim($sNamespace, ' \\')))
398
+        if (!($sNamespace = trim($sNamespace, ' \\')))
399 399
         {
400 400
             $sNamespace = '';
401 401
         }
402
-        if(($sNamespace))
402
+        if (($sNamespace))
403 403
         {
404 404
             // If there is an autoloader, register the dir with PSR4 autoloading
405
-            if(($this->xAutoloader))
405
+            if (($this->xAutoloader))
406 406
             {
407 407
                 $this->xAutoloader->setPsr4($sNamespace . '\\', $sDirectory);
408 408
             }
409 409
         }
410
-        elseif(($this->xAutoloader))
410
+        elseif (($this->xAutoloader))
411 411
         {
412 412
             // If there is an autoloader, register the dir with classmap autoloading
413 413
             $itDir = new RecursiveDirectoryIterator($sDirectory);
414 414
             $itFile = new RecursiveIteratorIterator($itDir);
415 415
             // Iterate on dir content
416
-            foreach($itFile as $xFile)
416
+            foreach ($itFile as $xFile)
417 417
             {
418 418
                 // skip everything except PHP files
419
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
419
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
420 420
                 {
421 421
                     continue;
422 422
                 }
@@ -452,33 +452,33 @@  discard block
 block discarded – undo
452 452
         $sClassPath = substr($xFile->getPath(), strlen($sDirectory));
453 453
         $sClassPath = str_replace($sDS, '\\', trim($sClassPath, $sDS));
454 454
         $sClassName = $xFile->getBasename('.php');
455
-        if(($sNamespace))
455
+        if (($sNamespace))
456 456
         {
457 457
             $sClassPath = ($sClassPath) ? $sNamespace . '\\' . $sClassPath : $sNamespace;
458 458
             $sClassName = '\\' . $sClassPath . '\\' . $sClassName;
459 459
         }
460 460
         // Require the file only if autoload is enabled but there is no autoloader
461
-        if(($this->bAutoloadEnabled) && !($this->xAutoloader))
461
+        if (($this->bAutoloadEnabled) && !($this->xAutoloader))
462 462
         {
463 463
             require_once($xFile->getPathname());
464 464
         }
465 465
         // Create and register an instance of the class
466
-        if(!array_key_exists('*', $aOptions) || !is_array($aOptions['*']))
466
+        if (!array_key_exists('*', $aOptions) || !is_array($aOptions['*']))
467 467
         {
468 468
             $aOptions['*'] = array();
469 469
         }
470 470
         $aOptions['*']['separator'] = $sSeparator;
471
-        if(($sNamespace))
471
+        if (($sNamespace))
472 472
         {
473 473
             $aOptions['*']['namespace'] = $sNamespace;
474 474
         }
475
-        if(($sClassPath))
475
+        if (($sClassPath))
476 476
         {
477 477
             $aOptions['*']['classpath'] = $sClassPath;
478 478
         }
479 479
         // Filter excluded methods
480
-        $aProtected = array_filter($aProtected, function ($sName) {return is_string($sName);});
481
-        if(count($aProtected) > 0)
480
+        $aProtected = array_filter($aProtected, function($sName) {return is_string($sName); });
481
+        if (count($aProtected) > 0)
482 482
         {
483 483
             $aOptions['*']['protected'] = $aProtected;
484 484
         }
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
         $sDS = DIRECTORY_SEPARATOR;
498 498
         // Change the keys in $aOptions to have "\" as separator
499 499
         $aNewOptions = array();
500
-        foreach($aOptions as $key => $aOption)
500
+        foreach ($aOptions as $key => $aOption)
501 501
         {
502 502
             $key = trim(str_replace(['.', '_'], ['\\', '\\'], $key), ' \\');
503 503
             $aNewOptions[$key] = $aOption;
504 504
         }
505 505
 
506
-        foreach($this->aClassDirs as $aClassDir)
506
+        foreach ($this->aClassDirs as $aClassDir)
507 507
         {
508 508
             // Get the directory
509 509
             $sDirectory = $aClassDir['directory'];
@@ -513,10 +513,10 @@  discard block
 block discarded – undo
513 513
             $itDir = new RecursiveDirectoryIterator($sDirectory);
514 514
             $itFile = new RecursiveIteratorIterator($itDir);
515 515
             // Iterate on dir content
516
-            foreach($itFile as $xFile)
516
+            foreach ($itFile as $xFile)
517 517
             {
518 518
                 // skip everything except PHP files
519
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
519
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
520 520
                 {
521 521
                     continue;
522 522
                 }
@@ -525,13 +525,13 @@  discard block
 block discarded – undo
525 525
                 $sClassPath = substr($xFile->getPath(), strlen($sDirectory));
526 526
                 $sClassPath = trim(str_replace($sDS, '\\', $sClassPath), '\\');
527 527
                 $sClassName = $sClassPath . '\\' . $xFile->getBasename('.php');
528
-                if(($sNamespace))
528
+                if (($sNamespace))
529 529
                 {
530 530
                     $sClassName = $sNamespace . '\\' . $sClassName;
531 531
                 }
532 532
                 // Get the class options
533 533
                 $aClassOptions = [];
534
-                if(array_key_exists($sClassName, $aNewOptions))
534
+                if (array_key_exists($sClassName, $aNewOptions))
535 535
                 {
536 536
                     $aClassOptions = $aNewOptions[$sClassName];
537 537
                 }
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
      */
553 553
     public function registerClass($sClassName, array $aOptions = array())
554 554
     {
555
-        if(!($sClassName = trim($sClassName, ' \\._')))
555
+        if (!($sClassName = trim($sClassName, ' \\._')))
556 556
         {
557 557
             return false;
558 558
         }
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
         // Replace "." and "_" with antislashes, and set the class path.
562 562
         $sClassName = str_replace(['.', '_'], ['\\', '\\'], $sClassName);
563 563
         $sClassPath = '';
564
-        if(($nLastSlashPosition = strrpos($sClassName, '\\')) !== false)
564
+        if (($nLastSlashPosition = strrpos($sClassName, '\\')) !== false)
565 565
         {
566 566
             $sClassPath = substr($sClassName, 0, $nLastSlashPosition);
567 567
             $sClassName = substr($sClassName, $nLastSlashPosition + 1);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         $sPartPath = str_replace('\\', $sDS, $sClassPath) . $sDS . $sClassName . '.php';
571 571
 
572 572
         // Search for the class file in all directories.
573
-        foreach($this->aClassDirs as $aClassDir)
573
+        foreach ($this->aClassDirs as $aClassDir)
574 574
         {
575 575
             // Get the separator
576 576
             $sSeparator = $aClassDir['separator'];
@@ -579,15 +579,15 @@  discard block
 block discarded – undo
579 579
             $nLen = strlen($sNamespace);
580 580
             $sFullPath = '';
581 581
             // Check if the class belongs to the namespace
582
-            if(($sNamespace) && substr($sClassPath, 0, $nLen) == $sNamespace)
582
+            if (($sNamespace) && substr($sClassPath, 0, $nLen) == $sNamespace)
583 583
             {
584 584
                 $sFullPath = $aClassDir['directory'] . $sDS . substr($sPartPath, $nLen + 1);
585 585
             }
586
-            elseif(!($sNamespace))
586
+            elseif (!($sNamespace))
587 587
             {
588 588
                 $sFullPath = $aClassDir['directory'] . $sDS . $sPartPath;
589 589
             }
590
-            if(($sFullPath) && is_file($sFullPath))
590
+            if (($sFullPath) && is_file($sFullPath))
591 591
             {
592 592
                 // Found the file in this directory
593 593
                 $xFileInfo = new \SplFileInfo($sFullPath);
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
     {
612 612
         $xObject = null; // The user registered object
613 613
         $xPlugin = $this->getRequestPlugin('CallableObject'); // The CallableObject plugin
614
-        if(($xPlugin))
614
+        if (($xPlugin))
615 615
         {
616 616
             $xObject = $xPlugin->getRegisteredObject($sClassName);
617 617
         }
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
      */
626 626
     private function getJsLibUri()
627 627
     {
628
-        if(!$this->hasOption('js.lib.uri'))
628
+        if (!$this->hasOption('js.lib.uri'))
629 629
         {
630 630
             return 'https://cdn.jsdelivr.net/jaxon/1.2.0/';
631 631
         }
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
         $jsDelivrUri = 'https://cdn.jsdelivr.net';
646 646
         $nLen = strlen($jsDelivrUri);
647 647
         // The jsDelivr CDN only hosts minified files
648
-        if(($this->getOption('js.app.minify')) || substr($this->getJsLibUri(), 0, $nLen) == $jsDelivrUri)
648
+        if (($this->getOption('js.app.minify')) || substr($this->getJsLibUri(), 0, $nLen) == $jsDelivrUri)
649 649
         {
650 650
             return '.min.js';
651 651
         }
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
         // Check config options
663 663
         // - The js.app.extern option must be set to true
664 664
         // - The js.app.uri and js.app.dir options must be set to non null values
665
-        if(!$this->getOption('js.app.extern') ||
665
+        if (!$this->getOption('js.app.extern') ||
666 666
             !$this->getOption('js.app.uri') ||
667 667
             !$this->getOption('js.app.dir'))
668 668
         {
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
         // Check dir access
672 672
         // - The js.app.dir must be writable
673 673
         $sJsAppDir = $this->getOption('js.app.dir');
674
-        if(!is_dir($sJsAppDir) || !is_writable($sJsAppDir))
674
+        if (!is_dir($sJsAppDir) || !is_writable($sJsAppDir))
675 675
         {
676 676
             return false;
677 677
         }
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      */
686 686
     private function setTemplateCacheDir()
687 687
     {
688
-        if($this->hasOption('core.template.cache_dir'))
688
+        if ($this->hasOption('core.template.cache_dir'))
689 689
         {
690 690
             $this->setCacheDir($this->getOption('core.template.cache_dir'));
691 691
         }
@@ -707,11 +707,11 @@  discard block
 block discarded – undo
707 707
 
708 708
         // Add component files to the javascript file array;
709 709
         $aJsFiles = array($sJsCoreUrl);
710
-        if($this->getOption('core.debug.on'))
710
+        if ($this->getOption('core.debug.on'))
711 711
         {
712 712
             $aJsFiles[] = $sJsDebugUrl;
713 713
             $aJsFiles[] = $sJsLanguageUrl;
714
-            if($this->getOption('core.debug.verbose'))
714
+            if ($this->getOption('core.debug.verbose'))
715 715
             {
716 716
                 $aJsFiles[] = $sJsVerboseUrl;
717 717
             }
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
             'sJsOptions' => $this->getOption('js.app.options'),
724 724
             'aUrls' => $aJsFiles,
725 725
         ));
726
-        foreach($this->aResponsePlugins as $xPlugin)
726
+        foreach ($this->aResponsePlugins as $xPlugin)
727 727
         {
728 728
             $sCode .= rtrim($xPlugin->getJs(), " \n") . "\n";
729 729
         }
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
         $this->setTemplateCacheDir();
742 742
 
743 743
         $sCode = '';
744
-        foreach($this->aResponsePlugins as $xPlugin)
744
+        foreach ($this->aResponsePlugins as $xPlugin)
745 745
         {
746 746
             $sCode .= rtrim($xPlugin->getCss(), " \n") . "\n";
747 747
         }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
         ));
830 830
 
831 831
         $sPluginScript = '';
832
-        foreach($this->aResponsePlugins as $xPlugin)
832
+        foreach ($this->aResponsePlugins as $xPlugin)
833 833
         {
834 834
             $sPluginScript .= "\n" . trim($xPlugin->getScript(), " \n");
835 835
         }
@@ -861,11 +861,11 @@  discard block
 block discarded – undo
861 861
 
862 862
         // Get the config and plugins scripts
863 863
         $sScript = $this->getConfigScript() . "\n" . $this->getReadyScript() . "\n";
864
-        foreach($this->aRequestPlugins as $xPlugin)
864
+        foreach ($this->aRequestPlugins as $xPlugin)
865 865
         {
866 866
             $sScript .= "\n" . trim($xPlugin->getScript(), " \n");
867 867
         }
868
-        if($this->canExportJavascript())
868
+        if ($this->canExportJavascript())
869 869
         {
870 870
             $sJsAppURI = rtrim($this->getOption('js.app.uri'), '/') . '/';
871 871
             $sJsAppDir = rtrim($this->getOption('js.app.dir'), '/') . '/';
@@ -874,13 +874,13 @@  discard block
 block discarded – undo
874 874
             $sHash = $this->generateHash();
875 875
             $sOutFile = $sHash . '.js';
876 876
             $sMinFile = $sHash . '.min.js';
877
-            if(!is_file($sJsAppDir . $sOutFile))
877
+            if (!is_file($sJsAppDir . $sOutFile))
878 878
             {
879 879
                 file_put_contents($sJsAppDir . $sOutFile, $sScript);
880 880
             }
881
-            if(($this->getOption('js.app.minify')))
881
+            if (($this->getOption('js.app.minify')))
882 882
             {
883
-                if(($this->minify($sJsAppDir . $sOutFile, $sJsAppDir . $sMinFile)))
883
+                if (($this->minify($sJsAppDir . $sOutFile, $sJsAppDir . $sMinFile)))
884 884
                 {
885 885
                     $sOutFile = $sMinFile;
886 886
                 }
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     public function getResponsePlugin($sName)
915 915
     {
916
-        if(array_key_exists($sName, $this->aResponsePlugins))
916
+        if (array_key_exists($sName, $this->aResponsePlugins))
917 917
         {
918 918
             return $this->aResponsePlugins[$sName];
919 919
         }
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
      */
930 930
     public function getRequestPlugin($sName)
931 931
     {
932
-        if(array_key_exists($sName, $this->aRequestPlugins))
932
+        if (array_key_exists($sName, $this->aRequestPlugins))
933 933
         {
934 934
             return $this->aRequestPlugins[$sName];
935 935
         }
Please login to merge, or discard this patch.