[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/debug/src/DataCollector/ -> LanguageStringsCollector.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\Language\Language;
  16  use Joomla\CMS\Uri\Uri;
  17  use Joomla\Plugin\System\Debug\AbstractDataCollector;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * LanguageStringsDataCollector
  25   *
  26   * @since  4.0.0
  27   */
  28  class LanguageStringsCollector extends AbstractDataCollector implements AssetProvider
  29  {
  30      /**
  31       * Collector name.
  32       *
  33       * @var   string
  34       * @since 4.0.0
  35       */
  36      private $name = 'languageStrings';
  37  
  38      /**
  39       * Called by the DebugBar when data needs to be collected
  40       *
  41       * @since  4.0.0
  42       *
  43       * @return array Collected data
  44       */
  45      public function collect(): array
  46      {
  47          return [
  48              'data'  => $this->getData(),
  49              'count' => $this->getCount(),
  50          ];
  51      }
  52  
  53      /**
  54       * Returns the unique name of the collector
  55       *
  56       * @since  4.0.0
  57       *
  58       * @return string
  59       */
  60      public function getName(): string
  61      {
  62          return $this->name;
  63      }
  64  
  65      /**
  66       * Returns a hash where keys are control names and their values
  67       * an array of options as defined in {@see \DebugBar\JavascriptRenderer::addControl()}
  68       *
  69       * @since  4.0.0
  70       *
  71       * @return array
  72       */
  73      public function getWidgets(): array
  74      {
  75          return [
  76              'untranslated'       => [
  77                  'icon'    => 'question-circle',
  78                  'widget'  => 'PhpDebugBar.Widgets.languageStringsWidget',
  79                  'map'     => $this->name . '.data',
  80                  'default' => '',
  81              ],
  82              'untranslated:badge' => [
  83                  'map'     => $this->name . '.count',
  84                  'default' => 'null',
  85              ],
  86          ];
  87      }
  88  
  89      /**
  90       * Returns an array with the following keys:
  91       *  - base_path
  92       *  - base_url
  93       *  - css: an array of filenames
  94       *  - js: an array of filenames
  95       *
  96       * @since  4.0.0
  97       * @return array
  98       */
  99      public function getAssets(): array
 100      {
 101          return [
 102              'js'  => Uri::root(true) . '/media/plg_system_debug/widgets/languageStrings/widget.min.js',
 103              'css' => Uri::root(true) . '/media/plg_system_debug/widgets/languageStrings/widget.min.css',
 104          ];
 105      }
 106  
 107      /**
 108       * Collect data.
 109       *
 110       * @return array
 111       *
 112       * @since 4.0.0
 113       */
 114      private function getData(): array
 115      {
 116          $orphans = Factory::getLanguage()->getOrphans();
 117  
 118          $data = [];
 119  
 120          foreach ($orphans as $orphan => $occurrences) {
 121              $data[$orphan] = [];
 122  
 123              foreach ($occurrences as $occurrence) {
 124                  $item = [];
 125  
 126                  $item['string'] = $occurrence['string'] ?? 'n/a';
 127                  $item['trace']  = [];
 128                  $item['caller'] = '';
 129  
 130                  if (isset($occurrence['trace'])) {
 131                      $cnt            = 0;
 132                      $trace          = [];
 133                      $callerLocation = '';
 134  
 135                      array_shift($occurrence['trace']);
 136  
 137                      foreach ($occurrence['trace'] as $i => $stack) {
 138                          $class = $stack['class'] ?? '';
 139                          $file  = $stack['file'] ?? '';
 140                          $line  = $stack['line'] ?? '';
 141  
 142                          $caller   = $this->formatCallerInfo($stack);
 143                          $location = $file && $line ? "$file:$line" : 'same';
 144  
 145                          $isCaller = 0;
 146  
 147                          if (!$callerLocation && $class !== Language::class && !strpos($file, 'Text.php')) {
 148                              $callerLocation = $location;
 149                              $isCaller       = 1;
 150                          }
 151  
 152                          $trace[] = [
 153                              \count($occurrence['trace']) - $cnt,
 154                              $isCaller,
 155                              $caller,
 156                              $file,
 157                              $line,
 158                          ];
 159  
 160                          $cnt++;
 161                      }
 162  
 163                      $item['trace']  = $trace;
 164                      $item['caller'] = $callerLocation;
 165                  }
 166  
 167                  $data[$orphan][] = $item;
 168              }
 169          }
 170  
 171          return [
 172              'orphans'    => $data,
 173              'jroot'      => JPATH_ROOT,
 174              'xdebugLink' => $this->getXdebugLinkTemplate(),
 175          ];
 176      }
 177  
 178      /**
 179       * Get a count value.
 180       *
 181       * @return integer
 182       *
 183       * @since 4.0.0
 184       */
 185      private function getCount(): int
 186      {
 187          return \count(Factory::getLanguage()->getOrphans());
 188      }
 189  }


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