[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/debug/src/DataCollector/ -> LanguageErrorsCollector.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   * LanguageErrorsDataCollector
  24   *
  25   * @since  4.0.0
  26   */
  27  class LanguageErrorsCollector extends AbstractDataCollector implements AssetProvider
  28  {
  29      /**
  30       * Collector name.
  31       *
  32       * @var   string
  33       * @since 4.0.0
  34       */
  35      private $name = 'languageErrors';
  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          return [
  55              'data'  => [
  56                  'files' => $this->getData(),
  57                  'jroot' => JPATH_ROOT,
  58                  'xdebugLink' => $this->getXdebugLinkTemplate(),
  59              ],
  60              'count' => $this->getCount(),
  61          ];
  62      }
  63  
  64      /**
  65       * Returns the unique name of the collector
  66       *
  67       * @since  4.0.0
  68       *
  69       * @return string
  70       */
  71      public function getName(): string
  72      {
  73          return $this->name;
  74      }
  75  
  76      /**
  77       * Returns a hash where keys are control names and their values
  78       * an array of options as defined in {@see \DebugBar\JavascriptRenderer::addControl()}
  79       *
  80       * @since  4.0.0
  81       *
  82       * @return array
  83       */
  84      public function getWidgets(): array
  85      {
  86          return [
  87              'errors'       => [
  88                  'icon' => 'warning',
  89                  'widget'  => 'PhpDebugBar.Widgets.languageErrorsWidget',
  90                  'map'     => $this->name . '.data',
  91                  'default' => '',
  92              ],
  93              'errors:badge' => [
  94                  'map'     => $this->name . '.count',
  95                  'default' => 'null',
  96              ],
  97          ];
  98      }
  99  
 100      /**
 101       * Returns an array with the following keys:
 102       *  - base_path
 103       *  - base_url
 104       *  - css: an array of filenames
 105       *  - js: an array of filenames
 106       *
 107       * @since  4.0.0
 108       * @return array
 109       */
 110      public function getAssets()
 111      {
 112          return [
 113              'js' => Uri::root(true) . '/media/plg_system_debug/widgets/languageErrors/widget.min.js',
 114              'css' => Uri::root(true) . '/media/plg_system_debug/widgets/languageErrors/widget.min.css',
 115          ];
 116      }
 117  
 118      /**
 119       * Collect data.
 120       *
 121       * @return array
 122       *
 123       * @since 4.0.0
 124       */
 125      private function getData(): array
 126      {
 127          $errorFiles = Factory::getLanguage()->getErrorFiles();
 128          $errors     = [];
 129  
 130          if (\count($errorFiles)) {
 131              foreach ($errorFiles as $file => $lines) {
 132                  foreach ($lines as $line) {
 133                      $errors[] = [$file, $line];
 134                      $this->count++;
 135                  }
 136              }
 137          }
 138  
 139          return $errors;
 140      }
 141  
 142      /**
 143       * Get a count value.
 144       *
 145       * @return int
 146       *
 147       * @since 4.0.0
 148       */
 149      private function getCount(): int
 150      {
 151          return $this->count;
 152      }
 153  }


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