Dotclear


Ignore:
Timestamp:
10/16/13 17:47:56 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
2.6
Message:

Add custom versions comparison, now can install module that required version x.y on a x.y-RC, x.y-dev, etc..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.utils.php

    r1179 r2388  
    7474          return $clean_ids; 
    7575     } 
     76 
     77     /** 
     78      * Compare two versions with option of using only main numbers. 
     79      * 
     80      * @param  string   $current_version    Current version 
     81      * @param  string   $required_version   Required version 
     82      * @param  string   $operator           Comparison operand 
     83      * @param  boolean  $strict                  Use full version 
     84      * @return boolean  True if comparison success 
     85      */ 
     86     public static function versionsCompare($current_version, $required_version, $operator='>=', $strict=true) 
     87     { 
     88          if ($strict) { 
     89               $current_version = preg_replace('!-r(\d+)$!', '-p$1', $current_version); 
     90               $required_version = preg_replace('!-r(\d+)$!', '-p$1', $required_version); 
     91          } 
     92          else { 
     93               $current_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $current_version); 
     94               $required_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $required_version); 
     95          } 
     96 
     97          return (boolean) version_compare($current_version, $required_version, $operator); 
     98     } 
    7699} 
    77100 
Note: See TracChangeset for help on using the changeset viewer.

Sites map