diff options
author | SVN Migration <svn@php.net> | 2001-11-13 01:06:49 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2001-11-13 01:06:49 +0000 |
commit | 07156d5fc531b9308da215d459607c752b1b4397 (patch) | |
tree | f283cde00ae1478677a98c9def2e48ef0270f969 | |
parent | dd96ef8151333c12691d72b95cb87063e5a3fc56 (diff) | |
download | php-git-07156d5fc531b9308da215d459607c752b1b4397.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PHP_4_0_7'.
-rw-r--r-- | pear/PEAR/Config.php | 222 | ||||
-rw-r--r-- | pear/PEAR/Registry.php | 176 | ||||
-rw-r--r-- | pear/PEAR/Remote.php | 102 | ||||
-rw-r--r-- | pear/System.php | 286 | ||||
-rw-r--r-- | pear/scripts/pearwin.php | 118 | ||||
-rw-r--r-- | pear/tests/pear_config.phpt | 72 | ||||
-rw-r--r-- | pear/tests/pear_error4.phpt | 89 | ||||
-rw-r--r-- | pear/tests/pear_registry.phpt | 92 | ||||
-rw-r--r-- | pear/tests/system.input | 1 | ||||
-rw-r--r-- | pear/tests/user.input | 0 |
10 files changed, 1158 insertions, 0 deletions
diff --git a/pear/PEAR/Config.php b/pear/PEAR/Config.php new file mode 100644 index 0000000000..f32097fedc --- /dev/null +++ b/pear/PEAR/Config.php @@ -0,0 +1,222 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | 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: Stig Bakken <ssb@fast.no> | +// | | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once 'PEAR.php'; + +/** + * This is a class for storing simple configuration values keeping + * track of which are system-defined (defaulted) and which are + * user-defined. By default, only user-defined settings are stored + * back to the user's configuration file. + * + * Configuration member is a simple associative array. Used keys: + * + * master_server which server to query for mirror lists etc. + * server which server/mirror we're currently using + * username PEAR username + * password PEAR password (stored base64-encoded) + * php_dir Where to install .php files + * ext_dir Directory to install compiled libs in + * doc_dir Directory to install documentation in + * + */ +class PEAR_Config extends PEAR +{ + // {{{ properties + + var $defaults_file = ''; + + var $config_file = ''; + + var $configuration = array(); + + var $defaulted = array(); + + // }}} + + // {{{ PEAR_Config([file], [defaults_file]) + + function PEAR_Config($file = '', $defaults_file = '') + { + $this->PEAR(); + $this->config_file = $file; + $this->defaults_file = $defaults_file; + if ($file && file_exists($file)) { + $this->readConfigFile($file); + } + if ($defaults_file && file_exists($defaults_file)) { + $this->mergeConfigFile($defaults_file, false, true); + } + } + + // }}} + + // {{{ readConfigFile([file], [defaults]) + + function readConfigFile($file = null, $defaults = false) + { + if ($file === null) { + $file = $this->config_file; + } + $fp = @fopen($file, "r"); + if (!$fp) { + return $this->raiseError($php_errormsg); + } + $size = filesize($file); + $contents = fread($fp, $size); + $data = unserialize($contents); + if ($data === false && $size > 1) { + return $this->raiseError("PEAR_Config::readConfigFile: bad data"); + } + $this->configuration = $data; + if ($defaults) { + foreach ($data as $key => $value) { + $this->defaulted[$key] = true; + } + } + } + + // }}} + // {{{ mergeConfigFile(file, [override], [defaults]) + + function mergeConfigFile($file, $override = true, $defaults = false) + { + $fp = @fopen($file, "r"); + if (!$fp) { + return $this->raiseError($php_errormsg); + } + $contents = fread($fp, filesize($file)); + $data = unserialize($contents); + if ($data === false) { + return $this->raiseError("PEAR_Config::mergeConfigFile: bad data"); + } + foreach ($data as $key => $value) { + if (isset($this->configuration[$key]) && !$override) { + continue; + } + if ($defaults) { + $this->defaulted[$key] = true; + } + $this->configuration[$key] = $value; + } + } + + // }}} + // {{{ writeConfigFile([file], [what_keys]) + + function writeConfigFile($file = null, $what_keys = 'userdefined') + { + if ($what_keys == 'both') { + $this->writeConfigFile($file, 'userdefined'); + $this->writeConfigFile($file, 'default'); + return; + } + if ($file === null) { + if ($what_keys == 'default') { + $file = $this->defaults_file; + } else { + $file = $this->config_file; + } + } + if ($what_keys == 'default') { + $keys_to_store = array_intersect(array_keys($this->configuration), + array_keys($this->defaulted)); + } elseif ($what_keys == 'all') { + $keys_to_store = array_keys($this->configuration); + } else { // user-defined keys + $keys_to_store = array_diff(array_keys($this->configuration), + array_keys($this->defaulted)); + } + $data = array(); + foreach ($keys_to_store as $key) { + $data[$key] = $this->configuration[$key]; + } + $fp = @fopen($file, "w"); + if (!$fp) { + return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed"); + } + if (!@fwrite($fp, serialize($data))) { + return $this->raiseError("PEAR_Config::writeConfigFile serialize failed"); + } + return true; + } + + // }}} + // {{{ get(key) + + function get($key) + { + return @$this->configuration[$key]; + } + + // }}} + // {{{ set(key, value, [default]) + + function set($key, $value, $default = false) + { + $this->configuration[$key] = $value; + if ($default) { + $this->defaulted[$key] = true; + } elseif (isset($this->defaulted[$key])) { + unset($this->defaulted[$key]); + } + } + + // }}} + // {{{ getKeys() + + function getKeys() + { + return array_keys($this->configuration); + } + + // }}} + // {{{ toDefault(key) + + function toDefault($key) + { + if (file_exists($this->defaults_file)) { + // re-reads the defaults file each time, but hey it works + unset($this->configuration[$key]); + $this->mergeConfigFile($this->defaults_file, false, true); + } + } + + // }}} + // {{{ isDefaulted(key) + + function isDefaulted($key) + { + return isset($this->defaulted[$key]); + } + + // }}} + // {{{ isDefined(key) + + function isDefined($key) + { + return isset($this->configuration[$key]); + } + + // }}} +} + +?>
\ No newline at end of file diff --git a/pear/PEAR/Registry.php b/pear/PEAR/Registry.php new file mode 100644 index 0000000000..c117cb0a9f --- /dev/null +++ b/pear/PEAR/Registry.php @@ -0,0 +1,176 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | 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: Stig Bakken <ssb@fast.no> | +// | | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once "System.php"; + +/** + * Administration class used to maintain the installed package database. + */ +class PEAR_Registry +{ + // {{{ properties + + var $statedir; + + // }}} + + // {{{ PEAR_Registry + + function PEAR_Registry() + { + $this->statedir = PEAR_INSTALL_DIR . "/.registry"; + } + + // }}} + + // {{{ _assertStateDir() + + function _assertStateDir() + { + if (!@is_dir($this->statedir)) { + System::mkdir("-p {$this->statedir}"); + } + } + + // }}} + // {{{ _packageFileName() + + function _packageFileName($package) + { + return "{$this->statedir}/{$package}.reg"; + } + + // }}} + // {{{ _openPackageFile() + + function _openPackageFile($package, $mode) + { + $this->_assertStateDir(); + $file = $this->_packageFileName($package); + $fp = @fopen($file, $mode); + if (!$fp) { + return null; + } + return $fp; + } + + // }}} + // {{{ _closePackageFile() + + function _closePackageFile($fp) + { + fclose($fp); + } + + // }}} + + // {{{ packageExists() + + function packageExists($package) + { + return file_exists($this->_packageFileName($package)); + } + + // }}} + // {{{ addPackage() + + function addPackage($package, $info) + { + if ($this->packageExists($package)) { + return false; + } + $fp = $this->_openPackageFile($package, "w"); + if ($fp === null) { + return false; + } + fwrite($fp, serialize($info)); + $this->_closePackageFile($fp); + return true; + } + + // }}} + // {{{ packageInfo() + + function packageInfo($package = null) + { + if ($package === null) { + return array_map(array($this, "packageInfo"), + $this->listPackages()); + } + $fp = $this->_openPackageFile($package, "r"); + if ($fp === null) { + return null; + } + $data = fread($fp, filesize($this->_packageFileName($package))); + $this->_closePackageFile($fp); + return unserialize($data); + } + + // }}} + // {{{ deletePackage() + + function deletePackage($package) + { + $file = $this->_packageFileName($package); + return @unlink($file); + } + + // }}} + // {{{ updatePackage() + + function updatePackage($package, $info) + { + $oldinfo = $this->packageInfo($package); + if (empty($oldinfo)) { + return false; + } + $fp = $this->_openPackageFile($package, "w"); + if ($fp === null) { + return false; + } + fwrite($fp, serialize(array_merge($oldinfo, $info))); + $this->_closePackageFile($fp); + return true; + } + + // }}} + // {{{ listPackages() + + function listPackages() + { + $pkglist = array(); + $dp = @opendir($this->statedir); + if (!$dp) { + return $pkglist; + } + while ($ent = readdir($dp)) { + if ($ent{0} == "." || substr($ent, -4) != ".reg") { + continue; + } + $pkglist[] = substr($ent, 0, -4); + } + return $pkglist; + } + + // }}} +} + +?>
\ No newline at end of file diff --git a/pear/PEAR/Remote.php b/pear/PEAR/Remote.php new file mode 100644 index 0000000000..920c2d68aa --- /dev/null +++ b/pear/PEAR/Remote.php @@ -0,0 +1,102 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | 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: Stig Bakken <ssb@fast.no> | +// | | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once 'PEAR.php'; + +/** + * This is a class for doing remote operations against the central + * PEAR database. + */ +class PEAR_Remote extends PEAR +{ + // {{{ properties + + var $config_object = null; + + // }}} + + // {{{ PEAR_Remote(config_object) + + function PEAR_Remote($config_object) + { + $this->PEAR(); + $this->config_object = $config_object; + } + + // }}} + + // {{{ call(method, [args...]) + + function call($method) + { + if (!extension_loaded("xmlrpc")) { + return $this->raiseError("xmlrpc support not loaded"); + } + $params = array_slice(func_get_args(), 1); + $request = xmlrpc_encode_request($method, $params); + $server_host = $this->config_object->get("master_server"); + if (empty($server_host)) { + return $this->raiseError("PEAR_Remote::call: no master_server configured"); + } + $server_port = 80; + $fp = @fsockopen($server_host, $server_port); + if (!$fp) { + return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host', $server_port) failed"); + } + $len = strlen($request); + fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n". + "Host: $server_host:$server_port\r\n". + "Content-type: text/xml\r\n". + "Content-length: $len\r\n". + "\r\n$request")); + $response = ''; + while (trim(fgets($fp, 2048)) != ''); // skip headers + while ($chunk = fread($fp, 10240)) { + $response .= $chunk; + } + fclose($fp); + $ret = xmlrpc_decode($response); + if (is_array($ret) && isset($ret['__PEAR_TYPE__'])) { + if ($ret['__PEAR_TYPE__'] == 'error') { + if (isset($ret['__PEAR_CLASS__'])) { + $class = $ret['__PEAR_CLASS__']; + } else { + $class = "PEAR_Error"; + } + if ($ret['code'] === '') $ret['code'] = null; + if ($ret['message'] === '') $ret['message'] = null; + if ($ret['userinfo'] === '') $ret['userinfo'] = null; + if (strtolower($class) == 'db_error') { + return $this->raiseError(DB::errorMessage($ret['code']), + $ret['code'], null, null, + $ret['userinfo']); + } else { + return $this->raiseError($ret['message'], $ret['code'], + null, null, $ret['userinfo']); + } + } + } + } + + // }}} +} + +?>
\ No newline at end of file diff --git a/pear/System.php b/pear/System.php new file mode 100644 index 0000000000..841e00b368 --- /dev/null +++ b/pear/System.php @@ -0,0 +1,286 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 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> | +// | | +// +----------------------------------------------------------------------+ +// +// $Id$ +// + +// TODO: +// - Test under Windows (help is really appreciated in this point) +// - Build strong tests +// - Error reporting (now shows standar php errors) +// - Write doc + +require_once 'PEAR.php'; +require_once 'Console/Getopt.php'; + +/** +* System offers cross plattform compatible system functions +* +* Static functions for different operations. Should work under +* Unix and Windows. The names and usage has been taken from its repectively +* GNU commands. +* +* Usage: System::rm('-r file1 dir1'); +* +* ------------------- EXPERIMENTAL STATUS ------------------- +* +* @package System +* @author Tomas V.V.Cox <cox@idecnet.com> +* @version $Version$ +* @access public +*/ +class System extends PEAR +{ + /** + * returns the commandline arguments of a function + * + * @param string $argv the commandline + * @param string $short_options the allowed option short-tags + * @param string $long_options the allowed option long-tags + * @return array the given options and there values + * @access private + */ + function _parseArgs($argv, $short_options, $long_options = null) + { + if (!is_array($argv)) { + $argv = preg_split('/\s+/', $argv); + } + $options = Console_Getopt::getopt($argv, $short_options); + return $options; + } + + /** + * Creates a nested array representing the structure of a directory + * + * System::_dirToStruct('dir1', 0) => + * Array + * ( + * [dirs] => Array + * ( + * [0] => dir1 + * ) + * + * [files] => Array + * ( + * [0] => dir1/file2 + * [1] => dir1/file3 + * ) + * ) + * @param string $sPath Name of the directory + * @param integer $maxinst max. deep of the lookup + * @param integer $aktinst starting deep of the lookup + * @return array the structure of the dir + * @access private + */ + + function _dirToStruct($sPath, $maxinst, $aktinst = 0) + { + $struct = array('dirs' => array(), 'files' => array()); + if (($dir = @opendir($sPath)) === false) { + return $struct; // XXX could not open error + } + $struct['dirs'][] = $sPath; // XXX don't add if '.' or '..' ? + $list = array(); + while ($file = readdir($dir)) { + if ($file != '.' && $file != '..') { + $list[] = $file; + } + } + closedir($dir); + sort($list); + foreach($list as $val) { + $path = $sPath . DIRECTORY_SEPARATOR . $val; + if (is_dir($path)) { + if ($aktinst < $maxinst || $maxinst == 0) { + $tmp = System::_dirToStruct($path, $maxinst, $aktinst+1); + $struct = array_merge_recursive($tmp, $struct); + } + } else { + $struct['files'][] = $path; + } + } + return $struct; + } + + /** + * Creates a nested array representing the structure of a directory and files + * + * @param array $files Array listing files and dirs + * @return array + * @see System::_dirToStruct() + */ + function _multipleToStruct($files) + { + $struct = array('dirs' => array(), 'files' => array()); + foreach($files as $file) { + if (is_dir($file)) { + $tmp = System::_dirToStruct($file, 0); + $struct = array_merge_recursive($tmp, $struct); + } else { + $struct['files'][] = $file; + } + } + return $struct; + } + + /** + * The rm command for removing files. + * Supports multiple files and dirs and also recursive deletes + * + * @param string $args the arguments for rm + * @return mixed PEAR_Error or true for success + * @access public + */ + function rm($args) + { + $opts = System::_parseArgs($args, 'rf'); // "f" do nothing but like it :-) + if (PEAR::isError($opts)) { + return $opts; + } + foreach($opts[0] as $opt) { + if ($opt[0] == 'r') { + $do_recursive = true; + } + } + if (isset($do_recursive)) { + $struct = System::_multipleToStruct($opts[1]); + if (PEAR::isError($struct)) { + return $struct; + } + foreach($struct['files'] as $file) { + unlink($file); // XXXX Works under Windows? + } + foreach($struct['dirs'] as $dir) { + rmdir($dir); + } + } else { + foreach ($opts[1] as $file) { + $delete = (is_dir($file)) ? 'rmdir' : 'unlink'; // XXXX Windows? + $delete($file); + } + } + return true; + } + + /** + * Make directories + * + * @param string $args the name of the director(y|ies) to create + * @return mixed PEAR_Error or true for success + * @access public + */ + function mkDir($args) + { + $opts = System::_parseArgs($args, 'pm:'); + if (PEAR::isError($opts)) { + return $opts; + } + $mode = 0777; // default mode + foreach($opts[0] as $opt) { + if ($opt[0] == 'p') { + $create_parents = true; + } elseif($opt[0] == 'm') { + $mode = $opt[1]; + } + } + if (isset($create_parents)) { + foreach($opts[1] as $dir) { + $dirstack = array(); + while (!@is_dir($dir) && $dir != DIRECTORY_SEPARATOR) { + array_unshift($dirstack, $dir); + $dir = dirname($dir); + } + while ($newdir = array_shift($dirstack)) { + if (!mkdir($newdir, $mode)) { + break; // XXX error + } + } + } + } else { + foreach($opts[1] as $dir) { + if (!mkdir($dir, $mode)) { + continue; // XXX error + } + } + } + return true; + } + + /** + * Concatenate files + * + * Usage: + * 1) $var = System::cat('sample.txt test.txt'); + * 2) System::cat('sample.txt test.txt > final.txt'); + * 3) System::cat('sample.txt test.txt >> final.txt'); + * + * Note: as the class use fopen, urls should work also (test that) + * + * @param string $args the arguments + * @return boolean true on success + * @access public + */ + function &cat($args) + { + $ret = null; + $files = array(); + if (!is_array($args)) { + $args = preg_split('/\s+/', $args); + } + for($i=0; $i < count($args); $i++) { + if ($args[$i] == '>') { + $mode = 'wb'; + $outputfile = $args[$i+1]; + break; + } elseif ($args[$i] == '>>') { + $mode = 'ab+'; + $outputfile = $args[$i+1]; + break; + } else { + $files[] = $args[$i]; + } + } + if (isset($mode)) { + if (!$outputfd = fopen($outputfile, $mode)) { + return $this->raiseError("Could not open $outputfile"); + } + $ret = true; + } + foreach($files as $file) { + if (!$fd = fopen($file, 'r')) { + return $this->raiseError("Could not open $file"); + } + while(!feof($fd)) { + $cont = fread($fd, 2048); + if (isset($outputfd)) { + fwrite($outputfd, $cont); + } else { + $ret .= $cont; + } + } + fclose($fd); + } + if (@is_resource($outputfd)) { + fclose($outputfd); + } + return $ret; + } + +} +?>
\ No newline at end of file diff --git a/pear/scripts/pearwin.php b/pear/scripts/pearwin.php new file mode 100644 index 0000000000..2e56d4f77f --- /dev/null +++ b/pear/scripts/pearwin.php @@ -0,0 +1,118 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | 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: Stig Bakken <ssb@fast.no> | +// | Tomas V.V.Cox <cox@idecnet.com> | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once 'PEAR.php'; +require_once 'Console/Getopt.php'; + +error_reporting(E_ALL ^ E_NOTICE); + +$options = Console_Getopt::getopt($argv, "h?v:e:p:d:"); +if (PEAR::isError($options)) { + usage($options); +} + +$opts = $options[0]; +foreach ($opts as $opt) { + $param = $opt[1]; + switch ($opt[0]) { + case 'v': + $verbose = $param; + break; + case 'e': + if ($param{0} != getenv('DIRECTORY_SEPARATOR')) { + usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n")); + } + $ext_dir = $param; + break; + case 'p': + if ($param{0} != getenv('DIRECTORY_SEPARATOR')) { + usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n")); + } + $script_dir = $param; + break; + case 'd': + if ($param{0} != getenv('DIRECTORY_SEPARATOR')) { + usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n")); + } + $doc_dir = $param; + break; + } +} + +$verbose = (isset($verbose)) ? $verbose : 1; +$script_dir = (isset($script_dir)) ? $script_dir : getenv('PEAR_INSTALL_DIR'); +$ext_dir = (isset($ext_dir)) ? $ext_dir : getenv('PEAR_EXTENSION_DIR'); +$doc_dir = (isset($doc_dir)) ? $doc_dir : ''; + +PEAR::setErrorHandling(PEAR_ERROR_PRINT); +$command = $options[1][1]; + +switch ($command) { + case 'install': + include_once 'PEAR/Installer.php'; + $package = $options[1][2]; + $installer =& new PEAR_Installer($script_dir, $ext_dir, $doc_dir); + $installer->debug = $verbose; + if (PEAR::isError($installer->Install($package))) { + print "\ninstall failed\n"; + } else { + print "install ok\n"; + } + break; + case 'package': + include_once 'PEAR/Packager.php'; + $pkginfofile = $options[1][2]; + $packager =& new PEAR_Packager($script_dir, $ext_dir, $doc_dir); + $packager->debug = $verbose; + if (PEAR::isError($packager->Package($pkginfofile))) { + print "\npackage failed\n"; + } else { + print "package ok\n"; + } + break; + default: + usage(); + break; +} + +function usage($obj = null) +{ + $stderr = fopen('php://stderr', 'w'); + if ($obj !== null) { + fputs($stderr, $obj->getMessage()); + } + fputs($stderr, + "Usage: pear [-v n] [-h] [-p <dir>] [-e <dir>] [-d <dir>] command <parameters>\n". + "Options:\n". + " -v set verbosity level to <n> (0-2, default 1)\n". + " -p <dir> set script install dir (absolute path)\n". + " -e <dir> set extension install dir (absolute path)\n". + " -d <dir> set documentation dest dir (absolute path)\n". + " -h, -? display help/usage (this message)\n". + "Commands:\n". + " install <package file>\n". + " package [package info file]\n". + "\n"); + fclose($stderr); + exit; +} + +?> diff --git a/pear/tests/pear_config.phpt b/pear/tests/pear_config.phpt new file mode 100644 index 0000000000..186c3a0cc3 --- /dev/null +++ b/pear/tests/pear_config.phpt @@ -0,0 +1,72 @@ +--TEST-- +PEAR_Config +--FILE-- +<?php + +error_reporting(E_ALL); +include "../PEAR/Config.php"; +copy("system.input", "system.conf"); +copy("user.input", "user.conf"); +PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n"); +dumpall(); + +print "creating config object\n"; +$config = new PEAR_Config("user.conf", "system.conf"); + +// overriding system values +$config->set("master_server", "pear.localdomain"); +$config->writeConfigFile(); +dumpall(); +var_dump($config->get("master_server")); + +// going back to defaults +$config->toDefault("master_server"); +$config->writeConfigFile(); +dumpall(); + +// + +print "done\n"; + +unlink("user.conf"); +unlink("system.conf"); + +// ------------------------------------------------------------------------- // + +function dumpit($file) +{ + $fp = fopen($file, "r"); + print "$file:"; + $data = unserialize(fread($fp, filesize($file))); + fclose($fp); + if (!is_array($data)) { + print " <empty>\n"; + return; + } + foreach ($data as $k => $v) { + print " $k=\"$v\""; + } + print "\n"; +} + +function dumpall() +{ + print "dumping...\n"; + dumpit("system.conf"); + dumpit("user.conf"); +} + +?> +--EXPECT-- +dumping... +system.conf: master_server="pear.php.net" +user.conf: <empty> +creating config object +dumping... +system.conf: master_server="pear.php.net" +user.conf: master_server="pear.localdomain" +string(16) "pear.localdomain" +dumping... +system.conf: master_server="pear.php.net" +user.conf: +done diff --git a/pear/tests/pear_error4.phpt b/pear/tests/pear_error4.phpt new file mode 100644 index 0000000000..1b50637698 --- /dev/null +++ b/pear/tests/pear_error4.phpt @@ -0,0 +1,89 @@ +--TEST-- +PEAR_Error: expected errors +--FILE-- +<?php // -*- PHP -*- + +// Test for: PEAR.php +// Parts tested: - PEAR_Error class +// - PEAR::expectError +// - PEAR::popExpect + +require "../PEAR.php"; + +error_reporting(E_ALL); + +function errorhandler($eobj) +{ + if (PEAR::isError($eobj)) { + print "error: ".$eobj->getMessage()."\n"; + } else { + print "errorhandler called without error object\n"; + } +} + +$obj = new PEAR; +$obj->setErrorHandling(PEAR_ERROR_CALLBACK, "errorhandler"); + +print "subtest 1\n"; +$obj->expectError(1); +$obj->raiseError("1", 1); +$obj->popExpect(); +$obj->raiseError("2", 2); + +print "subtest 2\n"; +$obj->expectError(3); +$obj->expectError(2); +$obj->raiseError("3", 3); + +print "subtest 3\n"; +$obj->popExpect(); +$obj->raiseError("3", 3); +$obj->popExpect(); + +print "subtest 4\n"; +$obj->expectError(array(1,2,3,4,5)); +$obj->raiseError("0", 0); +$obj->raiseError("1", 1); +$obj->raiseError("2", 2); +$obj->raiseError("3", 3); +$obj->raiseError("4", 4); +$obj->raiseError("5", 5); +$obj->raiseError("6", 6); +$obj->raiseError("error"); +$obj->popExpect(); + +print "subtest 5\n"; +$obj->expectError("*"); +$obj->raiseError("42", 42); +$obj->raiseError("75", 75); +$obj->raiseError("13", 13); +$obj->popExpect(); + +print "subtest 6\n"; +$obj->expectError(); +$obj->raiseError("123", 123); +$obj->raiseError("456", 456); +$obj->raiseError("789", 789); +$obj->popExpect(); + +print "subtest 7\n"; +$obj->expectError("syntax error"); +$obj->raiseError("type mismatch"); +$obj->raiseError("syntax error"); +$obj->popExpect(); + +?> +--EXPECT-- +subtest 1 +error: 2 +subtest 2 +error: 3 +subtest 3 +subtest 4 +error: 0 +error: 6 +error: error +subtest 5 +subtest 6 +subtest 7 +error: type mismatch diff --git a/pear/tests/pear_registry.phpt b/pear/tests/pear_registry.phpt new file mode 100644 index 0000000000..57d2456734 --- /dev/null +++ b/pear/tests/pear_registry.phpt @@ -0,0 +1,92 @@ +--TEST-- +PEAR_Registry +--FILE-- +<?php + +error_reporting(E_ALL); +include "../PEAR/Registry.php"; +PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n"); +cleanall(); + +print "creating registry object\n"; +$reg = new PEAR_Registry; +$reg->statedir = getcwd(); +dumpall($reg); +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0")); +dumpall($reg); +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0")); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0")); +dumpall($reg); +$reg->updatePackage("pkg2", array("version" => "2.1")); +dumpall($reg); +var_dump($reg->deletePackage("pkg2")); +dumpall($reg); +var_dump($reg->deletePackage("pkg2")); +dumpall($reg); +$reg->updatePackage("pkg3", array("version" => "3.1b1", "status" => "beta")); +dumpall($reg); + +print "tests done\n"; + +cleanall(); + +// ------------------------------------------------------------------------- // + +function cleanall() +{ + $dp = opendir("."); + while ($ent = readdir($dp)) { + if (substr($ent, -4) == ".inf") { + unlink($ent); + } + } +} + +function dumpall(&$reg) +{ + print "dumping registry...\n"; + $info = $reg->packageInfo(); + foreach ($info as $pkg) { + print $pkg["name"] . ":"; + unset($pkg["name"]); + foreach ($pkg as $k => $v) { + print " $k=\"$v\""; + } + print "\n"; + } + print "dump done\n"; +} + +?> +--EXPECT-- +creating registry object +dumping registry... +dump done +dumping registry... +pkg1: version="1.0" +dump done +dumping registry... +pkg1: version="1.0" +pkg2: version="2.0" +pkg3: version="3.0" +dump done +dumping registry... +pkg1: version="1.0" +pkg2: version="2.1" +pkg3: version="3.0" +dump done +bool(true) +dumping registry... +pkg1: version="1.0" +pkg3: version="3.0" +dump done +bool(false) +dumping registry... +pkg1: version="1.0" +pkg3: version="3.0" +dump done +dumping registry... +pkg1: version="1.0" +pkg3: version="3.1b1" status="beta" +dump done +tests done diff --git a/pear/tests/system.input b/pear/tests/system.input new file mode 100644 index 0000000000..9c6bece157 --- /dev/null +++ b/pear/tests/system.input @@ -0,0 +1 @@ +a:1:{s:13:"master_server";s:12:"pear.php.net";}
\ No newline at end of file diff --git a/pear/tests/user.input b/pear/tests/user.input new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/pear/tests/user.input |