diff options
author | Stig Bakken <ssb@php.net> | 2001-10-11 22:11:34 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 2001-10-11 22:11:34 +0000 |
commit | 405142087ca9f49f6f480e29541bb3fe05847fe8 (patch) | |
tree | c84afd0ac0031427f16272ec3a308805f3fc577d | |
parent | b26fbe41b188b2b6c65a175faa1abb84417d8a1a (diff) | |
download | php-git-405142087ca9f49f6f480e29541bb3fe05847fe8.tar.gz |
* replaced PEAR::phpVersionIs with version_compare
-rw-r--r-- | pear/PEAR.php | 57 | ||||
-rw-r--r-- | pear/tests/pear_versioncmp.phpt | 65 |
2 files changed, 0 insertions, 122 deletions
diff --git a/pear/PEAR.php b/pear/PEAR.php index 950433b89b..19412b0f0e 100644 --- a/pear/PEAR.php +++ b/pear/PEAR.php @@ -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() diff --git a/pear/tests/pear_versioncmp.phpt b/pear/tests/pear_versioncmp.phpt deleted file mode 100644 index 4611623d52..0000000000 --- a/pear/tests/pear_versioncmp.phpt +++ /dev/null @@ -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 |