[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/debug/src/DataCollector/ -> LanguageFilesCollector.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.Debug
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Plugin\System\Debug\DataCollector;
  12  
  13  use DebugBar\DataCollector\AssetProvider;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Uri\Uri;
  16  use Joomla\Plugin\System\Debug\AbstractDataCollector;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * LanguageFilesDataCollector
  24   *
  25   * @since  4.0.0
  26   */
  27  class LanguageFilesCollector extends AbstractDataCollector implements AssetProvider
  28  {
  29      /**
  30       * Collector name.
  31       *
  32       * @var   string
  33       * @since 4.0.0
  34       */
  35      private $name = 'languageFiles';
  36  
  37      /**
  38       * The count.
  39       *
  40       * @var   integer
  41       * @since 4.0.0
  42       */
  43      private $count = 0;
  44  
  45      /**
  46       * Called by the DebugBar when data needs to be collected
  47       *
  48       * @since  4.0.0
  49       *
  50       * @return array Collected data
  51       */
  52      public function collect(): array
  53      {
  54          $paths = Factory::getLanguage()->getPaths();
  55          $loaded = [];
  56  
  57          foreach ($paths as $extension => $files) {
  58              $loaded[$extension] = [];
  59  
  60              foreach ($files as $file => $status) {
  61                  $loaded[$extension][$file] = $status;
  62  
  63                  if ($status) {
  64                      $this->count++;
  65                  }
  66              }
  67          }
  68  
  69          return [
  70              'loaded' => $loaded,
  71              'xdebugLink' => $this->getXdebugLinkTemplate(),
  72              'jroot' => JPATH_ROOT,
  73              'count' => $this->count,
  74          ];
  75      }
  76  
  77      /**
  78       * Returns the unique name of the collector
  79       *
  80       * @since  4.0.0
  81       *
  82       * @return string
  83       */
  84      public function getName(): string
  85      {
  86          return $this->name;
  87      }
  88  
  89      /**
  90       * Returns a hash where keys are control names and their values
  91       * an array of options as defined in {@see \DebugBar\JavascriptRenderer::addControl()}
  92       *
  93       * @since  4.0.0
  94       *
  95       * @return array
  96       */
  97      public function getWidgets(): array
  98      {
  99          return [
 100              'loaded' => [
 101                  'icon' => 'language',
 102                  'widget' => 'PhpDebugBar.Widgets.languageFilesWidget',
 103                  'map' => $this->name,
 104                  'default' => '[]',
 105              ],
 106              'loaded:badge' => [
 107                  'map'     => $this->name . '.count',
 108                  'default' => 'null',
 109              ],
 110          ];
 111      }
 112  
 113      /**
 114       * Returns an array with the following keys:
 115       *  - base_path
 116       *  - base_url
 117       *  - css: an array of filenames
 118       *  - js: an array of filenames
 119       *
 120       * @since  4.0.0
 121       * @return array
 122       */
 123      public function getAssets(): array
 124      {
 125          return [
 126              'js' => Uri::root(true) . '/media/plg_system_debug/widgets/languageFiles/widget.min.js',
 127              'css' => Uri::root(true) . '/media/plg_system_debug/widgets/languageFiles/widget.min.css',
 128          ];
 129      }
 130  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer