From 6d0360204d1d14f7c1ce9cbc282a50d66edc3281 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Fri, 31 Oct 2003 22:53:20 +0000 Subject: [PATCH] better error messages, fix potential problems in the future --- pear/PEAR/Dependency.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pear/PEAR/Dependency.php b/pear/PEAR/Dependency.php index 12b2dffaefb..cd625738410 100644 --- a/pear/PEAR/Dependency.php +++ b/pear/PEAR/Dependency.php @@ -27,6 +27,9 @@ define('PEAR_DEPENDENCY_UPGRADE_MINOR', -3); define('PEAR_DEPENDENCY_UPGRADE_MAJOR', -4); define('PEAR_DEPENDENCY_BAD_DEPENDENCY', -5); define('PEAR_DEPENDENCY_MISSING_OPTIONAL', -6); +define('PEAR_DEPENDENCY_CONFLICT_OPTIONAL', -7); +define('PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL', -8); +define('PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL', -9); /** * Dependency check for PEAR packages @@ -156,10 +159,11 @@ class PEAR_Dependency if (!$this->registry->packageExists($name) || !version_compare("$version", "$req", $relation)) { - $code = $this->codeFromRelation($relation, $version, $req); + $code = $this->codeFromRelation($relation, $version, $req, $opt); if ($opt) { - $errmsg = "package `$name' version $req is recommended to utilize some features."; - return PEAR_DEPENDENCY_MISSING_OPTIONAL; + $errmsg = "package `$name' version " . $this->signOperator($relation) . + " $req is recommended to utilize some features. Installed version is $version"; + return $code; } $errmsg = "requires package `$name' " . $this->signOperator($relation) . " $req"; @@ -425,9 +429,10 @@ class PEAR_Dependency * @param string Relation * @param string Version * @param string Requirement + * @param bool Optional dependency indicator * @return integer */ - function codeFromRelation($relation, $version, $req) + function codeFromRelation($relation, $version, $req, $opt = false) { $code = PEAR_DEPENDENCY_BAD_DEPENDENCY; switch ($relation) { @@ -436,13 +441,16 @@ class PEAR_Dependency $have_major = preg_replace('/\D.*/', '', $version); $need_major = preg_replace('/\D.*/', '', $req); if ($need_major > $have_major) { - $code = PEAR_DEPENDENCY_UPGRADE_MAJOR; + $code = $opt ? PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL : + PEAR_DEPENDENCY_UPGRADE_MAJOR; } else { - $code = PEAR_DEPENDENCY_UPGRADE_MINOR; + $code = $opt ? PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL : + PEAR_DEPENDENCY_UPGRADE_MINOR; } break; case 'lt': case 'le': case 'ne': - $code = PEAR_DEPENDENCY_CONFLICT; + $code = $opt ? PEAR_DEPENDENCY_CONFLICT_OPTIONAL : + PEAR_DEPENDENCY_CONFLICT; break; } return $code;