[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/php/ -> ini.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\php;
  15  
  16  /**
  17  * Wrapper class for ini_get function.
  18  *
  19  * Provides easier handling of the different interpretations of ini values.
  20  * @deprecated 3.2.10 (To be removed 4.0.0)
  21  */
  22  class ini
  23  {
  24      /**
  25      * Simple wrapper for ini_get()
  26      * See http://php.net/manual/en/function.ini-get.php
  27      *
  28      * @param string $varname    The configuration option name.
  29      * @return bool|string        False if configuration option does not exist,
  30      *                            the configuration option value (string) otherwise.
  31      */
  32  	public function get($varname)
  33      {
  34          return ini_get($varname);
  35      }
  36  
  37      /**
  38      * Gets the configuration option value as a trimmed string.
  39      *
  40      * @param string $varname    The configuration option name.
  41      * @return bool|string        False if configuration option does not exist,
  42      *                            the configuration option value (string) otherwise.
  43      */
  44  	public function get_string($varname)
  45      {
  46          $value = $this->get($varname);
  47  
  48          if ($value === false)
  49          {
  50              return false;
  51          }
  52  
  53          return trim($value);
  54      }
  55  
  56      /**
  57      * Gets configuration option value as a boolean.
  58      * Interprets the string value 'off' as false.
  59      *
  60      * @param string $varname    The configuration option name.
  61      * @return bool                False if configuration option does not exist.
  62      *                            False if configuration option is disabled.
  63      *                            True otherwise.
  64      */
  65  	public function get_bool($varname)
  66      {
  67          $value = $this->get_string($varname);
  68  
  69          if (empty($value) || strtolower($value) == 'off')
  70          {
  71              return false;
  72          }
  73  
  74          return true;
  75      }
  76  
  77      /**
  78      * Gets configuration option value as an integer.
  79      *
  80      * @param string $varname    The configuration option name.
  81      * @return bool|int            False if configuration option does not exist,
  82      *                            false if configuration option value is not numeric,
  83      *                            the configuration option value (integer) otherwise.
  84      */
  85  	public function get_int($varname)
  86      {
  87          $value = $this->get_string($varname);
  88  
  89          if (!is_numeric($value))
  90          {
  91              return false;
  92          }
  93  
  94          return (int) $value;
  95      }
  96  
  97      /**
  98      * Gets configuration option value as a float.
  99      *
 100      * @param string $varname    The configuration option name.
 101      * @return bool|float        False if configuration option does not exist,
 102      *                            false if configuration option value is not numeric,
 103      *                            the configuration option value (float) otherwise.
 104      */
 105  	public function get_float($varname)
 106      {
 107          $value = $this->get_string($varname);
 108  
 109          if (!is_numeric($value))
 110          {
 111              return false;
 112          }
 113  
 114          return (float) $value;
 115      }
 116  
 117      /**
 118      * Gets configuration option value in bytes.
 119      * Converts strings like '128M' to bytes (integer or float).
 120      *
 121      * @param string $varname    The configuration option name.
 122      * @return bool|int|float    False if configuration option does not exist,
 123      *                            false if configuration option value is not well-formed,
 124      *                            the configuration option value otherwise.
 125      */
 126  	public function get_bytes($varname)
 127      {
 128          $value = $this->get_string($varname);
 129  
 130          if ($value === false)
 131          {
 132              return false;
 133          }
 134  
 135          if (is_numeric($value))
 136          {
 137              // Already in bytes.
 138              return phpbb_to_numeric($value);
 139          }
 140          else if (strlen($value) < 2)
 141          {
 142              // Single character.
 143              return false;
 144          }
 145          else if (strlen($value) < 3 && $value[0] === '-')
 146          {
 147              // Two characters but the first one is a minus.
 148              return false;
 149          }
 150  
 151          $value_lower = strtolower($value);
 152          $value_numeric = phpbb_to_numeric($value);
 153  
 154          switch ($value_lower[strlen($value_lower) - 1])
 155          {
 156              case 'g':
 157                  $value_numeric *= 1024;
 158              case 'm':
 159                  $value_numeric *= 1024;
 160              case 'k':
 161                  $value_numeric *= 1024;
 162              break;
 163  
 164              default:
 165                  // It's not already in bytes (and thus numeric)
 166                  // and does not carry a unit.
 167                  return false;
 168          }
 169  
 170          return $value_numeric;
 171      }
 172  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1