[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> Version.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  include_once ('vtigerversion.php');
  11  
  12  /**
  13   * Provides utility APIs to work with Vtiger Version detection
  14   * @package vtlib
  15   */
  16  class Vtiger_Version {
  17  
  18      /**
  19       * Get current version of vtiger in use.
  20       */
  21  	static function current() {
  22          global $vtiger_current_version;
  23          return $vtiger_current_version;
  24      }
  25  
  26      /**
  27       * Check current version of vtiger with given version
  28       * @param String Version against which comparision to be done
  29       * @param String Condition like ( '=', '!=', '<', '<=', '>', '>=')
  30       */
  31  	static function check($with_version, $condition='=') {
  32          $current_version = self::current();
  33          //xml node is passed to this method sometimes
  34          if(!is_string($with_version)) {
  35              $with_version = (string) $with_version;
  36          }
  37          $with_version = self::getUpperLimitVersion($with_version);
  38          return version_compare($current_version, $with_version, $condition);
  39      }
  40      
  41  	static function endsWith($string, $endString) {
  42          $strLen = strlen($string);
  43          $endStrLen = strlen($endString);
  44          if ($endStrLen > $strLen) return false;
  45          return substr_compare($string, $endString, -$endStrLen) === 0;        
  46      }
  47      
  48  	static function getUpperLimitVersion($version) {
  49          if(!self::endsWith($version, '.*')) return $version;
  50          
  51          $version = rtrim($version, '.*');
  52          $lastVersionPartIndex = strrpos($version, '.');
  53          if ($lastVersionPartIndex === false) {
  54              $version = ((int) $version) + 1;    
  55          } else {
  56              $lastVersionPart = substr($version, $lastVersionPartIndex+1, strlen($version));
  57              $upgradedVersionPart = ((int) $lastVersionPart) + 1;
  58              $version = substr($version, 0, $lastVersionPartIndex+1) . $upgradedVersionPart;
  59          }
  60          return $version;
  61      }
  62  }
  63  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1