2001-12-02 08:44:02 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
// | PHP Version 4 |
|
2001-12-02 08:44:02 +08:00
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
// | Copyright (c) 1997-2002 The PHP Group |
|
2001-12-02 08:44:02 +08:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
// | available at through the world-wide-web at |
|
|
|
|
// | http://www.php.net/license/2_02.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@fast.no> |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Methods for dependencies check. Based on Stig's dependencies RFC
|
|
|
|
* at http://cvs.php.net/cvs.php/pearweb/rfc
|
|
|
|
* (requires php >= 4.1)
|
|
|
|
*/
|
|
|
|
|
2001-12-11 00:59:17 +08:00
|
|
|
require_once "PEAR.php";
|
|
|
|
|
2001-12-03 00:29:37 +08:00
|
|
|
class PEAR_Dependency
|
2001-12-02 08:44:02 +08:00
|
|
|
{
|
2002-04-09 22:12:12 +08:00
|
|
|
function PEAR_Dependency(&$registry)
|
|
|
|
{
|
|
|
|
$this->registry = &$registry;
|
|
|
|
}
|
2001-12-18 05:08:58 +08:00
|
|
|
/**
|
|
|
|
* This method maps the xml dependency definition to the
|
|
|
|
* PEAR_dependecy one
|
|
|
|
*
|
|
|
|
* $opts => Array
|
|
|
|
* (
|
|
|
|
* [type] => pkg
|
|
|
|
* [rel] => ge
|
|
|
|
* [version] => 3.4
|
|
|
|
* [name] => HTML_Common
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
function callCheckMethod($opts)
|
|
|
|
{
|
|
|
|
$rel = isset($opts['rel']) ? $opts['rel'] : 'has';
|
|
|
|
if (isset($opts['version'])) {
|
|
|
|
$req = $opts['version'];
|
|
|
|
$rel = 'v.' . $rel;
|
|
|
|
} else {
|
|
|
|
$req = null;
|
|
|
|
}
|
|
|
|
$name = isset($opts['name']) ? $opts['name'] : null;
|
|
|
|
switch ($opts['type']) {
|
|
|
|
case 'pkg':
|
|
|
|
return $this->checkPackage($name, $req, $rel);
|
|
|
|
break;
|
|
|
|
case 'ext':
|
|
|
|
return $this->checkExtension($name, $req, $rel);
|
|
|
|
break;
|
|
|
|
case 'php':
|
|
|
|
return $this->checkPHP($req, $rel);
|
|
|
|
break;
|
|
|
|
case 'prog':
|
|
|
|
return $this->checkProgram($name);
|
|
|
|
break;
|
|
|
|
case 'os':
|
|
|
|
return $this->checkOS($name);
|
|
|
|
break;
|
|
|
|
case 'sapi':
|
|
|
|
return $this->checkSAPI($name);
|
|
|
|
break;
|
|
|
|
default:
|
2002-05-12 22:53:54 +08:00
|
|
|
return "'{$opts['type']}' dependency type not supported";
|
2001-12-18 05:08:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-02 08:44:02 +08:00
|
|
|
/**
|
2001-12-11 00:59:17 +08:00
|
|
|
* Package dependencies check method
|
|
|
|
*
|
|
|
|
* @param string $name Name of the package to test
|
|
|
|
* @param string $version The package version required
|
|
|
|
* @param string $relation How to compare versions with eachother
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
2001-12-18 05:08:58 +08:00
|
|
|
function checkPackage($name, $req = null, $relation = 'has')
|
2001-12-02 08:44:02 +08:00
|
|
|
{
|
2002-05-20 00:32:18 +08:00
|
|
|
if (substr($relation, 0, 2) == "v.") {
|
|
|
|
$relation = substr($relation, 2);
|
|
|
|
}
|
2002-05-12 22:53:54 +08:00
|
|
|
switch ($relation) {
|
|
|
|
case 'has':
|
|
|
|
if (!$this->registry->packageExists($name)) {
|
|
|
|
return "requires package `$name'";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case 'not':
|
|
|
|
if (!$this->registry->packageExists($name)) {
|
|
|
|
return "conflicts with package `$name'";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case 'lt':
|
|
|
|
case 'le':
|
|
|
|
case 'eq':
|
|
|
|
case 'ne':
|
|
|
|
case 'ge':
|
|
|
|
case 'gt':
|
|
|
|
$version = $this->registry->packageInfo($name, 'version');
|
2002-05-22 09:23:12 +08:00
|
|
|
if (!$this->registry->packageExists($name)
|
|
|
|
|| !version_compare($version, $req, $relation))
|
|
|
|
{
|
2002-05-12 22:53:54 +08:00
|
|
|
return "requires package `$name' " .
|
2002-05-22 09:23:12 +08:00
|
|
|
$this->signOperator($relation) . " $req";
|
2002-05-12 22:53:54 +08:00
|
|
|
}
|
2002-05-24 04:37:58 +08:00
|
|
|
return false;
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
2002-05-12 22:53:54 +08:00
|
|
|
return "Relation '$relation' with requirement '$req' is not supported (name=$name)";
|
2001-12-02 08:44:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-12-11 00:59:17 +08:00
|
|
|
* 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
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
2001-12-18 05:08:58 +08:00
|
|
|
function checkExtension($name, $req = null, $relation = 'has')
|
2001-12-02 08:44:02 +08:00
|
|
|
{
|
2001-12-11 00:59:17 +08:00
|
|
|
// XXX (ssb): could we avoid loading the extension here?
|
2001-12-02 08:44:02 +08:00
|
|
|
if (!extension_loaded($name)) {
|
|
|
|
$dlext = OS_WINDOWS ? '.dll' : '.so';
|
|
|
|
if (!@dl($name . $dlext)) {
|
2001-12-18 05:08:58 +08:00
|
|
|
return "'$name' PHP extension is not installed";
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($relation == 'has') {
|
2001-12-18 05:08:58 +08:00
|
|
|
return false;
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
|
|
|
if (substr($relation, 0, 2) == 'v.') {
|
2001-12-18 05:08:58 +08:00
|
|
|
$ext_ver = phpversion($name);
|
2001-12-11 00:59:17 +08:00
|
|
|
$operator = substr($relation, 2);
|
2001-12-18 05:08:58 +08:00
|
|
|
if (!version_compare($ext_ver, $req, $operator)) {
|
|
|
|
return "'$name' PHP extension version " .
|
|
|
|
$this->signOperator($operator) . " $req is required";
|
|
|
|
}
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Operating system dependencies check method
|
|
|
|
*
|
|
|
|
* @param string $os Name of the operating system
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
|
|
|
function checkOS($os)
|
|
|
|
{
|
2001-12-18 05:08:58 +08:00
|
|
|
// XXX Fixme: Implement a more flexible way, like
|
|
|
|
// comma separated values or something similar to PEAR_OS
|
|
|
|
|
2001-12-11 00:59:17 +08:00
|
|
|
// only 'has' relation is supported
|
2001-12-18 05:08:58 +08:00
|
|
|
if ($os == PHP_OS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return "'$os' operating system not supported";
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version check method
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @param string $req which version to compare
|
2001-12-11 00:59:17 +08:00
|
|
|
* @param string $relation how to compare the version
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
2001-12-18 05:08:58 +08:00
|
|
|
function checkPHP($req, $relation = 'v.ge')
|
2001-12-11 00:59:17 +08:00
|
|
|
{
|
|
|
|
if (substr($relation, 0, 2) == 'v.') {
|
2001-12-18 05:08:58 +08:00
|
|
|
$php_ver = phpversion();
|
2001-12-11 00:59:17 +08:00
|
|
|
$operator = substr($relation, 2);
|
2001-12-18 05:08:58 +08:00
|
|
|
if (!version_compare($php_ver, $req, $operator)) {
|
|
|
|
return "PHP version " . $this->signOperator($operator) .
|
|
|
|
" $req is required";
|
|
|
|
}
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
2001-12-18 05:08:58 +08:00
|
|
|
return false;
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External program check method. Looks for executable files in
|
|
|
|
* directories listed in the PATH environment variable.
|
|
|
|
*
|
|
|
|
* @param string $program which program to look for
|
|
|
|
*
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
|
|
|
function checkProgram($program)
|
|
|
|
{
|
|
|
|
// XXX FIXME honor safe mode
|
|
|
|
$path_delim = OS_WINDOWS ? ';' : ':';
|
|
|
|
$exe_suffix = OS_WINDOWS ? '.exe' : '';
|
2001-12-18 05:08:58 +08:00
|
|
|
$path_elements = explode($path_delim, getenv('PATH'));
|
2001-12-11 00:59:17 +08:00
|
|
|
foreach ($path_elements as $dir) {
|
2001-12-18 05:08:58 +08:00
|
|
|
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
|
|
|
|
if (@file_exists($file) && @is_executable($file)) {
|
|
|
|
return false;
|
2001-12-02 08:44:02 +08:00
|
|
|
}
|
|
|
|
}
|
2001-12-18 05:08:58 +08:00
|
|
|
return "'$program' program is not present in the PATH";
|
2001-12-02 08:44:02 +08:00
|
|
|
}
|
|
|
|
|
2001-12-11 00:59:17 +08:00
|
|
|
/**
|
|
|
|
* SAPI backend check method. Version comparison is not yet
|
|
|
|
* available here.
|
|
|
|
*
|
|
|
|
* @param string $name name of SAPI backend
|
2001-12-18 05:08:58 +08:00
|
|
|
* @param string $req which version to compare
|
2001-12-11 00:59:17 +08:00
|
|
|
* @param string $relation how to compare versions (currently
|
|
|
|
* hardcoded to 'has')
|
2001-12-18 05:08:58 +08:00
|
|
|
* @return mixed bool false if no error or the error string
|
2001-12-11 00:59:17 +08:00
|
|
|
*/
|
2001-12-18 05:08:58 +08:00
|
|
|
function checkSAPI($name, $req = null, $relation = 'has')
|
2001-12-11 00:59:17 +08:00
|
|
|
{
|
2001-12-18 05:08:58 +08:00
|
|
|
// XXX Fixme: There is no way to know if the user has or
|
|
|
|
// not other SAPI backends installed than the installer one
|
|
|
|
|
2001-12-11 00:59:17 +08:00
|
|
|
$sapi_backend = php_sapi_name();
|
|
|
|
// Version comparisons not supported, sapi backends don't have
|
|
|
|
// version information yet.
|
2001-12-18 05:08:58 +08:00
|
|
|
if ($sapi_backend == $name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return "'$sapi_backend' SAPI backend not supported";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts text comparing operators to them sign equivalents
|
|
|
|
* ex: 'ge' to '>='
|
|
|
|
*/
|
|
|
|
function signOperator($operator)
|
|
|
|
{
|
|
|
|
switch($operator) {
|
|
|
|
case 'lt': return '<';
|
|
|
|
case 'le': return '<=';
|
|
|
|
case 'gt': return '>';
|
|
|
|
case 'ge': return '>=';
|
|
|
|
case 'eq': return '==';
|
|
|
|
case 'ne': return '!=';
|
|
|
|
default:
|
|
|
|
return $operator;
|
|
|
|
}
|
2001-12-11 00:59:17 +08:00
|
|
|
}
|
2001-12-02 08:44:02 +08:00
|
|
|
}
|
|
|
|
|
2002-05-20 00:32:18 +08:00
|
|
|
?>
|