[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Log/Logger/ -> InMemoryLogger.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Log\Logger;
  11  
  12  use Joomla\CMS\Log\LogEntry;
  13  use Joomla\CMS\Log\Logger;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Logger class that keeps all entries in memory
  21   *
  22   * @since  4.0.0
  23   */
  24  class InMemoryLogger extends Logger
  25  {
  26      /**
  27       * List of collected log entries, grouped by $group
  28       *
  29       * @var array
  30       * @since  4.0.0
  31       */
  32      protected static $logEntries = [];
  33  
  34      /**
  35       * Group name to store the entries
  36       *
  37       * @var    string
  38       * @since  4.0.0
  39       */
  40      protected $group = 'default';
  41  
  42      /**
  43       * Constructor.
  44       *
  45       * @param   array  &$options  Log object options.
  46       *
  47       * @since   4.0.0
  48       */
  49      public function __construct(array &$options)
  50      {
  51          parent::__construct($options);
  52  
  53          if (!empty($this->options['group'])) {
  54              $this->group = $this->options['group'];
  55          }
  56      }
  57  
  58      /**
  59       * Method to add an entry to the log.
  60       *
  61       * @param   LogEntry  $entry  The log entry object to add to the log.
  62       *
  63       * @return  void
  64       *
  65       * @since   4.0.0
  66       */
  67      public function addEntry(LogEntry $entry)
  68      {
  69          static::$logEntries[$this->group][] = $entry;
  70      }
  71  
  72      /**
  73       * Returns a list of collected entries.
  74       *
  75       * @return  array
  76       *
  77       * @since   4.0.0
  78       */
  79      public function getCollectedEntries()
  80      {
  81          if (empty(static::$logEntries[$this->group])) {
  82              return [];
  83          }
  84  
  85          return static::$logEntries[$this->group];
  86      }
  87  }


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