4,19 → 4,12 |
* |
* PHP versions 4 and 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category pear |
* @package PEAR |
* @author Stig Bakken <ssb@php.net> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Config.php,v 1.52 2006/03/05 21:32:47 cellog Exp $ |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 0.1 |
*/ |
33,16 → 26,14 |
* @package PEAR |
* @author Stig Bakken <ssb@php.net> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @version Release: 1.10.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 0.1 |
*/ |
class PEAR_Command_Config extends PEAR_Command_Common |
{ |
// {{{ properties |
|
var $commands = array( |
'config-show' => array( |
'summary' => 'Show All Settings', |
136,29 → 127,21 |
), |
); |
|
// }}} |
// {{{ constructor |
|
/** |
* PEAR_Command_Config constructor. |
* |
* @access public |
*/ |
function PEAR_Command_Config(&$ui, &$config) |
function __construct(&$ui, &$config) |
{ |
parent::PEAR_Command_Common($ui, $config); |
parent::__construct($ui, $config); |
} |
|
// }}} |
|
// {{{ doConfigShow() |
|
function doConfigShow($command, $options, $params) |
{ |
$layer = null; |
if (is_array($params)) { |
$layer = isset($params[0]) ? $params[0] : NULL; |
} else { |
$layer = NULL; |
$layer = isset($params[0]) ? $params[0] : null; |
} |
|
// $params[0] -> the layer |
165,6 → 148,7 |
if ($error = $this->_checkLayer($layer)) { |
return $this->raiseError("config-show:$error"); |
} |
|
$keys = $this->config->getKeys(); |
sort($keys); |
$channel = isset($options['channel']) ? $options['channel'] : |
173,6 → 157,8 |
if (!$reg->channelExists($channel)) { |
return $this->raiseError('Channel "' . $channel . '" does not exist'); |
} |
|
$channel = $reg->channelName($channel); |
$data = array('caption' => 'Configuration (channel ' . $channel . '):'); |
foreach ($keys as $key) { |
$type = $this->config->getType($key); |
180,13 → 166,16 |
if ($type == 'password' && $value) { |
$value = '********'; |
} |
|
if ($value === false) { |
$value = 'false'; |
} elseif ($value === true) { |
$value = 'true'; |
} |
|
$data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value); |
} |
|
foreach ($this->config->getLayers() as $layer) { |
$data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer)); |
} |
195,21 → 184,13 |
return true; |
} |
|
// }}} |
// {{{ doConfigGet() |
|
function doConfigGet($command, $options, $params) |
{ |
if (!is_array($params)) { |
$args_cnt = 0; |
} else { |
$args_cnt = count($params); |
} |
|
$args_cnt = is_array($params) ? count($params) : 0; |
switch ($args_cnt) { |
case 1: |
$config_key = $params[0]; |
$layer = NULL; |
$layer = null; |
break; |
case 2: |
$config_key = $params[0]; |
223,21 → 204,17 |
return $this->raiseError("config-get expects 1 or 2 parameters"); |
} |
|
$reg = &$this->config->getRegistry(); |
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel'); |
$reg = &$this->config->getRegistry(); |
|
if (!$reg->channelExists($channel)) { |
return $this->raiseError('Channel "' . $channel . '" does not exist'); |
} |
|
$channel = $reg->channelName($channel); |
$this->ui->outputData($this->config->get($config_key, $layer, $channel), $command); |
|
return true; |
} |
|
// }}} |
// {{{ doConfigSet() |
|
function doConfigSet($command, $options, $params) |
{ |
// $param[0] -> a parameter to set |
244,25 → 221,41 |
// $param[1] -> the value for the parameter |
// $param[2] -> the layer |
$failmsg = ''; |
if (sizeof($params) < 2 || sizeof($params) > 3) { |
if (count($params) < 2 || count($params) > 3) { |
$failmsg .= "config-set expects 2 or 3 parameters"; |
return PEAR::raiseError($failmsg); |
} |
|
if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) { |
$failmsg .= $error; |
return PEAR::raiseError("config-set:$failmsg"); |
} |
$channel = isset($options['channel']) ? $options['channel'] : |
$this->config->get('default_channel'); |
|
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel'); |
$reg = &$this->config->getRegistry(); |
if (!$reg->channelExists($channel)) { |
return $this->raiseError('Channel "' . $channel . '" does not exist'); |
} |
if ($params[0] == 'default_channel') { |
if (!$reg->channelExists($params[1])) { |
return $this->raiseError('Channel "' . $params[1] . '" does not exist'); |
} |
|
$channel = $reg->channelName($channel); |
if ($params[0] == 'default_channel' && !$reg->channelExists($params[1])) { |
return $this->raiseError('Channel "' . $params[1] . '" does not exist'); |
} |
|
if ($params[0] == 'preferred_mirror' |
&& ( |
!$reg->mirrorExists($channel, $params[1]) && |
(!$reg->channelExists($params[1]) || $channel != $params[1]) |
) |
) { |
$msg = 'Channel Mirror "' . $params[1] . '" does not exist'; |
$msg .= ' in your registry for channel "' . $channel . '".'; |
$msg .= "\n" . 'Attempt to run "pear channel-update ' . $channel .'"'; |
$msg .= ' if you believe this mirror should exist as you may'; |
$msg .= ' have outdated channel information.'; |
return $this->raiseError($msg); |
} |
|
if (count($params) == 2) { |
array_push($params, 'user'); |
$layer = 'user'; |
269,29 → 262,29 |
} else { |
$layer = $params[2]; |
} |
|
array_push($params, $channel); |
if (!call_user_func_array(array(&$this->config, 'set'), $params)) |
{ |
if (!call_user_func_array(array(&$this->config, 'set'), $params)) { |
array_pop($params); |
$failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel"; |
} else { |
$this->config->store($layer); |
} |
|
if ($failmsg) { |
return $this->raiseError($failmsg); |
} |
|
$this->ui->outputData('config-set succeeded', $command); |
return true; |
} |
|
// }}} |
// {{{ doConfigHelp() |
|
function doConfigHelp($command, $options, $params) |
{ |
if (empty($params)) { |
$params = $this->config->getKeys(); |
} |
|
$data['caption'] = "Config help" . ((count($params) == 1) ? " for $params[0]" : ''); |
$data['headline'] = array('Name', 'Type', 'Description'); |
$data['border'] = true; |
302,14 → 295,13 |
$docs = rtrim($docs) . "\nValid set: " . |
implode(' ', $this->config->getSetValues($name)); |
} |
|
$data['data'][] = array($name, $type, $docs); |
} |
|
$this->ui->outputData($data, $command); |
} |
|
// }}} |
// {{{ doConfigCreate() |
|
function doConfigCreate($command, $options, $params) |
{ |
if (count($params) != 2) { |
316,6 → 308,7 |
return PEAR::raiseError('config-create: must have 2 parameters, root path and ' . |
'filename to save as'); |
} |
|
$root = $params[0]; |
// Clean up the DIRECTORY_SEPARATOR mess |
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; |
323,38 → 316,45 |
array('/', '/', '/'), |
$root); |
if ($root{0} != '/') { |
if (isset($options['windows'])) { |
if (!preg_match('/^[A-Za-z]:/', $root)) { |
return PEAR::raiseError('Root directory must be an absolute path beginning ' . |
'with "\\" or "C:\\", was: "' . $root . '"'); |
} |
} else { |
if (!isset($options['windows'])) { |
return PEAR::raiseError('Root directory must be an absolute path beginning ' . |
'with "/", was: "' . $root . '"'); |
} |
|
if (!preg_match('/^[A-Za-z]:/', $root)) { |
return PEAR::raiseError('Root directory must be an absolute path beginning ' . |
'with "\\" or "C:\\", was: "' . $root . '"'); |
} |
} |
|
$windows = isset($options['windows']); |
if ($windows) { |
$root = str_replace('/', '\\', $root); |
} |
if (!file_exists($params[1])) { |
if (!@touch($params[1])) { |
return PEAR::raiseError('Could not create "' . $params[1] . '"'); |
} |
|
if (!file_exists($params[1]) && !@touch($params[1])) { |
return PEAR::raiseError('Could not create "' . $params[1] . '"'); |
} |
|
$params[1] = realpath($params[1]); |
$config = &new PEAR_Config($params[1], '#no#system#config#', false, false); |
$config = new PEAR_Config($params[1], '#no#system#config#', false, false); |
if ($root{strlen($root) - 1} == '/') { |
$root = substr($root, 0, strlen($root) - 1); |
} |
|
$config->noRegistry(); |
$config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user'); |
$config->set('data_dir', $windows ? "$root\\pear\\data" : "$root/pear/data"); |
$config->set('www_dir', $windows ? "$root\\pear\\www" : "$root/pear/www"); |
$config->set('cfg_dir', $windows ? "$root\\pear\\cfg" : "$root/pear/cfg"); |
$config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext"); |
$config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs"); |
$config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests"); |
$config->set('cache_dir', $windows ? "$root\\pear\\cache" : "$root/pear/cache"); |
$config->set('download_dir', $windows ? "$root\\pear\\download" : "$root/pear/download"); |
$config->set('temp_dir', $windows ? "$root\\pear\\temp" : "$root/pear/temp"); |
$config->set('bin_dir', $windows ? "$root\\pear" : "$root/pear"); |
$config->set('man_dir', $windows ? "$root\\pear\\man" : "$root/pear/man"); |
$config->writeConfigFile(); |
$this->_showConfig($config); |
$this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"', |
361,8 → 361,6 |
$command); |
} |
|
// }}} |
|
function _showConfig(&$config) |
{ |
$params = array('user'); |
376,6 → 374,7 |
if ($type == 'password' && $value) { |
$value = '********'; |
} |
|
if ($value === false) { |
$value = 'false'; |
} elseif ($value === true) { |
384,6 → 383,7 |
$data['data'][$config->getGroup($key)][] = |
array($config->getPrompt($key) , $key, $value); |
} |
|
foreach ($config->getLayers() as $layer) { |
$data['data']['Config Files'][] = |
array(ucfirst($layer) . ' Configuration File', 'Filename' , |
393,7 → 393,6 |
$this->ui->outputData($data, 'config-show'); |
return true; |
} |
// {{{ _checkLayer() |
|
/** |
* Checks if a layer is defined or not |
409,10 → 408,7 |
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported"; |
} |
} |
|
return false; |
} |
|
// }}} |
} |
|
?> |