📄 config.php
字号:
// {{{ getDocs(key)
/**
* Get the documentation for a config value.
*
* @param string config key
*
* @return string documentation string
*
* @access public
*
*/
function getDocs($key)
{
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['doc'];
}
return false;
}
// }}}
// {{{ getPrompt(key)
/**
* Get the short documentation for a config value.
*
* @param string config key
*
* @return string short documentation string
*
* @access public
*
*/
function getPrompt($key)
{
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['prompt'];
}
return false;
}
// }}}
// {{{ getGroup(key)
/**
* Get the parameter group for a config key.
*
* @param string config key
*
* @return string parameter group
*
* @access public
*
*/
function getGroup($key)
{
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['group'];
}
return false;
}
// }}}
// {{{ getGroups()
/**
* Get the list of parameter groups.
*
* @return array list of parameter groups
*
* @access public
*
*/
function getGroups()
{
$tmp = array();
foreach ($this->configuration_info as $key => $info) {
$tmp[$info['group']] = 1;
}
return array_keys($tmp);
}
// }}}
// {{{ getGroupKeys()
/**
* Get the list of the parameters in a group.
*
* @param string $group parameter group
*
* @return array list of parameters in $group
*
* @access public
*
*/
function getGroupKeys($group)
{
$keys = array();
foreach ($this->configuration_info as $key => $info) {
if ($info['group'] == $group) {
$keys[] = $key;
}
}
return $keys;
}
// }}}
// {{{ getSetValues(key)
/**
* Get the list of allowed set values for a config value. Returns
* NULL for config values that are not sets.
*
* @param string config key
*
* @return array enumerated array of set values, or NULL if the
* config key is unknown or not a set
*
* @access public
*
*/
function getSetValues($key)
{
if (isset($this->configuration_info[$key]) &&
isset($this->configuration_info[$key]['type']) &&
$this->configuration_info[$key]['type'] == 'set')
{
$valid_set = $this->configuration_info[$key]['valid_set'];
reset($valid_set);
if (key($valid_set) === 0) {
return $valid_set;
}
return array_keys($valid_set);
}
return null;
}
// }}}
// {{{ getKeys()
/**
* Get all the current config keys.
*
* @return array simple array of config keys
*
* @access public
*/
function getKeys()
{
$keys = array();
foreach ($this->layers as $layer) {
$test = $this->configuration[$layer];
if (isset($test['__channels'])) {
foreach ($test['__channels'] as $channel => $configs) {
$keys = array_merge($keys, $configs);
}
}
unset($test['__channels']);
$keys = array_merge($keys, $test);
}
return array_keys($keys);
}
// }}}
// {{{ remove(key, [layer])
/**
* Remove the a config key from a specific config layer.
*
* @param string config key
*
* @param string (optional) config layer
*
* @return bool TRUE on success, FALSE on failure
*
* @access public
*/
function remove($key, $layer = 'user')
{
$channel = $this->getDefaultChannel();
if ($channel !== 'pear.php.net') {
if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
unset($this->configuration[$layer]['__channels'][$channel][$key]);
return true;
}
}
if (isset($this->configuration[$layer][$key])) {
unset($this->configuration[$layer][$key]);
return true;
}
return false;
}
// }}}
// {{{ removeLayer(layer)
/**
* Temporarily remove an entire config layer. USE WITH CARE!
*
* @param string config key
*
* @param string (optional) config layer
*
* @return bool TRUE on success, FALSE on failure
*
* @access public
*/
function removeLayer($layer)
{
if (isset($this->configuration[$layer])) {
$this->configuration[$layer] = array();
return true;
}
return false;
}
// }}}
// {{{ store([layer])
/**
* Stores configuration data in a layer.
*
* @param string config layer to store
*
* @return bool TRUE on success, or PEAR error on failure
*
* @access public
*/
function store($layer = 'user', $data = null)
{
return $this->writeConfigFile(null, $layer, $data);
}
// }}}
// {{{ toDefault(key)
/**
* Unset the user-defined value of a config key, reverting the
* value to the system-defined one.
*
* @param string config key
*
* @return bool TRUE on success, FALSE on failure
*
* @access public
*/
function toDefault($key)
{
trigger_error("PEAR_Config::toDefault() deprecated, use PEAR_Config::remove() instead", E_USER_NOTICE);
return $this->remove($key, 'user');
}
// }}}
// {{{ definedBy(key)
/**
* Tells what config layer that gets to define a key.
*
* @param string config key
* @param boolean return the defining channel
*
* @return string|array the config layer, or an empty string if not found.
*
* if $returnchannel, the return is an array array('layer' => layername,
* 'channel' => channelname), or an empty string if not found
*
* @access public
*/
function definedBy($key, $returnchannel = false)
{
foreach ($this->layers as $layer) {
$channel = $this->getDefaultChannel();
if ($channel !== 'pear.php.net') {
if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
if ($returnchannel) {
return array('layer' => $layer, 'channel' => $channel);
}
return $layer;
}
}
if (isset($this->configuration[$layer][$key])) {
if ($returnchannel) {
return array('layer' => $layer, 'channel' => 'pear.php.net');
}
return $layer;
}
}
return '';
}
// }}}
// {{{ isDefaulted(key)
/**
* Tells whether a config value has a system-defined value.
*
* @param string config key
*
* @return bool
*
* @access public
*
* @deprecated
*/
function isDefaulted($key)
{
trigger_error("PEAR_Config::isDefaulted() deprecated, use PEAR_Config::definedBy() instead", E_USER_NOTICE);
return $this->definedBy($key) == 'system';
}
// }}}
// {{{ isDefined(key)
/**
* Tells whether a given key exists as a config value.
*
* @param string config key
*
* @return bool whether <config key> exists in this object
*
* @access public
*/
function isDefined($key)
{
foreach ($this->layers as $layer) {
if (isset($this->configuration[$layer][$key])) {
return true;
}
}
return false;
}
// }}}
// {{{ isDefinedLayer(key)
/**
* Tells whether a given config layer exists.
*
* @param string config layer
*
* @return bool whether <config layer> exists in this object
*
* @access public
*/
function isDefinedLayer($layer)
{
return isset($this->configuration[$layer]);
}
// }}}
// {{{ getLayers()
/**
* Returns the layers defined (except the 'default' one)
*
* @return array of the defined layers
*/
function getLayers()
{
$cf = $this->configuration;
unset($cf['default']);
return array_keys($cf);
}
// }}}
// {{{ apiVersion()
function apiVersion()
{
return '1.1';
}
// }}}
/**
* @return PEAR_Registry
*/
function &getRegistry($use = null)
{
if ($use === null) {
$layer = 'user';
} else {
$layer = $use;
}
if (isset($this->_registry[$layer])) {
return $this->_registry[$layer];
} elseif ($use === null && isset($this->_registry['system'])) {
return $this->_registry['system'];
} elseif ($use === null && isset($this->_registry['default'])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -