cvs: php4 /pear/PEAR/Command Config.php
| From: | Tomas V.V.Cox | Date: | Mon, 01 Apr 2002 19:16:02 +0000 |
| Subject: | cvs: php4 /pear/PEAR/Command Config.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2964@lists.php.net to get a copy of this message | ||
cox Mon Apr 1 14:16:02 2002 EDT
Modified files:
/php4/pear/PEAR/Command Config.php
Log:
Added layer checks and reorganize a little the code
Index: php4/pear/PEAR/Command/Config.php
diff -u php4/pear/PEAR/Command/Config.php:1.7 php4/pear/PEAR/Command/Config.php:1.8
--- php4/pear/PEAR/Command/Config.php:1.7 Mon Apr 1 13:19:45 2002
+++ php4/pear/PEAR/Command/Config.php Mon Apr 1 14:16:01 2002
@@ -14,9 +14,11 @@
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stig Bakken <ssb@fast.no> |
+// | Tomas V.V.Cox <cox@idecnet.com> |
+// | |
// +----------------------------------------------------------------------+
//
-// $Id: Config.php,v 1.7 2002/04/01 18:19:45 cox Exp $
+// $Id: Config.php,v 1.8 2002/04/01 19:16:01 cox Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Config.php";
@@ -82,36 +84,39 @@
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 = '<not set>';
}
+ $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 @@
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 @@
}
// }}}
+
+ /**
+ * 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;
+ }
+
}
?>