[Patch] Optional dependencies

From: Date: Thu, 15 May 2003 19:43:37 +0000
Subject: [Patch] Optional dependencies
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16325@lists.php.net to get a copy of this message
Attached you'll find a patch against the latest CVS version of the PEAR installer, which implements optional dependencies. This kind of dependency is recognized by the attribute optional="yes" in the <dep> tag. Example: <dep type="pkg" rel="has" optional="yes">DB</dep> indicates that DB is recommended for the package, but mustn't be installed to (at least basically) use it. The patch is pretty small, but review by people being familiar with PEAR/*.php (especially Stig) is appreciated. -- - Martin Martin Jansen http://martinjansen.com/

Index: Installer.php =================================================================== RCS file: /repository/php4/pear/PEAR/Installer.php,v retrieving revision 1.86 diff -u -r1.86 Installer.php --- Installer.php 18 Mar 2003 12:06:06 -0000 1.86 +++ Installer.php 15 May 2003 19:38:22 -0000 @@ -15,6 +15,7 @@ // +----------------------------------------------------------------------+ // | Authors: Stig Bakken <ssb@php.net> | // | Tomas V.V.Cox <cox@idecnet.com> | +// | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // // $Id: Installer.php,v 1.86 2003/03/18 12:06:06 ssb Exp $ @@ -40,6 +41,7 @@ * * @since PHP 4.0.2 * @author Stig Bakken <ssb@php.net> + * @author Martin Jansen <mj@php.net> */ class PEAR_Installer extends PEAR_Common { @@ -599,12 +601,18 @@ // Check dependencies ------------------------------------------- if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) { - $error = $this->checkDeps($pkginfo); - if ($error) { + $dep_errors = ""; + $error = $this->checkDeps($pkginfo, $dep_errors); + if ($error == true) { if (empty($options['soft'])) { - $this->log(0, $error); + $this->log(0, substr($dep_errors, 1)); + } + return $this->raiseError("$pkgname: Dependencies failed"); + } else if ($dep_errors != "") { + // Print optional dependencies + if (empty($options['soft'])) { + $this->log(0, $dep_errors); } - return $this->raiseError("$pkgname: dependencies failed"); } } @@ -784,22 +792,35 @@ // }}} // {{{ checkDeps() - function checkDeps(&$pkginfo) + /** + * Check if the package meets all dependencies + * + * @param array Package information (passed by reference) + * @param string Error message (passed by reference) + * @return boolean False when no error occured, otherwise true + */ + function checkDeps(&$pkginfo, &$errors) { $depchecker = &new PEAR_Dependency($this->registry); $error = $errors = ''; - $failed_deps = array(); + $failed_deps = $optional_deps = array(); if (is_array($pkginfo['release_deps'])) { foreach($pkginfo['release_deps'] as $dep) { $code = $depchecker->callCheckMethod($error, $dep); if ($code) { - $failed_deps[] = array($dep, $code, $error); + if (isset($dep['optional']) && $dep['optional'] == "yes") { + // Ugly hack to adjust the error messages + $error = str_replace("requires ", "", $error); + $error = ucfirst($error); + $error = $error . " is recommended to utilize some features."; + $optional_deps[] = array($dep, $code, $error); + } else { + $failed_deps[] = array($dep, $code, $error); + } } } $n = count($failed_deps); if ($n > 0) { - $depinstaller =& new PEAR_Installer($this->ui); - $to_install = array(); for ($i = 0; $i < $n; $i++) { if (isset($failed_deps[$i]['type'])) { $type = $failed_deps[$i]['type']; @@ -824,7 +845,28 @@ break; } } - return substr($errors, 1); + return true; + } + + $n = count($optional_deps); + if ($n > 0) { + $errors = "Optional dependencies:"; + + for ($i = 0; $i < $n; $i++) { + if (isset($optional_deps[$i]['type'])) { + $type = $optional_deps[$i]['type']; + } else { + $type = 'pkg'; + } + switch ($optional_deps[$i][1]) { + case PEAR_DEPENDENCY_MISSING: + case PEAR_DEPENDENCY_UPGRADE_MINOR: + default: + $errors .= "\n" . $optional_deps[$i][2]; + break; + } + } + return false; } } return false;
« previous php.pear.dev (#16325) next »