From: SVN Migration Date: Thu, 4 Apr 2002 15:25:47 +0000 (+0000) Subject: This commit was manufactured by cvs2svn to create branch 'PHP_4_2_0'. X-Git-Tag: php-4.2.0RC3~56 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=401f3711f61083c1ac945565eb52e81b0d6a3671;p=php This commit was manufactured by cvs2svn to create branch 'PHP_4_2_0'. --- diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt new file mode 100644 index 0000000000..ce4e22a7bf --- /dev/null +++ b/ext/pgsql/tests/08escape.phpt @@ -0,0 +1,11 @@ +--TEST-- +PostgreSQL escape functions +--SKIPIF-- + +--FILE-- + +--EXPECT-- +pg_escape_string() is Ok +pg_escape_bytea() is Ok diff --git a/ext/pgsql/tests/escape.inc b/ext/pgsql/tests/escape.inc new file mode 100644 index 0000000000..c02ac423f8 --- /dev/null +++ b/ext/pgsql/tests/escape.inc @@ -0,0 +1,28 @@ + diff --git a/pear/PEAR/Command/Auth.php b/pear/PEAR/Command/Auth.php new file mode 100644 index 0000000000..f59f730b83 --- /dev/null +++ b/pear/PEAR/Command/Auth.php @@ -0,0 +1,132 @@ + | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once "PEAR/Command/Common.php"; +require_once "PEAR/Remote.php"; +require_once "PEAR/Config.php"; + +/** + * PEAR commands for managing configuration data. + * + */ +class PEAR_Command_Auth extends PEAR_Command_Common +{ + // {{{ constructor + + /** + * PEAR_Command_Auth constructor. + * + * @access public + */ + function PEAR_Command_Auth(&$ui, &$config) + { + parent::PEAR_Command_Common($ui, $config); + } + + // }}} + + // {{{ getCommands() + + /** + * Return a list of all the commands defined by this class. + * @return array list of commands + * @access public + */ + function getCommands() + { + return array('login', 'logout'); + } + + // }}} + + function getHelp($command) + { + switch ($command) { + case 'login': + return array(null, 'Connects to the remote server'); + case 'logout': + return array(null, 'Disconnects from the remote server'); + } + } + // {{{ run() + + /** + * Execute the command. + * + * @param string command name + * + * @param array option_name => value + * + * @param array list of additional parameters + * + * @return bool TRUE on success, FALSE for unknown commands, or + * a PEAR error on failure + * + * @access public + */ + function run($command, $options, $params) + { + $failmsg = ''; + $server = $this->config->get('master_server'); + switch ($command) { + case 'login': { + $remote = new PEAR_Remote($this->config); + $username = $this->config->get('username'); + if (empty($username)) { + $username = @$_ENV['USER']; + } + $this->ui->displayLine("Logging in to $server."); + $username = trim($this->ui->userDialog('Username', 'text', $username)); + + $this->config->set('username', $username); + $password = trim($this->ui->userDialog('Password', 'password')); + $this->config->set('password', $password); + $remote->expectError(401); + $ok = $remote->call('logintest'); + $remote->popExpect(); + if ($ok === true) { + $this->ui->displayLine("Logged in."); + $this->config->store(); + } else { + $this->ui->displayLine("Login failed!"); + } + break; + } + case 'logout': { + $this->ui->displayLine("Logging out from $server."); + $this->config->remove('username'); + $this->config->remove('password'); + $this->config->store(); + break; + } + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} +} + +?> \ No newline at end of file diff --git a/pear/PEAR/Command/Config.php b/pear/PEAR/Command/Config.php new file mode 100644 index 0000000000..009c2d243e --- /dev/null +++ b/pear/PEAR/Command/Config.php @@ -0,0 +1,181 @@ + | +// | Tomas V.V.Cox | +// | | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once "PEAR/Command/Common.php"; +require_once "PEAR/Config.php"; + +/** + * PEAR commands for managing configuration data. + * + */ +class PEAR_Command_Config extends PEAR_Command_Common +{ + // {{{ properties + // }}} + + // {{{ constructor + + /** + * PEAR_Command_Config constructor. + * + * @access public + */ + function PEAR_Command_Config(&$ui, &$config) + { + parent::PEAR_Command_Common($ui, $config); + } + + // }}} + + // {{{ getCommands() + + /** + * Return a list of all the commands defined by this class. + * @return array list of commands + * @access public + */ + function getCommands() + { + return array('config-show', 'config-get', 'config-set'); + } + + // }}} + + function getHelp($command) + { + switch ($command) { + case 'config-show': + $ret = array('[]', 'Displays the configuration'); + break; + case 'config-get': + $ret = array(' []', + 'Displays the value of the given parameter'); + break; + case 'config-set': + $ret = array(' []', + 'Sets the value of a parameter in the config'); + break; + } + $ret[1] .= "\n". + " Where to store/get the configuration. The installer\n". + " supports 'user' (per user conf) and 'system' (global conf)"; + return $ret; + } + // {{{ run() + + function run($command, $options, $params) + { + $cf = &$this->config; + $failmsg = ''; + switch ($command) { + case 'config-show': { + // $params[0] -> the layer + if ($error = $this->_checkLayer(@$params[0])) { + $failmsg .= $error; + break; + } + $keys = $cf->getKeys(); + sort($keys); + $this->ui->startTable(array('caption' => 'Configuration:')); + foreach ($keys as $key) { + $type = $cf->getType($key); + $value = $cf->get($key, @$params[0]); + if ($type == 'password' && $value) { + $value = '********'; + } + if (empty($value)) { + $value = ''; + } + $this->ui->tableRow(array($key, $value)); + } + $this->ui->endTable(); + break; + } + case 'config-get': { + // $params[0] -> the parameter + // $params[1] -> the layer + if ($error = $this->_checkLayer(@$params[1])) { + $failmsg .= $error; + break; + } + if (sizeof($params) < 1 || sizeof($params) > 2) { + $failmsg .= "config-get expects 1 or 2 parameters. Try \"help config-get\" for help"; + } elseif (sizeof($params) == 1) { + $this->ui->displayLine("$params[0] = " . $cf->get($params[0])); + } else { + $this->ui->displayLine("($params[1])$params[0] = " . + $cf->get($params[0], $params[1])); + } + break; + } + case 'config-set': { + // $param[0] -> a parameter to set + // $param[1] -> the value for the parameter + // $param[2] -> the layer + if (sizeof($params) < 2 || sizeof($params) > 3) { + $failmsg .= "config-set expects 2 or 3 parameters. Try \"help config-set\" for help"; + break; + } + if ($error = $this->_checkLayer(@$params[2])) { + $failmsg .= $error; + break; + } + if (!call_user_func_array(array(&$cf, 'set'), $params)) + { + $failmsg = "config-set (" . implode(", ", $params) . ") failed"; + } else { + $cf->store(); + } + break; + } + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} + + /** + * Checks if a layer is defined or not + * + * @param string $layer The layer to search for + * @return mixed False on no error or the error message + */ + function _checkLayer($layer = null) + { + if (!empty($layer)) { + $layers = $this->config->getLayers(); + if (!in_array($layer, $layers)) { + return " only the layers: \"" . implode('" or "', $layers) . "\" are supported"; + } + } + return false; + } + +} + +?> \ No newline at end of file diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php new file mode 100644 index 0000000000..92777094ca --- /dev/null +++ b/pear/PEAR/Command/Registry.php @@ -0,0 +1,132 @@ + value + * + * @param array list of additional parameters + * + * @return bool TRUE on success, FALSE if the command was unknown, + * or a PEAR error on failure + * + * @access public + */ + function run($command, $options, $params) + { + $failmsg = ''; + $cf = &PEAR_Config::singleton(); + switch ($command) { + // {{{ list-installed + + case 'list-installed': { + $reg = new PEAR_Registry($cf->get('php_dir')); + $installed = $reg->packageInfo(); + $i = $j = 0; + $this->ui->startTable( + array('caption' => 'Installed packages:', + 'border' => true)); + foreach ($installed as $package) { + if ($i++ % 20 == 0) { + $this->ui->tableRow( + array('Package', 'Version', 'State'), + array('bold' => true)); + } + $this->ui->tableRow(array($package['package'], + $package['version'], + @$package['release_state'])); + } + $this->ui->endTable(); + break; + } + + // }}} + case 'shell-test': { + // silence error messages for the rest of the execution + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); + $reg = &new PEAR_Registry($this->config->get('php_dir')); + // "pear shell-test Foo" + if (sizeof($params) == 1) { + if (!$reg->packageExists($params[0])) { + exit(1); + } + // "pear shell-test Foo 1.0" + } elseif (sizeof($params) == 2) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[1], "ge")) { + exit(1); + } + // "pear shell-test Foo ge 1.0" + } elseif (sizeof($params) == 3) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[2], $params[1])) { + exit(1); + } + } else { + PEAR::popErrorHandling(); + PEAR::raiseError("$command: expects 1 to 3 parameters"); + exit(1); + } + break; + } + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} + + +} + +?> \ No newline at end of file diff --git a/pear/PEAR/Command/Remote.php b/pear/PEAR/Command/Remote.php new file mode 100644 index 0000000000..ecf2c3e91f --- /dev/null +++ b/pear/PEAR/Command/Remote.php @@ -0,0 +1,128 @@ + value + * + * @param array list of additional parameters + * + * @return bool TRUE on success, FALSE for unknown commands, or + * a PEAR error on failure + * + * @access public + */ + function run($command, $options, $params) + { + $failmsg = ''; + $remote = &new PEAR_Remote($this->config); + switch ($command) { + case 'remote-package-info': { + break; + } + case 'list-remote-packages': { + break; + } + case 'list-upgrades': { + include_once "PEAR/Registry.php"; + if (empty($params[0])) { + $state = $this->config->get('preferred_state'); + } else { + $state = $params[0]; + } + $caption = 'Available Upgrades'; + if (empty($state) || $state == 'any') { + $latest = $remote->call("package.listLatestReleases"); + } else { + $latest = $remote->call("package.listLatestReleases", $state); + $caption .= ' (' . $state . ')'; + } + $caption .= ':'; + if (PEAR::isError($latest)) { + return $latest; + } + $reg = new PEAR_Registry($this->config->get('php_dir')); + $inst = array_flip($reg->listPackages()); + $this->ui->startTable(array('caption' => $caption, + 'border' => 1)); + $this->ui->tableRow(array('Package', 'Version', 'Size'), + array('bold' => true)); + foreach ($latest as $package => $info) { + if (!isset($inst[$package])) { + // skip packages we don't have installed + continue; + } + extract($info); + $inst_version = $reg->packageInfo($package, 'version'); + if (version_compare($version, $inst_version, "le")) { + // installed version is up-to-date + continue; + } + if ($filesize >= 20480) { + $filesize += 1024 - ($filesize % 1024); + $fs = sprintf("%dkB", $filesize / 1024); + } elseif ($filesize > 0) { + $filesize += 103 - ($filesize % 103); + $fs = sprintf("%.1fkB", $filesize / 1024.0); + } else { + $fs = " -"; // XXX center instead + } + $this->ui->tableRow(array($package, $version, $fs)); + } + $this->ui->endTable(); + break; + } + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} + + +} + +?> \ No newline at end of file