mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
* replaced PEAR::phpVersionIs with version_compare
This commit is contained in:
parent
b26fbe41b1
commit
405142087c
@ -491,63 +491,6 @@ class PEAR
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
/**
|
||||
* Converts a php version string to an array
|
||||
* (supported formats are: X.X.X, X.X.X-dev, X.X.XplX)
|
||||
*
|
||||
* @param string $version A valid php version (ie. 4.0.7)
|
||||
* @return array
|
||||
* @see PEAR::phpVersionIs()
|
||||
*/
|
||||
function _explodePHPVersion($version)
|
||||
{
|
||||
@list($version, ) = explode('-', $version); // 4.0.7-dev
|
||||
@list($version, ) = explode('RC', $version); // 4.0.7RC1
|
||||
list($mayor, $minor, $sub) = explode('.', $version);
|
||||
@list($sub, $patch) = explode('pl', $sub); // 4.0.14pl1
|
||||
if ($patch === null) {
|
||||
$patch = 0;
|
||||
}
|
||||
return array($mayor, $minor, $sub, $patch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if a version is minor or greater than a given PHP version
|
||||
* (it should be red as "if my php version is minor|greater|between this one)
|
||||
*
|
||||
* Usage:
|
||||
* PEAR::phpVersionIs('4.0.7') => if the current version
|
||||
* is minor than version 4.0.7
|
||||
* PEAR::phpVersionIs(null, '4.0.12pl3') => if current is greater that 4.0.12pl3
|
||||
* PEAR::phpVersionIs('4.0.9', '4.0.4') => if current is between 4.0.9 and 4.0.4
|
||||
*
|
||||
* @param string $minorthan Version should be minor than this param
|
||||
* @param string $greaterthan Version should be greater than this param
|
||||
* @param string $version Version to compare with (defaults to current)
|
||||
*
|
||||
* @return bool If the comparation was successful or not
|
||||
*/
|
||||
function phpVersionIs($minorthan = null, $greaterthan = null, $version = PHP_VERSION)
|
||||
{
|
||||
$version = PEAR::_explodePHPVersion($version);
|
||||
$ret = false;
|
||||
if ($minorthan) {
|
||||
$minor = PEAR::_explodePHPVersion($minorthan);
|
||||
for ($i=0; $i < count($version)-1 && $minor[$i] == $version[$i]; $i++);
|
||||
if ($version[$i] >= $minor[$i]) {
|
||||
return false;
|
||||
}
|
||||
$ret = true;
|
||||
}
|
||||
if ($greaterthan) {
|
||||
$greater = PEAR::_explodePHPVersion($greaterthan);
|
||||
for ($i=0; $i < count($version)-1 && $greater[$i] == $version[$i]; $i++);
|
||||
$ret = ($version[$i] > $greater[$i]) ? true : false;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// {{{ _PEAR_call_destructors()
|
||||
|
@ -1,65 +0,0 @@
|
||||
--TEST--
|
||||
PEAR::phpVersionIs()
|
||||
--SKIPIF--
|
||||
--FILE--
|
||||
<?php
|
||||
// Test for PEAR::phpVersionIs()
|
||||
|
||||
require_once '../PEAR.php';
|
||||
|
||||
define (PHP_CURRENT_VER, '4.0.7');
|
||||
|
||||
function cmp($param1=null, $param2=null, $expected)
|
||||
{
|
||||
echo PHP_CURRENT_VER;
|
||||
if ($param1) {
|
||||
echo " minor than $param1";
|
||||
}
|
||||
if ($param2) {
|
||||
echo " greater than $param2";
|
||||
}
|
||||
$res = PEAR::phpVersionIs($param1, $param2, PHP_CURRENT_VER);
|
||||
echo " is ";
|
||||
echo ($res) ? "TRUE" : "FALSE";
|
||||
if ($expected === $res) {
|
||||
echo " OK\n";
|
||||
} else {
|
||||
echo " FAIL\n";
|
||||
}
|
||||
}
|
||||
$vers = array(
|
||||
array('4.0.5', null, false),
|
||||
array('4.0.99', null, true),
|
||||
array(PHP_CURRENT_VER, null, false),
|
||||
array('4.0.99pl1', null, true),
|
||||
array('4.0.99RC1', null, true),
|
||||
array('4.0.99-dev', null, true),
|
||||
array(null, '4.0.5', true),
|
||||
array(null, '4.0.99', false),
|
||||
array(null, PHP_CURRENT_VER, false),
|
||||
array('4.0.5', '4.0.99', false),
|
||||
array('4.0.99', '4.0.5', true),
|
||||
array(PHP_CURRENT_VER, '4.0.5', false),
|
||||
array('4.0.99', PHP_CURRENT_VER, false)
|
||||
);
|
||||
|
||||
foreach ($vers as $ver) {
|
||||
cmp($ver[0], $ver[1], $ver[2]);
|
||||
}
|
||||
?>
|
||||
--GET--
|
||||
--POST--
|
||||
--EXPECT--
|
||||
4.0.7 minor than 4.0.5 is FALSE OK
|
||||
4.0.7 minor than 4.0.99 is TRUE OK
|
||||
4.0.7 minor than 4.0.7 is FALSE OK
|
||||
4.0.7 minor than 4.0.99pl1 is TRUE OK
|
||||
4.0.7 minor than 4.0.99RC1 is TRUE OK
|
||||
4.0.7 minor than 4.0.99-dev is TRUE OK
|
||||
4.0.7 greater than 4.0.5 is TRUE OK
|
||||
4.0.7 greater than 4.0.99 is FALSE OK
|
||||
4.0.7 greater than 4.0.7 is FALSE OK
|
||||
4.0.7 minor than 4.0.5 greater than 4.0.99 is FALSE OK
|
||||
4.0.7 minor than 4.0.99 greater than 4.0.5 is TRUE OK
|
||||
4.0.7 minor than 4.0.7 greater than 4.0.5 is FALSE OK
|
||||
4.0.7 minor than 4.0.99 greater than 4.0.7 is FALSE OK
|
Loading…
Reference in New Issue
Block a user