| // +----------------------------------------------------------------------+ // // $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'); } // }}} // {{{ run() function run($command, $params) { $cf =& $this->config; $failmsg = ''; switch ($command) { case 'config-show': { $keys = $cf->getKeys(); if (isset($params[0]) && $cf->isDefined($params[0])) { foreach ($keys as $key) { $type = $cf->getType($key); if ($type == 'password') { $this->ui->displayLine("$key = ********"); } else { $this->ui->displayLine("$key = " . $cf->get($key, $params[0])); } } } else { foreach ($keys as $key) { $type = $cf->getType($key); if ($type == 'password') { $this->ui->displayLine("$key = ********"); } else { $this->ui->displayLine("$key = " . $cf->get($key)); } } } break; } case 'config-get': { if (sizeof($params) < 1 || sizeof($params) > 2) { $failmsg .= "config-get expects 1 or 2 parameters"; } 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': { if (sizeof($params) < 2 || sizeof($params) > 3) { $failmsg .= "config-set expects 2 or 3 parameters"; break; } else { if (!call_user_func_array(array($cf, 'set'), $params)) { $failmsg = "config-set (" . implode(", ", $params) . ") failed"; } } break; } default: { return false; } } if ($failmsg) { return $this->raiseError($failmsg); } return true; } // }}} } ?>