Source for file Config.php
Documentation is available at Config.php
* PEAR_Command_Config (config-show, config-get, config-set, config-help, config-create commands)
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Config.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
require_once 'PEAR/Command/Common.php';
* PEAR commands for managing configuration data.
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
'summary' => 'Show All Settings',
'function' => 'doConfigShow',
'doc' => 'show configuration variables for another channel',
Displays all configuration values. An optional argument
may be used to tell which configuration layer to display. Valid
configuration layers are "user", "system" and "default". To display
configurations for different channels, set the default_channel
configuration variable and run config-show again.
'summary' => 'Show One Setting',
'function' => 'doConfigGet',
'doc' => 'show configuration variables for another channel',
'doc' => '<parameter> [layer]
Displays the value of one configuration parameter. The
first argument is the name of the parameter, an optional second argument
may be used to tell which configuration layer to look in. Valid configuration
layers are "user", "system" and "default". If no layer is specified, a value
will be picked from the first layer that defines the parameter, in the order
just specified. The configuration value will be retrieved for the channel
specified by the default_channel configuration variable.
'summary' => 'Change Setting',
'function' => 'doConfigSet',
'doc' => 'show configuration variables for another channel',
'doc' => '<parameter> <value> [layer]
Sets the value of one configuration parameter. The first argument is
the name of the parameter, the second argument is the new value. Some
parameters are subject to validation, and the command will fail with
an error message if the new value does not make sense. An optional
third argument may be used to specify in which layer to set the
configuration parameter. The default layer is "user". The
configuration value will be set for the current channel, which
is controlled by the default_channel configuration variable.
'summary' => 'Show Information About Setting',
'function' => 'doConfigHelp',
Displays help for a configuration parameter. Without arguments it
displays help for all configuration parameters.
'config-create' => array (
'summary' => 'Create a Default configuration file',
'function' => 'doConfigCreate',
'doc' => 'create a config file for a windows install',
'doc' => '<root path> <filename>
Create a default configuration file with all directory configuration
variables set to subdirectories of <root path>, and save it as <filename>.
This is useful especially for creating a configuration file for a remote
PEAR installation (using the --remoteconfig option of install, upgrade,
* PEAR_Command_Config constructor.
$layer = isset ($params[0 ]) ? $params[0 ] : null;
// $params[0] -> the layer
if ($error = $this->_checkLayer ($layer)) {
$keys = $this->config->getKeys ();
$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);
$data = array ('caption' => 'Configuration (channel ' . $channel . '):');
foreach ($keys as $key) {
$type = $this->config->getType ($key);
$value = $this->config->get ($key, $layer, $channel);
if ($type == 'password' && $value) {
} elseif ($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));
$this->ui->outputData ($data, $command);
$config_key = $params[0 ];
$config_key = $params[0 ];
if ($error = $this->_checkLayer ($layer)) {
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');
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);
// $param[0] -> a parameter to set
// $param[1] -> the value for the parameter
// $param[2] -> the layer
$failmsg .= "config-set expects 2 or 3 parameters";
if (isset ($params[2 ]) && ($error = $this->_checkLayer ($params[2 ]))) {
$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);
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.';
if (count($params) == 2 ) {
$failmsg = "config-set (" . implode(", ", $params) . " ) failed, channel $channel";
$this->ui->outputData ('config-set succeeded', $command);
$params = $this->config->getKeys ();
$data['caption'] = "Config help" . ((count($params) == 1 ) ? " for $params[0]" : '');
$data['headline'] = array ('Name', 'Type', 'Description');
foreach ($params as $name) {
$type = $this->config->getType ($name);
$docs = $this->config->getDocs ($name);
$docs = rtrim($docs) . "\nValid set: " .
$data['data'][] = array ($name, $type, $docs);
$this->ui->outputData ($data, $command);
if (count($params) != 2 ) {
return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
// Clean up the DIRECTORY_SEPARATOR mess
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
if (!isset ($options['windows'])) {
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
'with "/", was: "' . $root . '"');
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
'with "\\" or "C:\\", was: "' . $root . '"');
$windows = isset ($options['windows']);
$config = &new PEAR_Config($params[1 ], '#no#system#config#', false , false );
if ($root{strlen($root) - 1 } == '/') {
$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->writeConfigFile ();
$this->_showConfig ($config);
$this->ui->outputData ('Successfully created default configuration file "' . $params[1 ] . '"',
function _showConfig (&$config)
$keys = $config->getKeys ();
$channel = 'pear.php.net';
$data = array ('caption' => 'Configuration (channel ' . $channel . '):');
foreach ($keys as $key) {
$type = $config->getType ($key);
$value = $config->get ($key, 'user', $channel);
if ($type == 'password' && $value) {
} elseif ($value === true ) {
$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' ,
$config->getConfFile ($layer));
$this->ui->outputData ($data, 'config-show');
* 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) && $layer != 'default') {
$layers = $this->config->getLayers ();
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
Documentation generated on Wed, 06 Jul 2011 23:30:39 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|