[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> php_api.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT 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 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT 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 MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * PHP Compatibility API
  19   *
  20   * Provides functions to assist with backwards compatibility between PHP
  21   * versions.
  22   *
  23   * @package CoreAPI
  24   * @subpackage PHPCompatibilityAPI
  25   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  26   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  27   * @link http://www.mantisbt.org
  28   */
  29  
  30  /**
  31   * Constant for our minimum required PHP version
  32   */
  33  define( 'PHP_MIN_VERSION', '5.3.2' );
  34  
  35  # cache array of comparisons
  36  $g_cached_version = array();
  37  
  38  /**
  39   * Determine if PHP is running in CLI or CGI mode and return the mode.
  40   * @return int PHP mode
  41   */
  42  function php_mode() {
  43      static $s_mode = null;
  44  
  45      if ( is_null( $s_mode ) ) {
  46          # Check to see if this is CLI mode or CGI mode
  47          if ( isset( $_SERVER['SERVER_ADDR'] )
  48              || isset( $_SERVER['LOCAL_ADDR'] )
  49              || isset( $_SERVER['REMOTE_ADDR'] ) ) {
  50              $s_mode = PHP_CGI;
  51          } else {
  52              $s_mode = PHP_CLI;
  53          }
  54      }
  55  
  56      return $s_mode;
  57  }
  58  
  59  # Returns true if the current PHP version is higher than the one
  60  #  specified in the given string
  61  function php_version_at_least( $p_version_string ) {
  62      global $g_cached_version;
  63  
  64      if( isset( $g_cached_version[$p_version_string] ) ) {
  65          return $g_cached_version[$p_version_string];
  66      }
  67  
  68      $t_curver = array_pad( explode( '.', phpversion() ), 3, 0 );
  69      $t_minver = array_pad( explode( '.', $p_version_string ), 3, 0 );
  70  
  71      for( $i = 0;$i < 3;$i = $i + 1 ) {
  72          $t_cur = (int) $t_curver[$i];
  73          $t_min = (int) $t_minver[$i];
  74  
  75          if( $t_cur < $t_min ) {
  76              $g_cached_version[$p_version_string] = false;
  77              return false;
  78          }
  79          else if( $t_cur > $t_min ) {
  80              $g_cached_version[$p_version_string] = true;
  81              return true;
  82          }
  83      }
  84  
  85      # if we get here, the versions must match exactly so:
  86      $g_cached_version[$p_version_string] = true;
  87      return true;
  88  }
  89  
  90  # Check for function because it is deprecated in PHP 5.3 and removed in PHP 6
  91  if ( function_exists( 'set_magic_quotes_runtime' ) ) {
  92      @set_magic_quotes_runtime( false );
  93  }
  94  
  95  # Added in PHP 5.2.0
  96  if ( !function_exists( 'memory_get_peak_usage') ) {
  97  	function memory_get_peak_usage() {
  98          return memory_get_usage();
  99      }
 100  }
 101  
 102  # If mb_* not defined, define it to map to standard methods.
 103  if ( !function_exists( 'mb_substr' ) ) {
 104  	function mb_substr( $p_text, $p_index, $p_size ) {
 105          return utf8_substr( $p_text, $p_index, $p_size );
 106      }
 107  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7