From 95ab15f0a52eb83e13a11f76c508da68c0a29309 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Tue, 14 May 2002 01:49:56 +0000 Subject: [PATCH] * add command definitions, split run() into one method for each command --- pear/PEAR/Command/Auth.php | 136 +++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/pear/PEAR/Command/Auth.php b/pear/PEAR/Command/Auth.php index 8632e95c62..acf3da942e 100644 --- a/pear/PEAR/Command/Auth.php +++ b/pear/PEAR/Command/Auth.php @@ -28,7 +28,34 @@ require_once "PEAR/Config.php"; */ class PEAR_Command_Auth extends PEAR_Command_Common { - // {{{ constructor + // {{{ command definitions + + var $commands = array( + 'login' => array( + 'summary' => 'Connects and authenticates to remote server', + 'function' => 'doLogin', + 'options' => array(), + 'doc' => 'To use functions in the installer that require any kind +of privilege, you need to log in first. The username and password you enter +here will be stored in your per-user PEAR configuration (~/.pearrc on +Unix-like systems). After logging in, your username and password will be +passed along in every subsequent operation on the remote server. +', + ), + 'logout' => array( + 'summary' => 'Logs out from the remote server', + 'function' => 'doLogout', + 'options' => array(), + 'doc' => 'Logs out from the remote server. +This command does not actually connect to the remote +server, it only deletes the stored username and password from your +user configuration. +', + ) + + ); + + // }}} /** * PEAR_Command_Auth constructor. @@ -40,94 +67,69 @@ class PEAR_Command_Auth extends PEAR_Command_Common parent::PEAR_Command_Common($ui, $config); } - // }}} - - // {{{ getCommands() - /** - * Return a list of all the commands defined by this class. - * @return array list of commands + * Execute the 'logout' command. + * + * @param string $command command name + * + * @param array $options option_name => value + * + * @param array $params list of additional parameters + * + * @return bool TRUE on success, FALSE for unknown commands, or + * a PEAR error on failure + * * @access public */ - function getCommands() + function doLogin($command, $options, $params) { - return array('login' => 'Log In', - 'logout' => 'Log Out'); - } - - // }}} + $server = $this->config->get('master_server'); + $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)); - 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'); + $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!"); } + } - // {{{ run() /** - * Execute the command. + * Execute the 'logout' command. * - * @param string command name + * @param string $command command name * - * @param array option_name => value + * @param array $options option_name => value * - * @param array list of additional parameters + * @param array $params 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) + function doLogout($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; + $this->ui->displayLine("Logging out from $server."); + $this->config->remove('username'); + $this->config->remove('password'); + $this->config->store(); } - // }}} } ?> \ No newline at end of file -- 2.50.1