Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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  namespace core_external;
  18  
  19  /**
  20   * Singleton to handle the external settings..
  21   *
  22   * We use singleton to encapsulate the "logic".
  23   *
  24   * @package    core_external
  25   * @copyright  2012 Jerome Mouneyrac
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class external_settings {
  29  
  30      /** @var settings|null the singleton instance */
  31      public static $instance = null;
  32  
  33      /** @var bool Should the external function return raw text or formatted */
  34      private $raw = false;
  35  
  36      /** @var bool Should the external function filter the text */
  37      private $filter = false;
  38  
  39      /** @var bool Should the external function rewrite plugin file url */
  40      private $fileurl = true;
  41  
  42      /** @var string In which file should the urls be rewritten */
  43      private $file = 'webservice/pluginfile.php';
  44  
  45      /** @var string The session lang */
  46      private $lang = '';
  47  
  48      /** @var string The timezone to use during this WS request */
  49      private $timezone = '';
  50  
  51      /**
  52       * Constructor - protected - can not be instanciated
  53       */
  54      protected function __construct() {
  55          if ((AJAX_SCRIPT == false) && (CLI_SCRIPT == false) && (WS_SERVER == false)) {
  56              // For normal pages, the default should match the default for format_text.
  57              $this->filter = true;
  58              // Use pluginfile.php for web requests.
  59              $this->file = 'pluginfile.php';
  60          }
  61      }
  62  
  63      /**
  64       * Return only one instance
  65       *
  66       * @return self
  67       */
  68      public static function get_instance() {
  69          if (self::$instance === null) {
  70              self::$instance = new self();
  71          }
  72  
  73          return self::$instance;
  74      }
  75  
  76      /**
  77       * Reset the singleton instance.
  78       */
  79      public static function reset(): void {
  80          self::$instance = null;
  81      }
  82  
  83      /**
  84       * Set raw
  85       *
  86       * @param boolean $raw
  87       */
  88      public function set_raw($raw) {
  89          $this->raw = $raw;
  90      }
  91  
  92      /**
  93       * Get raw
  94       *
  95       * @return boolean
  96       */
  97      public function get_raw() {
  98          return $this->raw;
  99      }
 100  
 101      /**
 102       * Set filter
 103       *
 104       * @param boolean $filter
 105       */
 106      public function set_filter($filter) {
 107          $this->filter = $filter;
 108      }
 109  
 110      /**
 111       * Get filter
 112       *
 113       * @return boolean
 114       */
 115      public function get_filter() {
 116          return $this->filter;
 117      }
 118  
 119      /**
 120       * Set fileurl
 121       *
 122       * @param bool $fileurl
 123       */
 124      public function set_fileurl($fileurl) {
 125          $this->fileurl = $fileurl;
 126      }
 127  
 128      /**
 129       * Get fileurl
 130       *
 131       * @return bool
 132       */
 133      public function get_fileurl() {
 134          return $this->fileurl;
 135      }
 136  
 137      /**
 138       * Set file
 139       *
 140       * @param string $file
 141       */
 142      public function set_file($file) {
 143          $this->file = $file;
 144      }
 145  
 146      /**
 147       * Get file
 148       *
 149       * @return string
 150       */
 151      public function get_file() {
 152          return $this->file;
 153      }
 154  
 155      /**
 156       * Set lang
 157       *
 158       * @param string $lang
 159       */
 160      public function set_lang($lang) {
 161          $this->lang = $lang;
 162      }
 163  
 164      /**
 165       * Get lang
 166       *
 167       * @return string
 168       */
 169      public function get_lang() {
 170          return $this->lang;
 171      }
 172  
 173      /**
 174       * Set timezone
 175       *
 176       * @param string $timezone
 177       */
 178      public function set_timezone($timezone) {
 179          $this->timezone = $timezone;
 180      }
 181  
 182      /**
 183       * Get timezone
 184       *
 185       * @return string
 186       */
 187      public function get_timezone() {
 188          return $this->timezone;
 189      }
 190  }