Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Helper trait store.
  19   *
  20   * @package    tool_log
  21   * @copyright  2014 onwards Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_log\helper;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Helper trait store. Adds some helper methods for stores.
  30   *
  31   * @package    tool_log
  32   * @copyright  2014 onwards Ankit Agarwal
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  trait store {
  36  
  37      /** @var \tool_log\log\manager $manager manager instance. */
  38      protected $manager;
  39  
  40      /** @var string $component Frankenstyle store name. */
  41      protected $component;
  42  
  43      /** @var string $store name of the store. */
  44      protected $store;
  45  
  46  
  47      /**
  48       * Setup store specific variables.
  49       *
  50       * @param \tool_log\log\manager $manager manager instance.
  51       */
  52      protected function helper_setup(\tool_log\log\manager $manager) {
  53          $this->manager = $manager;
  54          $called = get_called_class();
  55          $parts = explode('\\', $called);
  56          if (!isset($parts[0]) || strpos($parts[0], 'logstore_') !== 0) {
  57              throw new \coding_exception("Store $called doesn't define classes in correct namespaces.");
  58          }
  59          $this->component = $parts[0];
  60          $this->store = str_replace('logstore_', '', $this->component);
  61      }
  62  
  63      /**
  64       * Api to get plugin config
  65       *
  66       * @param string $name name of the config.
  67       * @param null|mixed $default default value to return.
  68       *
  69       * @return mixed|null return config value.
  70       */
  71      protected function get_config($name, $default = null) {
  72          $value = get_config($this->component, $name);
  73          if ($value !== false) {
  74              return $value;
  75          }
  76          return $default;
  77      }
  78  
  79  }