[ Index ]

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1