From 60035fb949e0b1e292e090c86a81c394c9677be1 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Fri, 22 Mar 2002 09:22:28 +0000 Subject: [PATCH] * rename PEAR_CommandUI* to PEAR_Frontend* * rename PEAR/Command/Login.php to PEAR/Command/Auth.php * replace PEAR/Command/Info.php with PEAR/Command/Registry.php (will contain more commands related to the local registry) * started working on Frontend table output --- pear/Makefile.frag | 5 +- pear/PEAR/Command.php | 14 +- pear/PEAR/Command/{Login.php => Auth.php} | 10 +- pear/PEAR/Command/Common.php | 4 +- pear/PEAR/Command/Install.php | 1 + pear/PEAR/Command/List.php | 89 ------------- pear/PEAR/Command/Package.php | 2 +- pear/PEAR/Command/Registry.php | 91 +++++++++++++ pear/PEAR/CommandUI/CLI.php | 101 -------------- pear/PEAR/Frontend/CLI.php | 154 ++++++++++++++++++++++ pear/PEAR/Installer.php | 4 +- pear/PEAR/Remote.php | 2 +- 12 files changed, 266 insertions(+), 211 deletions(-) rename pear/PEAR/Command/{Login.php => Auth.php} (95%) delete mode 100644 pear/PEAR/Command/List.php create mode 100644 pear/PEAR/Command/Registry.php delete mode 100644 pear/PEAR/CommandUI/CLI.php create mode 100644 pear/PEAR/Frontend/CLI.php diff --git a/pear/Makefile.frag b/pear/Makefile.frag index 5a1cf57de4..7a1692bdbf 100644 --- a/pear/Makefile.frag +++ b/pear/Makefile.frag @@ -70,13 +70,14 @@ PEAR_FILES = \ PEAR.php \ PEAR/Autoloader.php \ PEAR/Command.php \ + PEAR/Command/Auth.php \ PEAR/Command/Common.php \ PEAR/Command/Config.php \ PEAR/Command/Install.php \ - PEAR/Command/Login.php \ PEAR/Command/Package.php \ + PEAR/Command/Registry.php \ PEAR/CommandResponse.php \ - PEAR/CommandUI/CLI.php \ + PEAR/Frontend/CLI.php \ PEAR/Common.php \ PEAR/Config.php \ PEAR/Dependency.php \ diff --git a/pear/PEAR/Command.php b/pear/PEAR/Command.php index f0f88eaefe..851099e66b 100644 --- a/pear/PEAR/Command.php +++ b/pear/PEAR/Command.php @@ -31,7 +31,7 @@ $GLOBALS['_PEAR_Command_commandlist'] = array(); * Which user interface class is being used. * @var string class name */ -$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_CommandUI_CLI'; +$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_Frontend_CLI'; /** * The options accepted by the commands @@ -101,13 +101,13 @@ class PEAR_Command } if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; - $obj = &new $class(PEAR_Command::getUIObject(), $config); + $obj = &new $class(PEAR_Command::getFrontendObject(), $config); return $obj; } return PEAR::raiseError("unknown command `$command'"); } - function &getUIObject() + function &getFrontendObject() { global $_PEAR_Command_uiclass, $_PEAR_Command_uiobject; if (empty($_PEAR_Command_uiobject)) { @@ -116,7 +116,7 @@ class PEAR_Command return $_PEAR_Command_uiobject; } - function setUIClass($uiclass) + function setFrontendClass($uiclass) { $GLOBALS['_PEAR_Command_uiclass'] = $uiclass; $file = str_replace("_", "/", $uiclass) . '.php'; @@ -124,10 +124,10 @@ class PEAR_Command return class_exists(strtolower($uiclass)); } - function setUIType($uitype) + function setFrontendType($uitype) { - $uiclass = 'PEAR_CommandUI_' . $uitype; - return PEAR_Command::setUIClass($uiclass); + $uiclass = 'PEAR_Frontend_' . $uitype; + return PEAR_Command::setFrontendClass($uiclass); } /** diff --git a/pear/PEAR/Command/Login.php b/pear/PEAR/Command/Auth.php similarity index 95% rename from pear/PEAR/Command/Login.php rename to pear/PEAR/Command/Auth.php index 44c85c909b..735c2e311c 100644 --- a/pear/PEAR/Command/Login.php +++ b/pear/PEAR/Command/Auth.php @@ -37,7 +37,7 @@ class PEAR_Command_Login extends PEAR_Command_Common */ function PEAR_Command_Login(&$ui, &$config) { - parent::PEAR_Command_Common($ui); + parent::PEAR_Command_Common($ui, $config); } // }}} @@ -66,7 +66,8 @@ class PEAR_Command_Login extends PEAR_Command_Common * * @param array list of additional parameters * - * @return bool TRUE on success, PEAR error on failure + * @return bool TRUE on success, FALSE for unknown commands, or + * a PEAR error on failure * * @access public */ @@ -77,6 +78,7 @@ class PEAR_Command_Login extends PEAR_Command_Common $server = $cf->get('master_server'); switch ($command) { case 'login': { + $remote = new PEAR_Remote($cf); $username = $cf->get('username'); if (empty($username)) { $username = @$_ENV['USER']; @@ -87,7 +89,6 @@ class PEAR_Command_Login extends PEAR_Command_Common $cf->set('username', $username); $password = trim($this->ui->userDialog('Password', 'password')); $cf->set('password', $password); - $remote = new PEAR_Remote($cf); $remote->expectError(401); $ok = $remote->call('logintest'); $remote->popExpect(); @@ -107,8 +108,7 @@ class PEAR_Command_Login extends PEAR_Command_Common break; } default: { - $failmsg = "unknown command: $command"; - break; + return false; } } if ($failmsg) { diff --git a/pear/PEAR/Command/Common.php b/pear/PEAR/Command/Common.php index 0ae02ebddd..7ea724a999 100644 --- a/pear/PEAR/Command/Common.php +++ b/pear/PEAR/Command/Common.php @@ -45,8 +45,8 @@ class PEAR_Command_Common extends PEAR function PEAR_Command_Common(&$ui, &$config) { parent::PEAR(); - $this->config =& $config; - $this->ui = $ui; + $this->config = &$config; + $this->ui = &$ui; } function getOptions() diff --git a/pear/PEAR/Command/Install.php b/pear/PEAR/Command/Install.php index e858adf5e0..3a8702bd92 100644 --- a/pear/PEAR/Command/Install.php +++ b/pear/PEAR/Command/Install.php @@ -66,6 +66,7 @@ class PEAR_Command_Install extends PEAR_Command_Common $this->config->get('ext_dir'), $this->config->get('doc_dir')); $installer->debug = $this->config->get('verbose'); + $failmsg = ''; $opts = array(); switch ($command) { diff --git a/pear/PEAR/Command/List.php b/pear/PEAR/Command/List.php deleted file mode 100644 index 7334c1802b..0000000000 --- a/pear/PEAR/Command/List.php +++ /dev/null @@ -1,89 +0,0 @@ - | -// +----------------------------------------------------------------------+ -// -// $Id$ - -require_once "PEAR/Command/Common.php"; -require_once "PEAR/Registry.php"; - -/** - * PEAR commands for managing configuration data. - * - */ -class PEAR_Command_List extends PEAR_Command_Common -{ - // {{{ properties - // }}} - - // {{{ constructor - - /** - * PEAR_Command_Config constructor. - * - * @access public - */ - function PEAR_Command_List(&$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('list'); - } - - // }}} - // {{{ run() - - function run($command, $options, $params) - { - $reg = new PEAR_Registry(); // XXX Use config here - $installed = $reg->packageInfo(); - $i = $j = 0; - ob_start(); - heading("Installed packages:"); - foreach ($installed as $package) { - if ($i++ % 20 == 0) { - if ($j++ > 0) { - print "\n"; - } - printf("%-20s %-10s %s\n", - "Package", "Version", "State"); - print str_repeat("-", 75)."\n"; - } - printf("%-20s %-10s %s\n", $package['package'], - $package['version'], $package['release_state']); - } - $output = ob_get_contents(); - ob_end_clean(); - $lines = explode("\n", $output); - foreach ($lines as $line) { - $this->ui->displayLine($line); - } - } -} -?> \ No newline at end of file diff --git a/pear/PEAR/Command/Package.php b/pear/PEAR/Command/Package.php index f3f7a27e67..cea5a627fb 100644 --- a/pear/PEAR/Command/Package.php +++ b/pear/PEAR/Command/Package.php @@ -8,7 +8,7 @@ class PEAR_Command_Package extends PEAR_Command_Common // {{{ constructor /** - * PEAR_Command_Login constructor. + * PEAR_Command_Package constructor. * * @access public */ diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php new file mode 100644 index 0000000000..f5444fcb86 --- /dev/null +++ b/pear/PEAR/Command/Registry.php @@ -0,0 +1,91 @@ + 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) { + case 'list-installed': { + $reg = new PEAR_Registry($cf->get('php_dir')); + $installed = $reg->packageInfo(); + $i = $j = 0; + heading("Installed packages:"); + foreach ($installed as $package) { + if ($i++ % 20 == 0) { + if ($j++ > 0) { + print "\n"; + } + printf("%-20s %-10s %s\n", + "Package", "Version", "State"); + print str_repeat("-", 75)."\n"; + } + printf("%-20s %-10s %s\n", $package['package'], + $package['version'], $package['release_state']); + } + break; + } + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} + + +} + +?> \ No newline at end of file diff --git a/pear/PEAR/CommandUI/CLI.php b/pear/PEAR/CommandUI/CLI.php deleted file mode 100644 index 76ea6f6baf..0000000000 --- a/pear/PEAR/CommandUI/CLI.php +++ /dev/null @@ -1,101 +0,0 @@ -output_mode) { - $this->endOutput(); - } - } - - function displayLine($text) - { - print "$text\n"; - } - - function userDialog($prompt, $type = 'text', $default = '') - { - if ($type == 'password') { - system('stty -echo'); - } - print "$prompt "; - if ($default) { - print "[$default] "; - } - print ": "; - $fp = fopen("php://stdin", "r"); - $line = fgets($fp, 2048); - fclose($fp); - if ($type == 'password') { - system('stty echo'); - print "\n"; - } - if ($default && trim($line) == "") { - return $default; - } - return $line; - } - - function userConfirm($prompt, $default = 'yes') - { - static $positives = array('y', 'yes', 'on', '1'); - static $negatives = array('n', 'no', 'off', '0'); - print "$prompt [$default] : "; - $fp = fopen("php://stdin", "r"); - $line = fgets($fp, 2048); - fclose($fp); - $answer = strtolower(trim($line)); - if (empty($answer)) { - $answer = $default; - } - if (in_array($answer, $positives)) { - return true; - } - if (in_array($answer, $negatives)) { - return false; - } - if (in_array($default, $positives)) { - return true; - } - return false; - } - - function setOutputMode($mode, $params = array()) - { - $this->output_mode = $mode; - $this->output_mode_params = $params; - } - - function startOutput($mode) - { - if ($this->output_mode) { - $this->endOutput(); - } - switch ($mode) { - } - } - - function endOutput($mode = null) - { - if ($mode === null) { - $mode = $this->output_mode; - } - $this->output_mode = ''; - switch ($mode) { - } - } -} - -?> \ No newline at end of file diff --git a/pear/PEAR/Frontend/CLI.php b/pear/PEAR/Frontend/CLI.php new file mode 100644 index 0000000000..22ff678528 --- /dev/null +++ b/pear/PEAR/Frontend/CLI.php @@ -0,0 +1,154 @@ +omode) { + $this->endOutput(); + } + } + + function displayLine($text) + { + print "| $text\n"; + } + + function displayHeading($title) + { + print "| ".strtoupper($title)."\n"; + print "| ".str_repeat("=", strlen($title))."\n"; + } + + function userDialog($prompt, $type = 'text', $default = '') + { + if ($type == 'password') { + system('stty -echo'); + } + print "| $prompt "; + if ($default) { + print "[$default] "; + } + print ": "; + $fp = fopen("php://stdin", "r"); + $line = fgets($fp, 2048); + fclose($fp); + if ($type == 'password') { + system('stty echo'); + print "\n"; + } + if ($default && trim($line) == "") { + return $default; + } + return $line; + } + + function userConfirm($prompt, $default = 'yes') + { + static $positives = array('y', 'yes', 'on', '1'); + static $negatives = array('n', 'no', 'off', '0'); + print "| $prompt [$default] : "; + $fp = fopen("php://stdin", "r"); + $line = fgets($fp, 2048); + fclose($fp); + $answer = strtolower(trim($line)); + if (empty($answer)) { + $answer = $default; + } + if (in_array($answer, $positives)) { + return true; + } + if (in_array($answer, $negatives)) { + return false; + } + if (in_array($default, $positives)) { + return true; + } + return false; + } + + function startTable($params = array()) + { + $this->omode = 'table'; + $params['table_data'] = array(); + $params['widest'] = array(); + $params['ncols'] = 0; + $this->params = $params; + } + + function tableRow($columns, $rowparams = array(), $colparams = array()) + { + for ($i = 0; $i < sizeof($columns); $i++) { + if (!isset($this->params['widest'][$i]) || + strlen($columns[$i] > $this->params['widest'][$i])) + { + $this->params['widest'][$i] = strlen($columns[$i]); + } + } + if (!isset($this->params['ncols']) || + sizeof($columns) > $this->params['ncols']) + { + $this->params['ncols'] = sizeof($columns); + } + $new_row = array( + 'data' => $columns, + 'rowparams' => $rowparams, + 'colparams' => $colparams, + ); + $this->params['table_data'][] = $new_row; + } + + function endTable() + { + $this->omode = ''; + extract($this->params); + if (!empty($caption)) { + $this->displayHeading($caption); + } + if (!isset($width)) { + $width = $widest; + } else { + for ($i = 0; $i < $ncols; $i++) { + if (!isset($width[$i])) { + $width[$i] = $widest[$i]; + } + } + } + if (empty($params['border'])) { + $cellstart = " "; + $rowend = "\n"; + $padrowend = false; + } else { + $cellstart = "| "; + $rowend = " |\n"; + $padrowend = true; + $borderline = "+"; + foreach ($width as $w) { + $borderline .= str_repeat('-', $w + 2); + } + } + for ($i = 0; $i < sizeof($table_data); $i++) { + extract($table_data[$i]); + for ($c = 0; $c < sizeof($data); $c++) { + $w = $width[$c]; + $l = strlen($data[$c]); + if ($l > $w) { + print + } + } + } + } +} + +?> \ No newline at end of file diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 0e9dbdaf19..e24688d15e 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -68,9 +68,7 @@ class PEAR_Installer extends PEAR_Common // {{{ constructor - function PEAR_Installer($phpdir = PEAR_INSTALL_DIR, - $extdir = PEAR_EXTENSION_DIR, - $docdir = null) + function PEAR_Installer(&$config) { $this->PEAR(); $this->phpdir = $phpdir; diff --git a/pear/PEAR/Remote.php b/pear/PEAR/Remote.php index 3ecbb5f4f5..97317cc71c 100644 --- a/pear/PEAR/Remote.php +++ b/pear/PEAR/Remote.php @@ -87,7 +87,7 @@ class PEAR_Remote extends PEAR return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401); } default: - return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]", (int)$matches[1]); + return $this->raiseError("PEAR_Remote: unexpected HTTP response", (int)$matches[1], null, null, "$matches[1] $matches[2]"); } while (trim(fgets($fp, 2048)) != ''); // skip rest of headers while ($chunk = fread($fp, 10240)) { -- 2.40.0