3
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2004 The PHP Group |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 3.0 of the PHP license, |
9
// | that is bundled with this package in the file LICENSE, and is |
10
// | available through the world-wide-web at the following url: |
11
// | http://www.php.net/license/3_0.txt. |
12
// | If you did not receive a copy of the PHP license and are unable to |
13
// | obtain it through the world-wide-web, please send a note to |
14
// | license@php.net so we can mail you a copy immediately. |
15
// +----------------------------------------------------------------------+
16
// | Author: Stig Bakken <ssb@php.net> |
17
// +----------------------------------------------------------------------+
19
// $Id: Config.php,v 1.52 2004/01/08 17:33:12 sniper Exp $
21
require_once 'PEAR.php';
22
require_once 'System.php';
25
* Last created PEAR_Config instance.
28
$GLOBALS['_PEAR_Config_instance'] = null;
29
if (!defined('PEAR_INSTALL_DIR') || !PEAR_INSTALL_DIR) {
30
$PEAR_INSTALL_DIR = PHP_LIBDIR . DIRECTORY_SEPARATOR . 'pear';
32
$PEAR_INSTALL_DIR = PEAR_INSTALL_DIR;
35
// Below we define constants with default values for all configuration
36
// parameters except username/password. All of them can have their
37
// defaults set through environment variables. The reason we use the
38
// PHP_ prefix is for some security, PHP protects environment
39
// variables starting with PHP_*.
41
if (getenv('PHP_PEAR_SYSCONF_DIR')) {
42
define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
43
} elseif (getenv('SystemRoot')) {
44
define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
46
define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
49
// Default for master_server
50
if (getenv('PHP_PEAR_MASTER_SERVER')) {
51
define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', getenv('PHP_PEAR_MASTER_SERVER'));
53
define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', 'pear.php.net');
56
// Default for http_proxy
57
if (getenv('PHP_PEAR_HTTP_PROXY')) {
58
define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('PHP_PEAR_HTTP_PROXY'));
59
} elseif (getenv('http_proxy')) {
60
define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('http_proxy'));
62
define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', '');
65
// Default for php_dir
66
if (getenv('PHP_PEAR_INSTALL_DIR')) {
67
define('PEAR_CONFIG_DEFAULT_PHP_DIR', getenv('PHP_PEAR_INSTALL_DIR'));
69
if (@is_dir($PEAR_INSTALL_DIR)) {
70
define('PEAR_CONFIG_DEFAULT_PHP_DIR',
73
define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
77
// Default for ext_dir
78
if (getenv('PHP_PEAR_EXTENSION_DIR')) {
79
define('PEAR_CONFIG_DEFAULT_EXT_DIR', getenv('PHP_PEAR_EXTENSION_DIR'));
81
if (ini_get('extension_dir')) {
82
define('PEAR_CONFIG_DEFAULT_EXT_DIR', ini_get('extension_dir'));
83
} elseif (defined('PEAR_EXTENSION_DIR') && @is_dir(PEAR_EXTENSION_DIR)) {
84
define('PEAR_CONFIG_DEFAULT_EXT_DIR', PEAR_EXTENSION_DIR);
85
} elseif (defined('PHP_EXTENSION_DIR')) {
86
define('PEAR_CONFIG_DEFAULT_EXT_DIR', PHP_EXTENSION_DIR);
88
define('PEAR_CONFIG_DEFAULT_EXT_DIR', '.');
92
// Default for doc_dir
93
if (getenv('PHP_PEAR_DOC_DIR')) {
94
define('PEAR_CONFIG_DEFAULT_DOC_DIR', getenv('PHP_PEAR_DOC_DIR'));
96
define('PEAR_CONFIG_DEFAULT_DOC_DIR',
97
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'docs');
100
// Default for bin_dir
101
if (getenv('PHP_PEAR_BIN_DIR')) {
102
define('PEAR_CONFIG_DEFAULT_BIN_DIR', getenv('PHP_PEAR_BIN_DIR'));
104
define('PEAR_CONFIG_DEFAULT_BIN_DIR', PHP_BINDIR);
107
// Default for data_dir
108
if (getenv('PHP_PEAR_DATA_DIR')) {
109
define('PEAR_CONFIG_DEFAULT_DATA_DIR', getenv('PHP_PEAR_DATA_DIR'));
111
define('PEAR_CONFIG_DEFAULT_DATA_DIR',
112
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'data');
115
// Default for test_dir
116
if (getenv('PHP_PEAR_TEST_DIR')) {
117
define('PEAR_CONFIG_DEFAULT_TEST_DIR', getenv('PHP_PEAR_TEST_DIR'));
119
define('PEAR_CONFIG_DEFAULT_TEST_DIR',
120
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'tests');
123
// Default for cache_dir
124
if (getenv('PHP_PEAR_CACHE_DIR')) {
125
define('PEAR_CONFIG_DEFAULT_CACHE_DIR', getenv('PHP_PEAR_CACHE_DIR'));
127
define('PEAR_CONFIG_DEFAULT_CACHE_DIR',
128
System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
129
DIRECTORY_SEPARATOR . 'cache');
132
// Default for php_bin
133
if (getenv('PHP_PEAR_PHP_BIN')) {
134
define('PEAR_CONFIG_DEFAULT_PHP_BIN', getenv('PHP_PEAR_PHP_BIN'));
136
define('PEAR_CONFIG_DEFAULT_PHP_BIN', PEAR_CONFIG_DEFAULT_BIN_DIR.
137
DIRECTORY_SEPARATOR.'php'.(OS_WINDOWS ? '.exe' : ''));
140
// Default for verbose
141
if (getenv('PHP_PEAR_VERBOSE')) {
142
define('PEAR_CONFIG_DEFAULT_VERBOSE', getenv('PHP_PEAR_VERBOSE'));
144
define('PEAR_CONFIG_DEFAULT_VERBOSE', 1);
147
// Default for preferred_state
148
if (getenv('PHP_PEAR_PREFERRED_STATE')) {
149
define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', getenv('PHP_PEAR_PREFERRED_STATE'));
151
define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', 'stable');
155
if (getenv('PHP_PEAR_UMASK')) {
156
define('PEAR_CONFIG_DEFAULT_UMASK', getenv('PHP_PEAR_UMASK'));
158
define('PEAR_CONFIG_DEFAULT_UMASK', decoct(umask()));
161
// Default for cache_ttl
162
if (getenv('PHP_PEAR_CACHE_TTL')) {
163
define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL'));
165
define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600);
168
// Default for sig_type
169
if (getenv('PHP_PEAR_SIG_TYPE')) {
170
define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE'));
172
define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg');
175
// Default for sig_bin
176
if (getenv('PHP_PEAR_SIG_BIN')) {
177
define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN'));
179
define('PEAR_CONFIG_DEFAULT_SIG_BIN',
181
'gpg', OS_WINDOWS ? 'c:\gnupg\gpg.exe' : '/usr/local/bin/gpg'));
184
// Default for sig_keydir
185
if (getenv('PHP_PEAR_SIG_KEYDIR')) {
186
define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR'));
188
define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR',
189
PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys');
193
* This is a class for storing configuration data, keeping track of
194
* which are system-defined, user-defined or defaulted.
196
class PEAR_Config extends PEAR
201
* Array of config files used.
203
* @var array layer => config file
210
var $layers = array();
213
* Configuration data, two-dimensional array where the first
214
* dimension is the config layer ('user', 'system' and 'default'),
215
* and the second dimension is keyname => value.
217
* The order in the first dimension is important! Earlier
218
* layers will shadow later ones when a config value is
219
* requested (if a 'user' value exists, it will be returned first,
220
* then 'system' and finally 'default').
222
* @var array layer => array(keyname => value, ...)
224
var $configuration = array(
227
'default' => array(),
231
* Information about the configuration data. Stores the type,
232
* default value and a documentation string for each configuration
235
* @var array layer => array(infotype => value, ...)
237
var $configuration_info = array(
239
'master_server' => array(
241
'default' => 'pear.php.net',
242
'doc' => 'name of the main PEAR server',
243
'prompt' => 'PEAR server',
244
'group' => 'Internet Access',
246
'http_proxy' => array(
248
'default' => PEAR_CONFIG_DEFAULT_HTTP_PROXY,
249
'doc' => 'HTTP proxy (host:port) to use when downloading packages',
250
'prompt' => 'HTTP Proxy Server Address',
251
'group' => 'Internet Access',
255
'type' => 'directory',
256
'default' => PEAR_CONFIG_DEFAULT_PHP_DIR,
257
'doc' => 'directory where .php files are installed',
258
'prompt' => 'PEAR directory',
259
'group' => 'File Locations',
262
'type' => 'directory',
263
'default' => PEAR_CONFIG_DEFAULT_EXT_DIR,
264
'doc' => 'directory where loadable extensions are installed',
265
'prompt' => 'PHP extension directory',
266
'group' => 'File Locations',
269
'type' => 'directory',
270
'default' => PEAR_CONFIG_DEFAULT_DOC_DIR,
271
'doc' => 'directory where documentation is installed',
272
'prompt' => 'PEAR documentation directory',
273
'group' => 'File Locations',
276
'type' => 'directory',
277
'default' => PEAR_CONFIG_DEFAULT_BIN_DIR,
278
'doc' => 'directory where executables are installed',
279
'prompt' => 'PEAR executables directory',
280
'group' => 'File Locations',
283
'type' => 'directory',
284
'default' => PEAR_CONFIG_DEFAULT_DATA_DIR,
285
'doc' => 'directory where data files are installed',
286
'prompt' => 'PEAR data directory',
287
'group' => 'File Locations (Advanced)',
290
'type' => 'directory',
291
'default' => PEAR_CONFIG_DEFAULT_TEST_DIR,
292
'doc' => 'directory where regression tests are installed',
293
'prompt' => 'PEAR test directory',
294
'group' => 'File Locations (Advanced)',
296
'cache_dir' => array(
297
'type' => 'directory',
298
'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
299
'doc' => 'directory which is used for XMLRPC cache',
300
'prompt' => 'PEAR Installer cache directory',
301
'group' => 'File Locations (Advanced)',
305
'default' => PEAR_CONFIG_DEFAULT_PHP_BIN,
306
'doc' => 'PHP CLI/CGI binary for executing scripts',
307
'prompt' => 'PHP CLI/CGI binary',
308
'group' => 'File Locations (Advanced)',
314
'doc' => '(maintainers) your PEAR account name',
315
'prompt' => 'PEAR username (for maintainers)',
316
'group' => 'Maintainers',
319
'type' => 'password',
321
'doc' => '(maintainers) your PEAR account password',
322
'prompt' => 'PEAR password (for maintainers)',
323
'group' => 'Maintainers',
328
'default' => PEAR_CONFIG_DEFAULT_VERBOSE,
329
'doc' => 'verbosity level
334
'prompt' => 'Debug Log Level',
335
'group' => 'Advanced',
337
'preferred_state' => array(
339
'default' => PEAR_CONFIG_DEFAULT_PREFERRED_STATE,
340
'doc' => 'the installer will prefer releases with this state when installing packages without a version or state specified',
341
'valid_set' => array(
342
'stable', 'beta', 'alpha', 'devel', 'snapshot'),
343
'prompt' => 'Preferred Package State',
344
'group' => 'Advanced',
348
'default' => PEAR_CONFIG_DEFAULT_UMASK,
349
'doc' => 'umask used when creating files (Unix-like systems only)',
350
'prompt' => 'Unix file mask',
351
'group' => 'Advanced',
353
'cache_ttl' => array(
355
'default' => PEAR_CONFIG_DEFAULT_CACHE_TTL,
356
'doc' => 'amount of secs where the local cache is used and not updated',
357
'prompt' => 'Cache TimeToLive',
358
'group' => 'Advanced',
362
'default' => PEAR_CONFIG_DEFAULT_SIG_TYPE,
363
'doc' => 'which package signature mechanism to use',
364
'valid_set' => array('gpg'),
365
'prompt' => 'Package Signature Type',
366
'group' => 'Maintainers',
370
'default' => PEAR_CONFIG_DEFAULT_SIG_BIN,
371
'doc' => 'which package signature mechanism to use',
372
'prompt' => 'Signature Handling Program',
373
'group' => 'Maintainers',
375
'sig_keyid' => array(
378
'doc' => 'which key to use for signing with',
379
'prompt' => 'Signature Key Id',
380
'group' => 'Maintainers',
382
'sig_keydir' => array(
384
'default' => PEAR_CONFIG_DEFAULT_SIG_KEYDIR,
385
'doc' => 'which package signature mechanism to use',
386
'prompt' => 'Signature Key Directory',
387
'group' => 'Maintainers',
393
// {{{ PEAR_Config([file], [defaults_file])
398
* @param string (optional) file to read user-defined options from
399
* @param string (optional) file to read system-wide defaults from
403
* @see PEAR_Config::singleton
405
function PEAR_Config($user_file = '', $system_file = '')
408
$sl = DIRECTORY_SEPARATOR;
409
if (empty($user_file)) {
411
$user_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini';
413
$user_file = getenv('HOME') . $sl . '.pearrc';
416
if (empty($system_file)) {
418
$system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini';
420
$system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf';
423
$this->layers = array_keys($this->configuration);
424
$this->files['user'] = $user_file;
425
$this->files['system'] = $system_file;
426
if ($user_file && file_exists($user_file)) {
427
$this->readConfigFile($user_file);
429
if ($system_file && file_exists($system_file)) {
430
$this->mergeConfigFile($system_file, false, 'system');
432
foreach ($this->configuration_info as $key => $info) {
433
$this->configuration['default'][$key] = $info['default'];
435
//$GLOBALS['_PEAR_Config_instance'] = &$this;
439
// {{{ singleton([file], [defaults_file])
442
* Static singleton method. If you want to keep only one instance
443
* of this class in use, this method will give you a reference to
444
* the last created PEAR_Config object if one exists, or create a
447
* @param string (optional) file to read user-defined options from
448
* @param string (optional) file to read system-wide defaults from
450
* @return object an existing or new PEAR_Config instance
454
* @see PEAR_Config::PEAR_Config
456
function &singleton($user_file = '', $system_file = '')
458
if (is_object($GLOBALS['_PEAR_Config_instance'])) {
459
return $GLOBALS['_PEAR_Config_instance'];
461
$GLOBALS['_PEAR_Config_instance'] =
462
&new PEAR_Config($user_file, $system_file);
463
return $GLOBALS['_PEAR_Config_instance'];
467
// {{{ readConfigFile([file], [layer])
470
* Reads configuration data from a file. All existing values in
471
* the config layer are discarded and replaced with data from the
474
* @param string (optional) file to read from, if NULL or not
475
* specified, the last-used file for the same layer (second param)
478
* @param string (optional) config layer to insert data into
479
* ('user' or 'system')
481
* @return bool TRUE on success or a PEAR error on failure
485
function readConfigFile($file = null, $layer = 'user')
487
if (empty($this->files[$layer])) {
488
return $this->raiseError("unknown config file type `$layer'");
490
if ($file === null) {
491
$file = $this->files[$layer];
493
$data = $this->_readConfigDataFrom($file);
494
if (PEAR::isError($data)) {
497
$this->_decodeInput($data);
498
$this->configuration[$layer] = $data;
503
// {{{ mergeConfigFile(file, [override], [layer])
506
* Merges data into a config layer from a file. Does the same
507
* thing as readConfigFile, except it does not replace all
508
* existing values in the config layer.
510
* @param string file to read from
512
* @param bool (optional) whether to overwrite existing data
515
* @param string config layer to insert data into ('user' or
518
* @return bool TRUE on success or a PEAR error on failure
522
function mergeConfigFile($file, $override = true, $layer = 'user')
524
if (empty($this->files[$layer])) {
525
return $this->raiseError("unknown config file type `$layer'");
527
if ($file === null) {
528
$file = $this->files[$layer];
530
$data = $this->_readConfigDataFrom($file);
531
if (PEAR::isError($data)) {
534
$this->_decodeInput($data);
536
$this->configuration[$layer] = array_merge($this->configuration[$layer], $data);
538
$this->configuration[$layer] = array_merge($data, $this->configuration[$layer]);
544
// {{{ writeConfigFile([file], [layer])
547
* Writes data into a config layer from a file.
549
* @param string file to read from
551
* @param bool (optional) whether to overwrite existing data
554
* @param string config layer to insert data into ('user' or
557
* @return bool TRUE on success or a PEAR error on failure
561
function writeConfigFile($file = null, $layer = 'user', $data = null)
563
if ($layer == 'both' || $layer == 'all') {
564
foreach ($this->files as $type => $file) {
565
$err = $this->writeConfigFile($file, $type, $data);
566
if (PEAR::isError($err)) {
572
if (empty($this->files[$layer])) {
573
return $this->raiseError("unknown config file type `$layer'");
575
if ($file === null) {
576
$file = $this->files[$layer];
578
$data = ($data === null) ? $this->configuration[$layer] : $data;
579
$this->_encodeOutput($data);
580
$opt = array('-p', dirname($file));
581
if (!@System::mkDir($opt)) {
582
return $this->raiseError("could not create directory: " . dirname($file));
584
if (@is_file($file) && !@is_writeable($file)) {
585
return $this->raiseError("no write access to $file!");
587
$fp = @fopen($file, "w");
589
return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed");
591
$contents = "#PEAR_Config 0.9\n" . serialize($data);
592
if (!@fwrite($fp, $contents)) {
593
return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed");
599
// {{{ _readConfigDataFrom(file)
602
* Reads configuration data from a file and returns the parsed data
605
* @param string file to read from
607
* @return array configuration data or a PEAR error on failure
611
function _readConfigDataFrom($file)
613
$fp = @fopen($file, "r");
615
return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed");
617
$size = filesize($file);
618
$rt = get_magic_quotes_runtime();
619
set_magic_quotes_runtime(0);
620
$contents = fread($fp, $size);
621
set_magic_quotes_runtime($rt);
624
if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
625
$version = $matches[1];
626
$contents = substr($contents, strlen($matches[0]));
628
if (version_compare("$version", '1', '<')) {
629
$data = unserialize($contents);
630
if (!is_array($data)) {
631
if (strlen(trim($contents)) > 0) {
632
$error = "PEAR_Config: bad data in $file";
633
// if (isset($this)) {
634
return $this->raiseError($error);
636
// return PEAR::raiseError($error);
641
// add parsing of newer formats here...
643
return $this->raiseError("$file: unknown version `$version'");
649
// {{{ getConfFile(layer)
651
* Gets the file used for storing the config for a layer
653
* @param string $layer 'user' or 'system'
656
function getConfFile($layer)
658
return $this->files[$layer];
662
// {{{ _encodeOutput(&data)
665
* Encodes/scrambles configuration data before writing to files.
666
* Currently, 'password' values will be base64-encoded as to avoid
667
* that people spot cleartext passwords by accident.
669
* @param array (reference) array to encode values in
671
* @return bool TRUE on success
675
function _encodeOutput(&$data)
677
foreach ($data as $key => $value) {
678
if (!isset($this->configuration_info[$key])) {
681
$type = $this->configuration_info[$key]['type'];
683
// we base64-encode passwords so they are at least
684
// not shown in plain by accident
686
$data[$key] = base64_encode($data[$key]);
690
$data[$key] = octdec($data[$key]);
699
// {{{ _decodeInput(&data)
702
* Decodes/unscrambles configuration data after reading from files.
704
* @param array (reference) array to encode values in
706
* @return bool TRUE on success
710
* @see PEAR_Config::_encodeOutput
712
function _decodeInput(&$data)
714
if (!is_array($data)) {
717
foreach ($data as $key => $value) {
718
if (!isset($this->configuration_info[$key])) {
721
$type = $this->configuration_info[$key]['type'];
724
$data[$key] = base64_decode($data[$key]);
728
$data[$key] = decoct($data[$key]);
737
// {{{ get(key, [layer])
740
* Returns a configuration value, prioritizing layers as per the
743
* @param string config key
745
* @return mixed the config value, or NULL if not found
749
function get($key, $layer = null)
751
if ($layer === null) {
752
foreach ($this->layers as $layer) {
753
if (isset($this->configuration[$layer][$key])) {
754
return $this->configuration[$layer][$key];
757
} elseif (isset($this->configuration[$layer][$key])) {
758
return $this->configuration[$layer][$key];
764
// {{{ set(key, value, [layer])
767
* Set a config value in a specific layer (defaults to 'user').
768
* Enforces the types defined in the configuration_info array. An
769
* integer config variable will be cast to int, and a set config
770
* variable will be validated against its legal values.
772
* @param string config key
774
* @param string config value
776
* @param string (optional) config layer
778
* @return bool TRUE on success, FALSE on failure
782
function set($key, $value, $layer = 'user')
784
if (empty($this->configuration_info[$key])) {
787
extract($this->configuration_info[$key]);
790
$value = (int)$value;
793
// If a valid_set is specified, require the value to
794
// be in the set. If there is no valid_set, accept
798
if ((key($valid_set) === 0 && !in_array($value, $valid_set)) ||
799
(key($valid_set) !== 0 && empty($valid_set[$value])))
807
$this->configuration[$layer][$key] = $value;
815
* Get the type of a config value.
817
* @param string config key
819
* @return string type, one of "string", "integer", "file",
820
* "directory", "set" or "password".
825
function getType($key)
827
if (isset($this->configuration_info[$key])) {
828
return $this->configuration_info[$key]['type'];
837
* Get the documentation for a config value.
839
* @param string config key
841
* @return string documentation string
846
function getDocs($key)
848
if (isset($this->configuration_info[$key])) {
849
return $this->configuration_info[$key]['doc'];
854
// {{{ getPrompt(key)
857
* Get the short documentation for a config value.
859
* @param string config key
861
* @return string short documentation string
866
function getPrompt($key)
868
if (isset($this->configuration_info[$key])) {
869
return $this->configuration_info[$key]['prompt'];
877
* Get the parameter group for a config key.
879
* @param string config key
881
* @return string parameter group
886
function getGroup($key)
888
if (isset($this->configuration_info[$key])) {
889
return $this->configuration_info[$key]['group'];
898
* Get the list of parameter groups.
900
* @return array list of parameter groups
908
foreach ($this->configuration_info as $key => $info) {
909
$tmp[$info['group']] = 1;
911
return array_keys($tmp);
915
// {{{ getGroupKeys()
918
* Get the list of the parameters in a group.
920
* @param string $group parameter group
922
* @return array list of parameters in $group
927
function getGroupKeys($group)
930
foreach ($this->configuration_info as $key => $info) {
931
if ($info['group'] == $group) {
939
// {{{ getSetValues(key)
942
* Get the list of allowed set values for a config value. Returns
943
* NULL for config values that are not sets.
945
* @param string config key
947
* @return array enumerated array of set values, or NULL if the
948
* config key is unknown or not a set
953
function getSetValues($key)
955
if (isset($this->configuration_info[$key]) &&
956
isset($this->configuration_info[$key]['type']) &&
957
$this->configuration_info[$key]['type'] == 'set')
959
$valid_set = $this->configuration_info[$key]['valid_set'];
961
if (key($valid_set) === 0) {
964
return array_keys($valid_set);
973
* Get all the current config keys.
975
* @return array simple array of config keys
982
foreach ($this->layers as $layer) {
983
$keys = array_merge($keys, $this->configuration[$layer]);
985
return array_keys($keys);
989
// {{{ remove(key, [layer])
992
* Remove the a config key from a specific config layer.
994
* @param string config key
996
* @param string (optional) config layer
998
* @return bool TRUE on success, FALSE on failure
1002
function remove($key, $layer = 'user')
1004
if (isset($this->configuration[$layer][$key])) {
1005
unset($this->configuration[$layer][$key]);
1012
// {{{ removeLayer(layer)
1015
* Temporarily remove an entire config layer. USE WITH CARE!
1017
* @param string config key
1019
* @param string (optional) config layer
1021
* @return bool TRUE on success, FALSE on failure
1025
function removeLayer($layer)
1027
if (isset($this->configuration[$layer])) {
1028
$this->configuration[$layer] = array();
1035
// {{{ store([layer])
1038
* Stores configuration data in a layer.
1040
* @param string config layer to store
1042
* @return bool TRUE on success, or PEAR error on failure
1046
function store($layer = 'user', $data = null)
1048
return $this->writeConfigFile(null, $layer, $data);
1052
// {{{ toDefault(key)
1055
* Unset the user-defined value of a config key, reverting the
1056
* value to the system-defined one.
1058
* @param string config key
1060
* @return bool TRUE on success, FALSE on failure
1064
function toDefault($key)
1066
trigger_error("PEAR_Config::toDefault() deprecated, use PEAR_Config::remove() instead", E_USER_NOTICE);
1067
return $this->remove($key, 'user');
1071
// {{{ definedBy(key)
1074
* Tells what config layer that gets to define a key.
1076
* @param string config key
1078
* @return string the config layer, or an empty string if not found
1082
function definedBy($key)
1084
foreach ($this->layers as $layer) {
1085
if (isset($this->configuration[$layer][$key])) {
1093
// {{{ isDefaulted(key)
1096
* Tells whether a config value has a system-defined value.
1098
* @param string config key
1106
function isDefaulted($key)
1108
trigger_error("PEAR_Config::isDefaulted() deprecated, use PEAR_Config::definedBy() instead", E_USER_NOTICE);
1109
return $this->definedBy($key) == 'system';
1113
// {{{ isDefined(key)
1116
* Tells whether a given key exists as a config value.
1118
* @param string config key
1120
* @return bool whether <config key> exists in this object
1124
function isDefined($key)
1126
foreach ($this->layers as $layer) {
1127
if (isset($this->configuration[$layer][$key])) {
1135
// {{{ isDefinedLayer(key)
1138
* Tells whether a given config layer exists.
1140
* @param string config layer
1142
* @return bool whether <config layer> exists in this object
1146
function isDefinedLayer($layer)
1148
return isset($this->configuration[$layer]);
1155
* Returns the layers defined (except the 'default' one)
1157
* @return array of the defined layers
1159
function getLayers()
1161
$cf = $this->configuration;
1162
unset($cf['default']);
1163
return array_keys($cf);