summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas V.V.Cox <cox@php.net>2001-10-04 19:05:09 +0000
committerTomas V.V.Cox <cox@php.net>2001-10-04 19:05:09 +0000
commit0786889de0fd4cba0646ab3ab6b1834afc331484 (patch)
tree0b3c0fb9144128d429d8fa420910bf7490e3aea9
parent27744e892a9a447279c6cea51ca8dc39061d03d9 (diff)
downloadphp-git-0786889de0fd4cba0646ab3ab6b1834afc331484.tar.gz
added method phpVersionIs() to find if a PHP version is minor, greater
or both (see in-line doc for more info)
-rw-r--r--pear/PEAR.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/pear/PEAR.php b/pear/PEAR.php
index 0c6b0f537a..f5bce41577 100644
--- a/pear/PEAR.php
+++ b/pear/PEAR.php
@@ -15,6 +15,8 @@
// +----------------------------------------------------------------------+
// | Authors: Sterling Hughes <sterling@php.net> |
// | Stig Bakken <ssb@fast.no> |
+// | Tomas V.V.Cox <cox@idecnet.com> |
+// | |
// +----------------------------------------------------------------------+
//
// $Id$
@@ -489,6 +491,61 @@ 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($v, ) = explode('-', $version); // 4.0.7-dev
+ list($mayor, $minor, $sub) = explode('.', $v);
+ @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
+ * (useful for dependencies checking).
+ * Usage:
+ * PEAR::phpVersionIs('4.0.7') => if version 4.0.7 if minor than
+ * the current version
+ * PEAR::phpVersionIs(null, '4.0.12pl3') => if version 4.0.12pl3 is greater
+ * PEAR::phpVersionIs('4.0.5', '4.0.7') => if version is between 4.0.5 and 4.0.7
+ *
+ * @param string $minorthan PHP version that should be minor than the given version
+ * @param string $greaterthan PHP version that should be greater
+ * @param string $version The PHP 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 ($minor[$i] >= $version[$i]) {
+ return false;
+ }
+ $ret = true;
+ }
+ if ($greaterthan) {
+ $greater = PEAR::_explodePHPVersion($greaterthan);
+ for ($i=0; $i < count($version)-1 && $greater[$i] == $version[$i]; $i++);
+ $ret = ($greater[$i] > $version[$i]) ? true : false;
+ }
+ return $ret;
+ }
+
}
// {{{ _PEAR_call_destructors()