From: Tomas V.V.Cox Date: Mon, 1 Apr 2002 19:16:01 +0000 (+0000) Subject: Added layer checks and reorganize a little the code X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~925 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b57e0609adc23a0c1d2cbd67672bc8d65858f7ca;p=php Added layer checks and reorganize a little the code --- diff --git a/pear/PEAR/Command/Config.php b/pear/PEAR/Command/Config.php index 99624fb49d..009c2d243e 100644 --- a/pear/PEAR/Command/Config.php +++ b/pear/PEAR/Command/Config.php @@ -14,6 +14,8 @@ // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken | +// | Tomas V.V.Cox | +// | | // +----------------------------------------------------------------------+ // // $Id$ @@ -82,36 +84,39 @@ class PEAR_Command_Config extends PEAR_Command_Common function run($command, $options, $params) { - $cf =& $this->config; + $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:')); - if (isset($params[0]) && $cf->isDefined($params[0])) { - foreach ($keys as $key) { - $type = $cf->getType($key); - $value = $cf->get($key, $params[0]); - if ($type == 'password' && $value) { - $value = '********'; - } - $this->ui->tableRow(array($key, $value)); + foreach ($keys as $key) { + $type = $cf->getType($key); + $value = $cf->get($key, @$params[0]); + if ($type == 'password' && $value) { + $value = '********'; } - } else { - foreach ($keys as $key) { - $type = $cf->getType($key); - $value = $cf->get($key, @$params[0]); - if ($type == 'password' && $value) { - $value = '********'; - } - $this->ui->tableRow(array($key, $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) { @@ -123,17 +128,22 @@ class PEAR_Command_Config extends PEAR_Command_Common 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 { - if (!call_user_func_array(array(&$cf, 'set'), $params)) - { - $failmsg = "config-set (" . - implode(", ", $params) . ") failed"; - } else { - $cf->store(); - } + $cf->store(); } break; } @@ -148,6 +158,24 @@ class PEAR_Command_Config extends PEAR_Command_Common } // }}} + + /** + * 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