[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/phpbb/config/ -> config.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\config;
  15  
  16  /**
  17  * Configuration container class
  18  */
  19  class config implements \ArrayAccess, \IteratorAggregate, \Countable
  20  {
  21      /**
  22      * The configuration data
  23      * @var array<string,string>
  24      */
  25      protected $config;
  26  
  27      /**
  28      * Creates a configuration container with a default set of values
  29      *
  30      * @param array<string,string> $config The configuration data.
  31      */
  32  	public function __construct(array $config)
  33      {
  34          $this->config = $config;
  35      }
  36  
  37      /**
  38      * Retrieves an ArrayIterator over the configuration values.
  39      *
  40      * @return \ArrayIterator An iterator over all config data
  41      */
  42  	public function getIterator()
  43      {
  44          return new \ArrayIterator($this->config);
  45      }
  46  
  47      /**
  48      * Checks if the specified config value exists.
  49      *
  50      * @param  string $key The configuration option's name.
  51      * @return bool        Whether the configuration option exists.
  52      */
  53      #[\ReturnTypeWillChange]
  54  	public function offsetExists($key)
  55      {
  56          return isset($this->config[$key]);
  57      }
  58  
  59      /**
  60      * Retrieves a configuration value.
  61      *
  62      * @param  string $key The configuration option's name.
  63      * @return string      The configuration value
  64      */
  65      #[\ReturnTypeWillChange]
  66  	public function offsetGet($key)
  67      {
  68          return (isset($this->config[$key])) ? $this->config[$key] : '';
  69      }
  70  
  71      /**
  72      * Temporarily overwrites the value of a configuration variable.
  73      *
  74      * The configuration change will not persist. It will be lost
  75      * after the request.
  76      *
  77      * @param string $key   The configuration option's name.
  78      * @param string $value The temporary value.
  79      */
  80      #[\ReturnTypeWillChange]
  81  	public function offsetSet($key, $value)
  82      {
  83          $this->config[$key] = $value;
  84      }
  85  
  86      /**
  87      * Called when deleting a configuration value directly, triggers an error.
  88      *
  89      * @param string $key The configuration option's name.
  90      */
  91      #[\ReturnTypeWillChange]
  92  	public function offsetUnset($key)
  93      {
  94          trigger_error('Config values have to be deleted explicitly with the \phpbb\config\config::delete($key) method.', E_USER_ERROR);
  95      }
  96  
  97      /**
  98      * Retrieves the number of configuration options currently set.
  99      *
 100      * @return int Number of config options
 101      */
 102  	public function count()
 103      {
 104          return count($this->config);
 105      }
 106  
 107      /**
 108      * Removes a configuration option
 109      *
 110      * @param  String $key       The configuration option's name
 111      * @param  bool   $use_cache Whether this variable should be cached or if it
 112      *                           changes too frequently to be efficiently cached
 113      * @return null
 114      */
 115  	public function delete($key, $use_cache = true)
 116      {
 117          unset($this->config[$key]);
 118      }
 119  
 120      /**
 121      * Sets a configuration option's value
 122      *
 123      * @param string $key       The configuration option's name
 124      * @param string $value     New configuration value
 125      * @param bool   $use_cache Whether this variable should be cached or if it
 126      *                          changes too frequently to be efficiently cached.
 127      */
 128  	public function set($key, $value, $use_cache = true)
 129      {
 130          $this->config[$key] = $value;
 131      }
 132  
 133      /**
 134      * Sets a configuration option's value only if the old_value matches the
 135      * current configuration value or the configuration value does not exist yet.
 136      *
 137      * @param  string $key       The configuration option's name
 138      * @param  string $old_value Current configuration value
 139      * @param  string $new_value New configuration value
 140      * @param  bool   $use_cache Whether this variable should be cached or if it
 141      *                           changes too frequently to be efficiently cached.
 142      * @return bool              True if the value was changed, false otherwise.
 143      */
 144  	public function set_atomic($key, $old_value, $new_value, $use_cache = true)
 145      {
 146          if (!isset($this->config[$key]) || $this->config[$key] == $old_value)
 147          {
 148              $this->config[$key] = $new_value;
 149              return true;
 150          }
 151          return false;
 152      }
 153  
 154      /**
 155      * Checks configuration option's value only if the new_value matches the
 156      * current configuration value and the configuration value does exist.Called
 157      * only after set_atomic has been called.
 158      *
 159      * @param  string $key       The configuration option's name
 160      * @param  string $new_value New configuration value
 161      * @throws \phpbb\exception\http_exception when config value is set and not equal to new_value.
 162      * @return bool              True if the value was changed, false otherwise.
 163      */
 164  	public function ensure_lock($key, $new_value)
 165      {
 166          if (isset($this->config[$key]) && $this->config[$key] == $new_value)
 167          {
 168              return true;
 169          }
 170          throw new \phpbb\exception\http_exception(500, 'Failure while aqcuiring locks.');
 171      }
 172  
 173      /**
 174      * Increments an integer configuration value.
 175      *
 176      * @param string $key       The configuration option's name
 177      * @param int    $increment Amount to increment by
 178      * @param bool   $use_cache Whether this variable should be cached or if it
 179      *                          changes too frequently to be efficiently cached.
 180      */
 181  	function increment($key, $increment, $use_cache = true)
 182      {
 183          if (!isset($this->config[$key]))
 184          {
 185              $this->config[$key] = 0;
 186          }
 187  
 188          $this->config[$key] += $increment;
 189      }
 190  }


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1