Source for file Dependency.php
Documentation is available at Dependency.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// | Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
// THIS FILE IS DEPRECATED IN FAVOR OF DEPENDENCY2.PHP, AND IS NOT USED IN THE INSTALLER
// $Id: Dependency.php,v 1.42 2006/03/26 23:25:56 cellog Exp $
require_once "OS/Guess.php";
define('PEAR_DEPENDENCY_MISSING', -1 );
define('PEAR_DEPENDENCY_CONFLICT', -2 );
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
* The class is based on the dependency RFC that can be found at
* http://cvs.php.net/cvs.php/pearweb/rfc. It requires PHP >= 4.1
* @author Tomas V.V.Vox <cox@idecnet.com>
* @author Stig Bakken <ssb@php.net>
* @param object Registry object
function PEAR_Dependency (&$registry)
$this->registry = &$registry;
* This method maps the XML dependency definition to the
* corresponding one from PEAR_Dependency
* @param string Error message
function callCheckMethod (&$errmsg, $opts)
$rel = isset ($opts['rel']) ? $opts['rel'] : 'has';
$req = isset ($opts['version']) ? $opts['version'] : null;
$name = isset ($opts['name']) ? $opts['name'] : null;
$channel = isset ($opts['channel']) ? $opts['channel'] : 'pear.php.net';
$opt = (isset ($opts['optional']) && $opts['optional'] == 'yes') ?
$opts['optional'] : null;
return $this->checkPackage ($errmsg, $name, $req, $rel, $opt, $channel);
return $this->checkExtension ($errmsg, $name, $req, $rel, $opt);
return $this->checkPHP ($errmsg, $req, $rel);
return $this->checkProgram ($errmsg, $name);
return $this->checkOS ($errmsg, $name);
return $this->checkSAPI ($errmsg, $name);
return $this->checkZend ($errmsg, $name);
return " '{$opts['type']}' dependency type not supported";
* Package dependencies check method
* @param string $errmsg Empty string, it will be populated with an error message, if any
* @param string $name Name of the package to test
* @param string $req The package version required
* @param string $relation How to compare versions with each other
* @param bool $opt Whether the relationship is optional
* @param string $channel Channel name
* @return mixed bool false if no error or the error string
function checkPackage (&$errmsg, $name, $req = null , $relation = 'has',
$opt = false , $channel = 'pear.php.net')
if (!$this->registry->packageExists ($name, $channel)) {
$errmsg = " package `$channel/$name' is recommended to utilize some features.";
$errmsg = " requires package `$channel/$name'";
if ($this->registry->packageExists ($name, $channel)) {
$errmsg = " conflicts with package `$channel/$name'";
$version = $this->registry->packageInfo ($name, 'version', $channel);
if (!$this->registry->packageExists ($name, $channel)
$code = $this->codeFromRelation ($relation, $version, $req, $opt);
$errmsg = " package `$channel/$name' version " . $this->signOperator ($relation) .
" $req is recommended to utilize some features.";
$errmsg .= " Installed version is $version";
$errmsg = " requires package `$channel/$name' " .
$this->signOperator ($relation) . " $req";
$errmsg = " relation '$relation' with requirement '$req' is not supported (name=$channel/$name)";
// {{{ checkPackageUninstall()
* Check package dependencies on uninstall
* @param string $error The resultant error string
* @param string $warning The resultant warning string
* @param string $name Name of the package to test
* @param string $channel Channel name of the package
* @return bool true if there were errors
function checkPackageUninstall (&$error, &$warning, $package, $channel = 'pear.php.net')
$channels = $this->registry->listAllPackages ();
foreach ($channels as $channelname => $packages) {
foreach ($packages as $pkg) {
if ($pkg == $package && $channel == $channelname) {
$deps = $this->registry->packageInfo ($pkg, 'release_deps', $channel);
foreach ($deps as $dep) {
$depchannel = isset ($dep['channel']) ? $dep['channel'] : 'pear.php.net';
if ($dep['type'] == 'pkg' && (strcasecmp($dep['name'], $package) == 0 ) &&
($depchannel == $channel)) {
if ($dep['rel'] == 'ne') {
if (isset ($dep['optional']) && $dep['optional'] == 'yes') {
$warning .= " \nWarning: Package '$depchannel/$pkg' optionally depends on '$channel:/package'";
$error .= " Package '$depchannel/$pkg' depends on '$channel/$package'\n";
return ($error) ? true : false;
* Extension dependencies check method
* @param string $name Name of the extension to test
* @param string $req_ext_ver Required extension version to compare with
* @param string $relation How to compare versions with eachother
* @param bool $opt Whether the relationship is optional
* @return mixed bool false if no error or the error string
function checkExtension (&$errmsg, $name, $req = null , $relation = 'has',
if ($relation == 'not') {
$errmsg = " conflicts with PHP extension '$name'";
$errmsg = " '$name' PHP extension is recommended to utilize some features";
$errmsg = " '$name' PHP extension is not installed";
if ($relation == 'has') {
// Force params to be strings, otherwise the comparation will fail (ex. 0.9==0.90)
$errmsg = " '$name' PHP extension version " .
$this->signOperator ($operator) . " $req is required";
$code = $this->codeFromRelation ($relation, $ext_ver, $req, $opt);
$errmsg = " '$name' PHP extension version " . $this->signOperator ($operator) .
" $req is recommended to utilize some features";
* Operating system dependencies check method
* @param string $os Name of the operating system
* @return mixed bool false if no error or the error string
function checkOS (&$errmsg, $os)
// XXX Fixme: Implement a more flexible way, like
// comma separated values or something similar to PEAR_OS
// only 'has' relation is currently supported
if ($myos->matchSignature ($os)) {
$errmsg = " '$os' operating system not supported";
* PHP version check method
* @param string $req which version to compare
* @param string $relation how to compare the version
* @return mixed bool false if no error or the error string
function checkPHP (&$errmsg, $req, $relation = 'ge')
// this would be a bit stupid, but oh well :)
if ($relation == 'has') {
if ($relation == 'not') {
$errmsg = "Invalid dependency - 'not' is allowed when specifying PHP, you must run PHP in PHP";
if (substr($req, 0 , 2 ) == 'v.') {
$errmsg = "PHP version " . $this->signOperator ($operator) .
* External program check method. Looks for executable files in
* directories listed in the PATH environment variable.
* @param string $program which program to look for
* @return mixed bool false if no error or the error string
function checkProgram (&$errmsg, $program)
// XXX FIXME honor safe mode
foreach ($path_elements as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
$errmsg = " '$program' program is not present in the PATH";
* SAPI backend check method. Version comparison is not yet
* @param string $name name of SAPI backend
* @param string $req which version to compare
* @param string $relation how to compare versions (currently
* @return mixed bool false if no error or the error string
function checkSAPI (&$errmsg, $name, $req = null , $relation = 'has')
// XXX Fixme: There is no way to know if the user has or
// not other SAPI backends installed than the installer one
// Version comparisons not supported, sapi backends don't have
// version information yet.
if ($sapi_backend == $name) {
$errmsg = " '$sapi_backend' SAPI backend not supported";
* Zend version check method
* @param string $req which version to compare
* @param string $relation how to compare the version
* @return mixed bool false if no error or the error string
function checkZend (&$errmsg, $req, $relation = 'ge')
if (substr($req, 0 , 2 ) == 'v.') {
$operator = substr($relation,0 ,2 );
$errmsg = "Zend version " . $this->signOperator ($operator) .
* Converts text comparing operators to them sign equivalents
* @return string Sign equivalent
function signOperator ($operator)
// {{{ codeFromRelation()
* Convert relation into corresponding code
* @param string Requirement
* @param bool Optional dependency indicator
function codeFromRelation ($relation, $version, $req, $opt = false )
case 'gt': case 'ge': case 'eq':
if ($need_major > $have_major) {
case 'lt': case 'le': case 'ne':
Documentation generated on Mon, 11 Mar 2019 15:09:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|