Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_Config, customized configuration handling for the PEAR Installer
3
 * PEAR_Config, customized configuration handling for the PEAR Installer
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: Config.php,v 1.137 2006/11/19 21:33:00 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
22
 */
15
 */
23
 
16
 
24
/**
17
/**
25
 * Required for error handling
18
 * Required for error handling
26
 */
19
 */
27
require_once 'PEAR.php';
20
require_once 'PEAR.php';
28
require_once 'PEAR/Registry.php';
21
require_once 'PEAR/Registry.php';
29
require_once 'PEAR/Installer/Role.php';
22
require_once 'PEAR/Installer/Role.php';
30
require_once 'System.php';
23
require_once 'System.php';
31
require_once 'PEAR/Remote.php';
-
 
32
 
24
 
33
/**
25
/**
34
 * Last created PEAR_Config instance.
26
 * Last created PEAR_Config instance.
35
 * @var object
27
 * @var object
36
 */
28
 */
37
$GLOBALS['_PEAR_Config_instance'] = null;
29
$GLOBALS['_PEAR_Config_instance'] = null;
38
if (!defined('PEAR_INSTALL_DIR') || !PEAR_INSTALL_DIR) {
30
if (!defined('PEAR_INSTALL_DIR') || !PEAR_INSTALL_DIR) {
39
    $PEAR_INSTALL_DIR = PHP_LIBDIR . DIRECTORY_SEPARATOR . 'pear';
31
    $PEAR_INSTALL_DIR = PHP_LIBDIR . DIRECTORY_SEPARATOR . 'pear';
40
} else {
32
} else {
41
    $PEAR_INSTALL_DIR = PEAR_INSTALL_DIR;
33
    $PEAR_INSTALL_DIR = PEAR_INSTALL_DIR;
42
}
34
}
43
 
35
 
44
// Below we define constants with default values for all configuration
36
// Below we define constants with default values for all configuration
45
// parameters except username/password.  All of them can have their
37
// parameters except username/password.  All of them can have their
46
// defaults set through environment variables.  The reason we use the
38
// defaults set through environment variables.  The reason we use the
47
// PHP_ prefix is for some security, PHP protects environment
39
// PHP_ prefix is for some security, PHP protects environment
48
// variables starting with PHP_*.
40
// variables starting with PHP_*.
49
 
41
 
50
// default channel and preferred mirror is based on whether we are invoked through
42
// default channel and preferred mirror is based on whether we are invoked through
51
// the "pear" or the "pecl" command
43
// the "pear" or the "pecl" command
-
 
44
if (!defined('PEAR_RUNTYPE')) {
-
 
45
    define('PEAR_RUNTYPE', 'pear');
-
 
46
}
52
 
47
 
53
if (!defined('PEAR_RUNTYPE') || PEAR_RUNTYPE == 'pear') {
48
if (PEAR_RUNTYPE == 'pear') {
54
    define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pear.php.net');
49
    define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pear.php.net');
55
} else {
50
} else {
56
    define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pecl.php.net');
51
    define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pecl.php.net');
57
}
52
}
58
 
53
 
59
if (getenv('PHP_PEAR_SYSCONF_DIR')) {
54
if (getenv('PHP_PEAR_SYSCONF_DIR')) {
60
    define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
55
    define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
61
} elseif (getenv('SystemRoot')) {
56
} elseif (getenv('SystemRoot')) {
62
    define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
57
    define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
63
} else {
58
} else {
64
    define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
59
    define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
65
}
60
}
66
 
61
 
67
// Default for master_server
62
// Default for master_server
68
if (getenv('PHP_PEAR_MASTER_SERVER')) {
63
if (getenv('PHP_PEAR_MASTER_SERVER')) {
69
    define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', getenv('PHP_PEAR_MASTER_SERVER'));
64
    define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', getenv('PHP_PEAR_MASTER_SERVER'));
70
} else {
65
} else {
71
    define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', 'pear.php.net');
66
    define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', 'pear.php.net');
72
}
67
}
73
 
68
 
74
// Default for http_proxy
69
// Default for http_proxy
75
if (getenv('PHP_PEAR_HTTP_PROXY')) {
70
if (getenv('PHP_PEAR_HTTP_PROXY')) {
76
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('PHP_PEAR_HTTP_PROXY'));
71
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('PHP_PEAR_HTTP_PROXY'));
77
} elseif (getenv('http_proxy')) {
72
} elseif (getenv('http_proxy')) {
78
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('http_proxy'));
73
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('http_proxy'));
79
} else {
74
} else {
80
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', '');
75
    define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', '');
81
}
76
}
82
 
77
 
83
// Default for php_dir
78
// Default for php_dir
84
if (getenv('PHP_PEAR_INSTALL_DIR')) {
79
if (getenv('PHP_PEAR_INSTALL_DIR')) {
85
    define('PEAR_CONFIG_DEFAULT_PHP_DIR', getenv('PHP_PEAR_INSTALL_DIR'));
80
    define('PEAR_CONFIG_DEFAULT_PHP_DIR', getenv('PHP_PEAR_INSTALL_DIR'));
86
} else {
81
} else {
87
    if (file_exists($PEAR_INSTALL_DIR) && is_dir($PEAR_INSTALL_DIR)) {
82
    if (@file_exists($PEAR_INSTALL_DIR) && is_dir($PEAR_INSTALL_DIR)) {
88
        define('PEAR_CONFIG_DEFAULT_PHP_DIR',
83
        define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
89
               $PEAR_INSTALL_DIR);
-
 
90
    } else {
84
    } else {
91
        define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
85
        define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
92
    }
86
    }
93
}
87
}
-
 
88
 
-
 
89
// Default for metadata_dir
-
 
90
if (getenv('PHP_PEAR_METADATA_DIR')) {
-
 
91
    define('PEAR_CONFIG_DEFAULT_METADATA_DIR', getenv('PHP_PEAR_METADATA_DIR'));
-
 
92
} else {
-
 
93
    define('PEAR_CONFIG_DEFAULT_METADATA_DIR', '');
-
 
94
}
94
 
95
 
95
// Default for ext_dir
96
// Default for ext_dir
96
if (getenv('PHP_PEAR_EXTENSION_DIR')) {
97
if (getenv('PHP_PEAR_EXTENSION_DIR')) {
97
    define('PEAR_CONFIG_DEFAULT_EXT_DIR', getenv('PHP_PEAR_EXTENSION_DIR'));
98
    define('PEAR_CONFIG_DEFAULT_EXT_DIR', getenv('PHP_PEAR_EXTENSION_DIR'));
98
} else {
99
} else {
99
    if (ini_get('extension_dir')) {
100
    if (ini_get('extension_dir')) {
100
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', ini_get('extension_dir'));
101
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', ini_get('extension_dir'));
101
    } elseif (defined('PEAR_EXTENSION_DIR') &&
102
    } elseif (defined('PEAR_EXTENSION_DIR') &&
102
              file_exists(PEAR_EXTENSION_DIR) && is_dir(PEAR_EXTENSION_DIR)) {
103
              file_exists(PEAR_EXTENSION_DIR) && is_dir(PEAR_EXTENSION_DIR)) {
103
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', PEAR_EXTENSION_DIR);
104
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', PEAR_EXTENSION_DIR);
104
    } elseif (defined('PHP_EXTENSION_DIR')) {
105
    } elseif (defined('PHP_EXTENSION_DIR')) {
105
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', PHP_EXTENSION_DIR);
106
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', PHP_EXTENSION_DIR);
106
    } else {
107
    } else {
107
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', '.');
108
        define('PEAR_CONFIG_DEFAULT_EXT_DIR', '.');
108
    }
109
    }
109
}
110
}
110
 
111
 
111
// Default for doc_dir
112
// Default for doc_dir
112
if (getenv('PHP_PEAR_DOC_DIR')) {
113
if (getenv('PHP_PEAR_DOC_DIR')) {
113
    define('PEAR_CONFIG_DEFAULT_DOC_DIR', getenv('PHP_PEAR_DOC_DIR'));
114
    define('PEAR_CONFIG_DEFAULT_DOC_DIR', getenv('PHP_PEAR_DOC_DIR'));
114
} else {
115
} else {
115
    define('PEAR_CONFIG_DEFAULT_DOC_DIR',
116
    define('PEAR_CONFIG_DEFAULT_DOC_DIR',
116
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'docs');
117
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'docs');
117
}
118
}
118
 
119
 
119
// Default for bin_dir
120
// Default for bin_dir
120
if (getenv('PHP_PEAR_BIN_DIR')) {
121
if (getenv('PHP_PEAR_BIN_DIR')) {
121
    define('PEAR_CONFIG_DEFAULT_BIN_DIR', getenv('PHP_PEAR_BIN_DIR'));
122
    define('PEAR_CONFIG_DEFAULT_BIN_DIR', getenv('PHP_PEAR_BIN_DIR'));
122
} else {
123
} else {
123
    define('PEAR_CONFIG_DEFAULT_BIN_DIR', PHP_BINDIR);
124
    define('PEAR_CONFIG_DEFAULT_BIN_DIR', PHP_BINDIR);
124
}
125
}
125
 
126
 
126
// Default for data_dir
127
// Default for data_dir
127
if (getenv('PHP_PEAR_DATA_DIR')) {
128
if (getenv('PHP_PEAR_DATA_DIR')) {
128
    define('PEAR_CONFIG_DEFAULT_DATA_DIR', getenv('PHP_PEAR_DATA_DIR'));
129
    define('PEAR_CONFIG_DEFAULT_DATA_DIR', getenv('PHP_PEAR_DATA_DIR'));
129
} else {
130
} else {
130
    define('PEAR_CONFIG_DEFAULT_DATA_DIR',
131
    define('PEAR_CONFIG_DEFAULT_DATA_DIR',
131
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'data');
132
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'data');
132
}
133
}
-
 
134
 
-
 
135
// Default for cfg_dir
-
 
136
if (getenv('PHP_PEAR_CFG_DIR')) {
-
 
137
    define('PEAR_CONFIG_DEFAULT_CFG_DIR', getenv('PHP_PEAR_CFG_DIR'));
-
 
138
} else {
-
 
139
    define('PEAR_CONFIG_DEFAULT_CFG_DIR',
-
 
140
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'cfg');
-
 
141
}
-
 
142
 
-
 
143
// Default for www_dir
-
 
144
if (getenv('PHP_PEAR_WWW_DIR')) {
-
 
145
    define('PEAR_CONFIG_DEFAULT_WWW_DIR', getenv('PHP_PEAR_WWW_DIR'));
-
 
146
} else {
-
 
147
    define('PEAR_CONFIG_DEFAULT_WWW_DIR',
-
 
148
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'www');
-
 
149
}
-
 
150
 
-
 
151
// Default for man_dir
-
 
152
if (getenv('PHP_PEAR_MAN_DIR')) {
-
 
153
    define('PEAR_CONFIG_DEFAULT_MAN_DIR', getenv('PHP_PEAR_MAN_DIR'));
-
 
154
} else {
-
 
155
    if (defined('PHP_MANDIR')) { // Added in PHP5.3.7
-
 
156
        define('PEAR_CONFIG_DEFAULT_MAN_DIR', PHP_MANDIR);
-
 
157
    } else {
-
 
158
        define('PEAR_CONFIG_DEFAULT_MAN_DIR', PHP_PREFIX . DIRECTORY_SEPARATOR .
-
 
159
           'local' . DIRECTORY_SEPARATOR .'man');
-
 
160
    }
-
 
161
}
133
 
162
 
134
// Default for test_dir
163
// Default for test_dir
135
if (getenv('PHP_PEAR_TEST_DIR')) {
164
if (getenv('PHP_PEAR_TEST_DIR')) {
136
    define('PEAR_CONFIG_DEFAULT_TEST_DIR', getenv('PHP_PEAR_TEST_DIR'));
165
    define('PEAR_CONFIG_DEFAULT_TEST_DIR', getenv('PHP_PEAR_TEST_DIR'));
137
} else {
166
} else {
138
    define('PEAR_CONFIG_DEFAULT_TEST_DIR',
167
    define('PEAR_CONFIG_DEFAULT_TEST_DIR',
139
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'tests');
168
           $PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'tests');
140
}
169
}
141
 
170
 
142
// Default for temp_dir
171
// Default for temp_dir
143
if (getenv('PHP_PEAR_TEMP_DIR')) {
172
if (getenv('PHP_PEAR_TEMP_DIR')) {
144
    define('PEAR_CONFIG_DEFAULT_TEMP_DIR', getenv('PHP_PEAR_TEMP_DIR'));
173
    define('PEAR_CONFIG_DEFAULT_TEMP_DIR', getenv('PHP_PEAR_TEMP_DIR'));
145
} else {
174
} else {
146
    define('PEAR_CONFIG_DEFAULT_TEMP_DIR',
175
    define('PEAR_CONFIG_DEFAULT_TEMP_DIR',
147
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
176
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
148
           DIRECTORY_SEPARATOR . 'temp');
177
           DIRECTORY_SEPARATOR . 'temp');
149
}
178
}
150
 
179
 
151
// Default for cache_dir
180
// Default for cache_dir
152
if (getenv('PHP_PEAR_CACHE_DIR')) {
181
if (getenv('PHP_PEAR_CACHE_DIR')) {
153
    define('PEAR_CONFIG_DEFAULT_CACHE_DIR', getenv('PHP_PEAR_CACHE_DIR'));
182
    define('PEAR_CONFIG_DEFAULT_CACHE_DIR', getenv('PHP_PEAR_CACHE_DIR'));
154
} else {
183
} else {
155
    define('PEAR_CONFIG_DEFAULT_CACHE_DIR',
184
    define('PEAR_CONFIG_DEFAULT_CACHE_DIR',
156
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
185
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
157
           DIRECTORY_SEPARATOR . 'cache');
186
           DIRECTORY_SEPARATOR . 'cache');
158
}
187
}
159
 
188
 
160
// Default for download_dir
189
// Default for download_dir
161
if (getenv('PHP_PEAR_DOWNLOAD_DIR')) {
190
if (getenv('PHP_PEAR_DOWNLOAD_DIR')) {
162
    define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR', getenv('PHP_PEAR_DOWNLOAD_DIR'));
191
    define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR', getenv('PHP_PEAR_DOWNLOAD_DIR'));
163
} else {
192
} else {
164
    define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR',
193
    define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR',
165
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
194
           System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
166
           DIRECTORY_SEPARATOR . 'download');
195
           DIRECTORY_SEPARATOR . 'download');
167
}
196
}
168
 
197
 
169
// Default for php_bin
198
// Default for php_bin
170
if (getenv('PHP_PEAR_PHP_BIN')) {
199
if (getenv('PHP_PEAR_PHP_BIN')) {
171
    define('PEAR_CONFIG_DEFAULT_PHP_BIN', getenv('PHP_PEAR_PHP_BIN'));
200
    define('PEAR_CONFIG_DEFAULT_PHP_BIN', getenv('PHP_PEAR_PHP_BIN'));
172
} else {
201
} else {
173
    define('PEAR_CONFIG_DEFAULT_PHP_BIN', PEAR_CONFIG_DEFAULT_BIN_DIR.
202
    define('PEAR_CONFIG_DEFAULT_PHP_BIN', PEAR_CONFIG_DEFAULT_BIN_DIR.
174
           DIRECTORY_SEPARATOR.'php'.(OS_WINDOWS ? '.exe' : ''));
203
           DIRECTORY_SEPARATOR.'php'.(OS_WINDOWS ? '.exe' : ''));
175
}
204
}
176
 
205
 
177
// Default for verbose
206
// Default for verbose
178
if (getenv('PHP_PEAR_VERBOSE')) {
207
if (getenv('PHP_PEAR_VERBOSE')) {
179
    define('PEAR_CONFIG_DEFAULT_VERBOSE', getenv('PHP_PEAR_VERBOSE'));
208
    define('PEAR_CONFIG_DEFAULT_VERBOSE', getenv('PHP_PEAR_VERBOSE'));
180
} else {
209
} else {
181
    define('PEAR_CONFIG_DEFAULT_VERBOSE', 1);
210
    define('PEAR_CONFIG_DEFAULT_VERBOSE', 1);
182
}
211
}
183
 
212
 
184
// Default for preferred_state
213
// Default for preferred_state
185
if (getenv('PHP_PEAR_PREFERRED_STATE')) {
214
if (getenv('PHP_PEAR_PREFERRED_STATE')) {
186
    define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', getenv('PHP_PEAR_PREFERRED_STATE'));
215
    define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', getenv('PHP_PEAR_PREFERRED_STATE'));
187
} else {
216
} else {
188
    define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', 'stable');
217
    define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', 'stable');
189
}
218
}
190
 
219
 
191
// Default for umask
220
// Default for umask
192
if (getenv('PHP_PEAR_UMASK')) {
221
if (getenv('PHP_PEAR_UMASK')) {
193
    define('PEAR_CONFIG_DEFAULT_UMASK', getenv('PHP_PEAR_UMASK'));
222
    define('PEAR_CONFIG_DEFAULT_UMASK', getenv('PHP_PEAR_UMASK'));
194
} else {
223
} else {
195
    define('PEAR_CONFIG_DEFAULT_UMASK', decoct(umask()));
224
    define('PEAR_CONFIG_DEFAULT_UMASK', decoct(umask()));
196
}
225
}
197
 
226
 
198
// Default for cache_ttl
227
// Default for cache_ttl
199
if (getenv('PHP_PEAR_CACHE_TTL')) {
228
if (getenv('PHP_PEAR_CACHE_TTL')) {
200
    define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL'));
229
    define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL'));
201
} else {
230
} else {
202
    define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600);
231
    define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600);
203
}
232
}
204
 
233
 
205
// Default for sig_type
234
// Default for sig_type
206
if (getenv('PHP_PEAR_SIG_TYPE')) {
235
if (getenv('PHP_PEAR_SIG_TYPE')) {
207
    define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE'));
236
    define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE'));
208
} else {
237
} else {
209
    define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg');
238
    define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg');
210
}
239
}
211
 
240
 
212
// Default for sig_bin
241
// Default for sig_bin
213
if (getenv('PHP_PEAR_SIG_BIN')) {
242
if (getenv('PHP_PEAR_SIG_BIN')) {
214
    define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN'));
243
    define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN'));
215
} else {
244
} else {
216
    define('PEAR_CONFIG_DEFAULT_SIG_BIN',
245
    define('PEAR_CONFIG_DEFAULT_SIG_BIN',
217
           System::which(
246
           System::which(
218
               'gpg', OS_WINDOWS ? 'c:\gnupg\gpg.exe' : '/usr/local/bin/gpg'));
247
               'gpg', OS_WINDOWS ? 'c:\gnupg\gpg.exe' : '/usr/local/bin/gpg'));
219
}
248
}
220
 
249
 
221
// Default for sig_keydir
250
// Default for sig_keydir
222
if (getenv('PHP_PEAR_SIG_KEYDIR')) {
251
if (getenv('PHP_PEAR_SIG_KEYDIR')) {
223
    define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR'));
252
    define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR'));
224
} else {
253
} else {
225
    define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR',
254
    define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR',
226
           PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys');
255
           PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys');
227
}
256
}
228
 
257
 
229
/**
258
/**
230
 * This is a class for storing configuration data, keeping track of
259
 * This is a class for storing configuration data, keeping track of
231
 * which are system-defined, user-defined or defaulted.
260
 * which are system-defined, user-defined or defaulted.
232
 * @category   pear
261
 * @category   pear
233
 * @package    PEAR
262
 * @package    PEAR
234
 * @author     Stig Bakken <ssb@php.net>
263
 * @author     Stig Bakken <ssb@php.net>
235
 * @author     Greg Beaver <cellog@php.net>
264
 * @author     Greg Beaver <cellog@php.net>
236
 * @copyright  1997-2006 The PHP Group
265
 * @copyright  1997-2009 The Authors
237
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
266
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
238
 * @version    Release: 1.5.1
267
 * @version    Release: 1.10.1
239
 * @link       http://pear.php.net/package/PEAR
268
 * @link       http://pear.php.net/package/PEAR
240
 * @since      Class available since Release 0.1
269
 * @since      Class available since Release 0.1
241
 */
270
 */
242
class PEAR_Config extends PEAR
271
class PEAR_Config extends PEAR
243
{
272
{
244
    // {{{ properties
-
 
245
 
-
 
246
    /**
273
    /**
247
     * Array of config files used.
274
     * Array of config files used.
248
     *
275
     *
249
     * @var array layer => config file
276
     * @var array layer => config file
250
     */
277
     */
251
    var $files = array(
278
    var $files = array(
252
        'system' => '',
279
        'system' => '',
253
        'user' => '',
280
        'user' => '',
254
        );
281
        );
255
 
282
 
256
    var $layers = array();
283
    var $layers = array();
257
    
284
 
258
    /**
285
    /**
259
     * Configuration data, two-dimensional array where the first
286
     * Configuration data, two-dimensional array where the first
260
     * dimension is the config layer ('user', 'system' and 'default'),
287
     * dimension is the config layer ('user', 'system' and 'default'),
261
     * and the second dimension is keyname => value.
288
     * and the second dimension is keyname => value.
262
     *
289
     *
263
     * The order in the first dimension is important!  Earlier
290
     * The order in the first dimension is important!  Earlier
264
     * layers will shadow later ones when a config value is
291
     * layers will shadow later ones when a config value is
265
     * requested (if a 'user' value exists, it will be returned first,
292
     * requested (if a 'user' value exists, it will be returned first,
266
     * then 'system' and finally 'default').
293
     * then 'system' and finally 'default').
267
     *
294
     *
268
     * @var array layer => array(keyname => value, ...)
295
     * @var array layer => array(keyname => value, ...)
269
     */
296
     */
270
    var $configuration = array(
297
    var $configuration = array(
271
        'user' => array(),
298
        'user' => array(),
272
        'system' => array(),
299
        'system' => array(),
273
        'default' => array(),
300
        'default' => array(),
274
        );
301
        );
275
    
302
 
276
    /**
303
    /**
277
     * Configuration values that can be set for a channel
304
     * Configuration values that can be set for a channel
278
     *
305
     *
279
     * All other configuration values can only have a global value
306
     * All other configuration values can only have a global value
280
     * @var array
307
     * @var array
281
     * @access private
308
     * @access private
282
     */
309
     */
283
    var $_channelConfigInfo = array(
310
    var $_channelConfigInfo = array(
284
        'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir',
311
        'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'cfg_dir',
285
        'test_dir', 'php_bin', 'username', 'password', 'verbose',
312
        'test_dir', 'www_dir', 'php_bin', 'php_prefix', 'php_suffix', 'username',
286
        'preferred_state', 'umask', 'preferred_mirror',
313
        'password', 'verbose', 'preferred_state', 'umask', 'preferred_mirror', 'php_ini'
287
        );
314
        );
288
 
315
 
289
    /**
316
    /**
290
     * Channels that can be accessed
317
     * Channels that can be accessed
291
     * @see setChannels()
318
     * @see setChannels()
292
     * @var array
319
     * @var array
293
     * @access private
320
     * @access private
294
     */
321
     */
295
    var $_channels = array('pear.php.net', 'pecl.php.net', '__uri');
322
    var $_channels = array('pear.php.net', 'pecl.php.net', '__uri');
296
 
323
 
297
    /**
324
    /**
298
     * This variable is used to control the directory values returned
325
     * This variable is used to control the directory values returned
299
     * @see setInstallRoot();
326
     * @see setInstallRoot();
300
     * @var string|false
327
     * @var string|false
301
     * @access private
328
     * @access private
302
     */
329
     */
303
    var $_installRoot = false;
330
    var $_installRoot = false;
304
 
331
 
305
    /**
332
    /**
306
     * If requested, this will always refer to the registry
333
     * If requested, this will always refer to the registry
307
     * contained in php_dir
334
     * contained in php_dir
308
     * @var PEAR_Registry
335
     * @var PEAR_Registry
309
     */
336
     */
310
    var $_registry = array();
337
    var $_registry = array();
311
 
338
 
312
    /**
339
    /**
313
     * @var array
340
     * @var array
314
     * @access private
341
     * @access private
315
     */
342
     */
316
    var $_regInitialized = array();
343
    var $_regInitialized = array();
317
 
344
 
318
    /**
345
    /**
319
     * @var bool
346
     * @var bool
320
     * @access private
347
     * @access private
321
     */
348
     */
322
    var $_noRegistry = false;
349
    var $_noRegistry = false;
323
 
350
 
324
    /**
351
    /**
325
     * amount of errors found while parsing config
352
     * amount of errors found while parsing config
326
     * @var integer
353
     * @var integer
327
     * @access private
354
     * @access private
328
     */
355
     */
329
    var $_errorsFound = 0;
356
    var $_errorsFound = 0;
330
    var $_lastError = null;
357
    var $_lastError = null;
331
 
358
 
332
    /**
359
    /**
333
     * Information about the configuration data.  Stores the type,
360
     * Information about the configuration data.  Stores the type,
334
     * default value and a documentation string for each configuration
361
     * default value and a documentation string for each configuration
335
     * value.
362
     * value.
336
     *
363
     *
337
     * @var array layer => array(infotype => value, ...)
364
     * @var array layer => array(infotype => value, ...)
338
     */
365
     */
339
    var $configuration_info = array(
366
    var $configuration_info = array(
340
        // Channels/Internet Access
367
        // Channels/Internet Access
341
        'default_channel' => array(
368
        'default_channel' => array(
342
            'type' => 'string',
369
            'type' => 'string',
343
            'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
370
            'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
344
            'doc' => 'the default channel to use for all non explicit commands',
371
            'doc' => 'the default channel to use for all non explicit commands',
345
            'prompt' => 'Default Channel',
372
            'prompt' => 'Default Channel',
346
            'group' => 'Internet Access',
373
            'group' => 'Internet Access',
347
            ),
374
            ),
348
        'preferred_mirror' => array(
375
        'preferred_mirror' => array(
349
            'type' => 'string',
376
            'type' => 'string',
350
            'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
377
            'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
351
            'doc' => 'the default server or mirror to use for channel actions',
378
            'doc' => 'the default server or mirror to use for channel actions',
352
            'prompt' => 'Default Channel Mirror',
379
            'prompt' => 'Default Channel Mirror',
353
            'group' => 'Internet Access',
380
            'group' => 'Internet Access',
354
            ),
381
            ),
355
        'remote_config' => array(
382
        'remote_config' => array(
356
            'type' => 'password',
383
            'type' => 'password',
357
            'default' => '',
384
            'default' => '',
358
            'doc' => 'ftp url of remote configuration file to use for synchronized install',
385
            'doc' => 'ftp url of remote configuration file to use for synchronized install',
359
            'prompt' => 'Remote Configuration File',
386
            'prompt' => 'Remote Configuration File',
360
            'group' => 'Internet Access',
387
            'group' => 'Internet Access',
361
            ),
388
            ),
362
        'auto_discover' => array(
389
        'auto_discover' => array(
363
            'type' => 'integer',
390
            'type' => 'integer',
364
            'default' => 0,
391
            'default' => 0,
365
            'doc' => 'whether to automatically discover new channels',
392
            'doc' => 'whether to automatically discover new channels',
366
            'prompt' => 'Auto-discover new Channels',
393
            'prompt' => 'Auto-discover new Channels',
367
            'group' => 'Internet Access',
394
            'group' => 'Internet Access',
368
            ),
395
            ),
369
        // Internet Access
396
        // Internet Access
370
        'master_server' => array(
397
        'master_server' => array(
371
            'type' => 'string',
398
            'type' => 'string',
372
            'default' => 'pear.php.net',
399
            'default' => 'pear.php.net',
373
            'doc' => 'name of the main PEAR server [NOT USED IN THIS VERSION]',
400
            'doc' => 'name of the main PEAR server [NOT USED IN THIS VERSION]',
374
            'prompt' => 'PEAR server [DEPRECATED]',
401
            'prompt' => 'PEAR server [DEPRECATED]',
375
            'group' => 'Internet Access',
402
            'group' => 'Internet Access',
376
            ),
403
            ),
377
        'http_proxy' => array(
404
        'http_proxy' => array(
378
            'type' => 'string',
405
            'type' => 'string',
379
            'default' => PEAR_CONFIG_DEFAULT_HTTP_PROXY,
406
            'default' => PEAR_CONFIG_DEFAULT_HTTP_PROXY,
380
            'doc' => 'HTTP proxy (host:port) to use when downloading packages',
407
            'doc' => 'HTTP proxy (host:port) to use when downloading packages',
381
            'prompt' => 'HTTP Proxy Server Address',
408
            'prompt' => 'HTTP Proxy Server Address',
382
            'group' => 'Internet Access',
409
            'group' => 'Internet Access',
383
            ),
410
            ),
384
        // File Locations
411
        // File Locations
385
        'php_dir' => array(
412
        'php_dir' => array(
386
            'type' => 'directory',
413
            'type' => 'directory',
387
            'default' => PEAR_CONFIG_DEFAULT_PHP_DIR,
414
            'default' => PEAR_CONFIG_DEFAULT_PHP_DIR,
388
            'doc' => 'directory where .php files are installed',
415
            'doc' => 'directory where .php files are installed',
389
            'prompt' => 'PEAR directory',
416
            'prompt' => 'PEAR directory',
390
            'group' => 'File Locations',
417
            'group' => 'File Locations',
391
            ),
418
            ),
392
        'ext_dir' => array(
419
        'ext_dir' => array(
393
            'type' => 'directory',
420
            'type' => 'directory',
394
            'default' => PEAR_CONFIG_DEFAULT_EXT_DIR,
421
            'default' => PEAR_CONFIG_DEFAULT_EXT_DIR,
395
            'doc' => 'directory where loadable extensions are installed',
422
            'doc' => 'directory where loadable extensions are installed',
396
            'prompt' => 'PHP extension directory',
423
            'prompt' => 'PHP extension directory',
397
            'group' => 'File Locations',
424
            'group' => 'File Locations',
398
            ),
425
            ),
399
        'doc_dir' => array(
426
        'doc_dir' => array(
400
            'type' => 'directory',
427
            'type' => 'directory',
401
            'default' => PEAR_CONFIG_DEFAULT_DOC_DIR,
428
            'default' => PEAR_CONFIG_DEFAULT_DOC_DIR,
402
            'doc' => 'directory where documentation is installed',
429
            'doc' => 'directory where documentation is installed',
403
            'prompt' => 'PEAR documentation directory',
430
            'prompt' => 'PEAR documentation directory',
404
            'group' => 'File Locations',
431
            'group' => 'File Locations',
405
            ),
432
            ),
406
        'bin_dir' => array(
433
        'bin_dir' => array(
407
            'type' => 'directory',
434
            'type' => 'directory',
408
            'default' => PEAR_CONFIG_DEFAULT_BIN_DIR,
435
            'default' => PEAR_CONFIG_DEFAULT_BIN_DIR,
409
            'doc' => 'directory where executables are installed',
436
            'doc' => 'directory where executables are installed',
410
            'prompt' => 'PEAR executables directory',
437
            'prompt' => 'PEAR executables directory',
411
            'group' => 'File Locations',
438
            'group' => 'File Locations',
412
            ),
439
            ),
413
        'data_dir' => array(
440
        'data_dir' => array(
414
            'type' => 'directory',
441
            'type' => 'directory',
415
            'default' => PEAR_CONFIG_DEFAULT_DATA_DIR,
442
            'default' => PEAR_CONFIG_DEFAULT_DATA_DIR,
416
            'doc' => 'directory where data files are installed',
443
            'doc' => 'directory where data files are installed',
417
            'prompt' => 'PEAR data directory',
444
            'prompt' => 'PEAR data directory',
418
            'group' => 'File Locations (Advanced)',
445
            'group' => 'File Locations (Advanced)',
419
            ),
446
            ),
-
 
447
        'cfg_dir' => array(
-
 
448
            'type' => 'directory',
-
 
449
            'default' => PEAR_CONFIG_DEFAULT_CFG_DIR,
-
 
450
            'doc' => 'directory where modifiable configuration files are installed',
-
 
451
            'prompt' => 'PEAR configuration file directory',
-
 
452
            'group' => 'File Locations (Advanced)',
-
 
453
            ),
-
 
454
        'www_dir' => array(
-
 
455
            'type' => 'directory',
-
 
456
            'default' => PEAR_CONFIG_DEFAULT_WWW_DIR,
-
 
457
            'doc' => 'directory where www frontend files (html/js) are installed',
-
 
458
            'prompt' => 'PEAR www files directory',
-
 
459
            'group' => 'File Locations (Advanced)',
-
 
460
            ),
-
 
461
        'man_dir' => array(
-
 
462
            'type' => 'directory',
-
 
463
            'default' => PEAR_CONFIG_DEFAULT_MAN_DIR,
-
 
464
            'doc' => 'directory where unix manual pages are installed',
-
 
465
            'prompt' => 'Systems manpage files directory',
-
 
466
            'group' => 'File Locations (Advanced)',
-
 
467
            ),
420
        'test_dir' => array(
468
        'test_dir' => array(
421
            'type' => 'directory',
469
            'type' => 'directory',
422
            'default' => PEAR_CONFIG_DEFAULT_TEST_DIR,
470
            'default' => PEAR_CONFIG_DEFAULT_TEST_DIR,
423
            'doc' => 'directory where regression tests are installed',
471
            'doc' => 'directory where regression tests are installed',
424
            'prompt' => 'PEAR test directory',
472
            'prompt' => 'PEAR test directory',
425
            'group' => 'File Locations (Advanced)',
473
            'group' => 'File Locations (Advanced)',
426
            ),
474
            ),
427
        'cache_dir' => array(
475
        'cache_dir' => array(
428
            'type' => 'directory',
476
            'type' => 'directory',
429
            'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
477
            'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
430
            'doc' => 'directory which is used for XMLRPC cache',
478
            'doc' => 'directory which is used for web service cache',
431
            'prompt' => 'PEAR Installer cache directory',
479
            'prompt' => 'PEAR Installer cache directory',
432
            'group' => 'File Locations (Advanced)',
480
            'group' => 'File Locations (Advanced)',
433
            ),
481
            ),
434
        'temp_dir' => array(
482
        'temp_dir' => array(
435
            'type' => 'directory',
483
            'type' => 'directory',
436
            'default' => PEAR_CONFIG_DEFAULT_TEMP_DIR,
484
            'default' => PEAR_CONFIG_DEFAULT_TEMP_DIR,
437
            'doc' => 'directory which is used for all temp files',
485
            'doc' => 'directory which is used for all temp files',
438
            'prompt' => 'PEAR Installer temp directory',
486
            'prompt' => 'PEAR Installer temp directory',
439
            'group' => 'File Locations (Advanced)',
487
            'group' => 'File Locations (Advanced)',
440
            ),
488
            ),
441
        'download_dir' => array(
489
        'download_dir' => array(
442
            'type' => 'directory',
490
            'type' => 'directory',
443
            'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
491
            'default' => PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR,
444
            'doc' => 'directory which is used for all downloaded files',
492
            'doc' => 'directory which is used for all downloaded files',
445
            'prompt' => 'PEAR Installer download directory',
493
            'prompt' => 'PEAR Installer download directory',
446
            'group' => 'File Locations (Advanced)',
494
            'group' => 'File Locations (Advanced)',
447
            ),
495
            ),
448
        'php_bin' => array(
496
        'php_bin' => array(
449
            'type' => 'file',
497
            'type' => 'file',
450
            'default' => PEAR_CONFIG_DEFAULT_PHP_BIN,
498
            'default' => PEAR_CONFIG_DEFAULT_PHP_BIN,
451
            'doc' => 'PHP CLI/CGI binary for executing scripts',
499
            'doc' => 'PHP CLI/CGI binary for executing scripts',
452
            'prompt' => 'PHP CLI/CGI binary',
500
            'prompt' => 'PHP CLI/CGI binary',
453
            'group' => 'File Locations (Advanced)',
501
            'group' => 'File Locations (Advanced)',
454
            ),
502
            ),
-
 
503
        'php_prefix' => array(
-
 
504
            'type' => 'string',
-
 
505
            'default' => '',
-
 
506
            'doc' => '--program-prefix for php_bin\'s ./configure, used for pecl installs',
-
 
507
            'prompt' => '--program-prefix passed to PHP\'s ./configure',
-
 
508
            'group' => 'File Locations (Advanced)',
-
 
509
            ),
-
 
510
        'php_suffix' => array(
-
 
511
            'type' => 'string',
-
 
512
            'default' => '',
-
 
513
            'doc' => '--program-suffix for php_bin\'s ./configure, used for pecl installs',
-
 
514
            'prompt' => '--program-suffix passed to PHP\'s ./configure',
-
 
515
            'group' => 'File Locations (Advanced)',
-
 
516
            ),
455
        'php_ini' => array(
517
        'php_ini' => array(
456
            'type' => 'file',
518
            'type' => 'file',
457
            'default' => '',
519
            'default' => '',
458
            'doc' => 'location of php.ini in which to enable PECL extensions on install',
520
            'doc' => 'location of php.ini in which to enable PECL extensions on install',
459
            'prompt' => 'php.ini location',
521
            'prompt' => 'php.ini location',
460
            'group' => 'File Locations (Advanced)',
522
            'group' => 'File Locations (Advanced)',
461
            ),
523
            ),
-
 
524
        'metadata_dir' => array(
-
 
525
            'type' => 'directory',
-
 
526
            'default' => PEAR_CONFIG_DEFAULT_METADATA_DIR,
-
 
527
            'doc' => 'directory where metadata files are installed (registry, filemap, channels, ...)',
-
 
528
            'prompt' => 'PEAR metadata directory',
-
 
529
            'group' => 'File Locations (Advanced)',
-
 
530
            ),
462
        // Maintainers
531
        // Maintainers
463
        'username' => array(
532
        'username' => array(
464
            'type' => 'string',
533
            'type' => 'string',
465
            'default' => '',
534
            'default' => '',
466
            'doc' => '(maintainers) your PEAR account name',
535
            'doc' => '(maintainers) your PEAR account name',
467
            'prompt' => 'PEAR username (for maintainers)',
536
            'prompt' => 'PEAR username (for maintainers)',
468
            'group' => 'Maintainers',
537
            'group' => 'Maintainers',
469
            ),
538
            ),
470
        'password' => array(
539
        'password' => array(
471
            'type' => 'password',
540
            'type' => 'password',
472
            'default' => '',
541
            'default' => '',
473
            'doc' => '(maintainers) your PEAR account password',
542
            'doc' => '(maintainers) your PEAR account password',
474
            'prompt' => 'PEAR password (for maintainers)',
543
            'prompt' => 'PEAR password (for maintainers)',
475
            'group' => 'Maintainers',
544
            'group' => 'Maintainers',
476
            ),
545
            ),
477
        // Advanced
546
        // Advanced
478
        'verbose' => array(
547
        'verbose' => array(
479
            'type' => 'integer',
548
            'type' => 'integer',
480
            'default' => PEAR_CONFIG_DEFAULT_VERBOSE,
549
            'default' => PEAR_CONFIG_DEFAULT_VERBOSE,
481
            'doc' => 'verbosity level
550
            'doc' => 'verbosity level
482
0: really quiet
551
0: really quiet
483
1: somewhat quiet
552
1: somewhat quiet
484
2: verbose
553
2: verbose
485
3: debug',
554
3: debug',
486
            'prompt' => 'Debug Log Level',
555
            'prompt' => 'Debug Log Level',
487
            'group' => 'Advanced',
556
            'group' => 'Advanced',
488
            ),
557
            ),
489
        'preferred_state' => array(
558
        'preferred_state' => array(
490
            'type' => 'set',
559
            'type' => 'set',
491
            'default' => PEAR_CONFIG_DEFAULT_PREFERRED_STATE,
560
            'default' => PEAR_CONFIG_DEFAULT_PREFERRED_STATE,
492
            'doc' => 'the installer will prefer releases with this state when installing packages without a version or state specified',
561
            'doc' => 'the installer will prefer releases with this state when installing packages without a version or state specified',
493
            'valid_set' => array(
562
            'valid_set' => array(
494
                'stable', 'beta', 'alpha', 'devel', 'snapshot'),
563
                'stable', 'beta', 'alpha', 'devel', 'snapshot'),
495
            'prompt' => 'Preferred Package State',
564
            'prompt' => 'Preferred Package State',
496
            'group' => 'Advanced',
565
            'group' => 'Advanced',
497
            ),
566
            ),
498
        'umask' => array(
567
        'umask' => array(
499
            'type' => 'mask',
568
            'type' => 'mask',
500
            'default' => PEAR_CONFIG_DEFAULT_UMASK,
569
            'default' => PEAR_CONFIG_DEFAULT_UMASK,
501
            'doc' => 'umask used when creating files (Unix-like systems only)',
570
            'doc' => 'umask used when creating files (Unix-like systems only)',
502
            'prompt' => 'Unix file mask',
571
            'prompt' => 'Unix file mask',
503
            'group' => 'Advanced',
572
            'group' => 'Advanced',
504
            ),
573
            ),
505
        'cache_ttl' => array(
574
        'cache_ttl' => array(
506
            'type' => 'integer',
575
            'type' => 'integer',
507
            'default' => PEAR_CONFIG_DEFAULT_CACHE_TTL,
576
            'default' => PEAR_CONFIG_DEFAULT_CACHE_TTL,
508
            'doc' => 'amount of secs where the local cache is used and not updated',
577
            'doc' => 'amount of secs where the local cache is used and not updated',
509
            'prompt' => 'Cache TimeToLive',
578
            'prompt' => 'Cache TimeToLive',
510
            'group' => 'Advanced',
579
            'group' => 'Advanced',
511
            ),
580
            ),
512
        'sig_type' => array(
581
        'sig_type' => array(
513
            'type' => 'set',
582
            'type' => 'set',
514
            'default' => PEAR_CONFIG_DEFAULT_SIG_TYPE,
583
            'default' => PEAR_CONFIG_DEFAULT_SIG_TYPE,
515
            'doc' => 'which package signature mechanism to use',
584
            'doc' => 'which package signature mechanism to use',
516
            'valid_set' => array('gpg'),
585
            'valid_set' => array('gpg'),
517
            'prompt' => 'Package Signature Type',
586
            'prompt' => 'Package Signature Type',
518
            'group' => 'Maintainers',
587
            'group' => 'Maintainers',
519
            ),
588
            ),
520
        'sig_bin' => array(
589
        'sig_bin' => array(
521
            'type' => 'string',
590
            'type' => 'string',
522
            'default' => PEAR_CONFIG_DEFAULT_SIG_BIN,
591
            'default' => PEAR_CONFIG_DEFAULT_SIG_BIN,
523
            'doc' => 'which package signature mechanism to use',
592
            'doc' => 'which package signature mechanism to use',
524
            'prompt' => 'Signature Handling Program',
593
            'prompt' => 'Signature Handling Program',
525
            'group' => 'Maintainers',
594
            'group' => 'Maintainers',
526
            ),
595
            ),
527
        'sig_keyid' => array(
596
        'sig_keyid' => array(
528
            'type' => 'string',
597
            'type' => 'string',
529
            'default' => '',
598
            'default' => '',
530
            'doc' => 'which key to use for signing with',
599
            'doc' => 'which key to use for signing with',
531
            'prompt' => 'Signature Key Id',
600
            'prompt' => 'Signature Key Id',
532
            'group' => 'Maintainers',
601
            'group' => 'Maintainers',
533
            ),
602
            ),
534
        'sig_keydir' => array(
603
        'sig_keydir' => array(
535
            'type' => 'directory',
604
            'type' => 'directory',
536
            'default' => PEAR_CONFIG_DEFAULT_SIG_KEYDIR,
605
            'default' => PEAR_CONFIG_DEFAULT_SIG_KEYDIR,
537
            'doc' => 'directory where signature keys are located',
606
            'doc' => 'directory where signature keys are located',
538
            'prompt' => 'Signature Key Directory',
607
            'prompt' => 'Signature Key Directory',
539
            'group' => 'Maintainers',
608
            'group' => 'Maintainers',
540
            ),
609
            ),
541
        // __channels is reserved - used for channel-specific configuration
610
        // __channels is reserved - used for channel-specific configuration
542
        );
611
        );
543
 
-
 
544
    // }}}
-
 
545
 
-
 
546
    // {{{ PEAR_Config([file], [defaults_file])
-
 
547
 
612
 
548
    /**
613
    /**
549
     * Constructor.
614
     * Constructor.
550
     *
615
     *
551
     * @param string file to read user-defined options from
616
     * @param string file to read user-defined options from
552
     * @param string file to read system-wide defaults from
617
     * @param string file to read system-wide defaults from
553
     * @param bool   determines whether a registry object "follows"
618
     * @param bool   determines whether a registry object "follows"
554
     *               the value of php_dir (is automatically created
619
     *               the value of php_dir (is automatically created
555
     *               and moved when php_dir is changed)
620
     *               and moved when php_dir is changed)
556
     * @param bool   if true, fails if configuration files cannot be loaded
621
     * @param bool   if true, fails if configuration files cannot be loaded
557
     *
622
     *
558
     * @access public
623
     * @access public
559
     *
624
     *
560
     * @see PEAR_Config::singleton
625
     * @see PEAR_Config::singleton
561
     */
626
     */
562
    function PEAR_Config($user_file = '', $system_file = '', $ftp_file = false,
627
    function __construct($user_file = '', $system_file = '', $ftp_file = false,
563
                         $strict = true)
628
                         $strict = true)
564
    {
629
    {
565
        $this->PEAR();
630
        parent::__construct();
566
        PEAR_Installer_Role::initializeConfig($this);
631
        PEAR_Installer_Role::initializeConfig($this);
567
        $sl = DIRECTORY_SEPARATOR;
632
        $sl = DIRECTORY_SEPARATOR;
568
        if (empty($user_file)) {
633
        if (empty($user_file)) {
569
            if (OS_WINDOWS) {
634
            if (OS_WINDOWS) {
570
                $user_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini';
635
                $user_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini';
571
            } else {
636
            } else {
572
                $user_file = getenv('HOME') . $sl . '.pearrc';
637
                $user_file = getenv('HOME') . $sl . '.pearrc';
573
            }
638
            }
574
        }
639
        }
-
 
640
 
575
        if (empty($system_file)) {
641
        if (empty($system_file)) {
-
 
642
            $system_file = PEAR_CONFIG_SYSCONFDIR . $sl;
576
            if (OS_WINDOWS) {
643
            if (OS_WINDOWS) {
577
                $system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini';
644
                $system_file .= 'pearsys.ini';
578
            } else {
645
            } else {
579
                $system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf';
646
                $system_file .= 'pear.conf';
580
            }
647
            }
581
        }
648
        }
582
 
649
 
583
        $this->layers = array_keys($this->configuration);
650
        $this->layers = array_keys($this->configuration);
584
        $this->files['user'] = $user_file;
651
        $this->files['user']   = $user_file;
585
        $this->files['system'] = $system_file;
652
        $this->files['system'] = $system_file;
586
        if ($user_file && file_exists($user_file)) {
653
        if ($user_file && file_exists($user_file)) {
587
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
654
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
588
            $this->readConfigFile($user_file, 'user', $strict);
655
            $this->readConfigFile($user_file, 'user', $strict);
589
            $this->popErrorHandling();
656
            $this->popErrorHandling();
590
            if ($this->_errorsFound > 0) {
657
            if ($this->_errorsFound > 0) {
591
                return;
658
                return;
592
            }
659
            }
593
        }
660
        }
594
 
661
 
595
        if ($system_file && file_exists($system_file)) {
662
        if ($system_file && @file_exists($system_file)) {
596
            $this->mergeConfigFile($system_file, false, 'system', $strict);
663
            $this->mergeConfigFile($system_file, false, 'system', $strict);
597
            if ($this->_errorsFound > 0) {
664
            if ($this->_errorsFound > 0) {
598
                return;
665
                return;
599
            }
666
            }
600
 
667
 
601
        }
668
        }
602
 
669
 
603
        if (!$ftp_file) {
670
        if (!$ftp_file) {
604
            $ftp_file = $this->get('remote_config');
671
            $ftp_file = $this->get('remote_config');
605
        }
672
        }
606
 
673
 
607
        if ($ftp_file && defined('PEAR_REMOTEINSTALL_OK')) {
674
        if ($ftp_file && defined('PEAR_REMOTEINSTALL_OK')) {
608
            $this->readFTPConfigFile($ftp_file);
675
            $this->readFTPConfigFile($ftp_file);
609
        }
676
        }
610
 
677
 
611
        foreach ($this->configuration_info as $key => $info) {
678
        foreach ($this->configuration_info as $key => $info) {
612
            $this->configuration['default'][$key] = $info['default'];
679
            $this->configuration['default'][$key] = $info['default'];
613
        }
680
        }
614
 
681
 
-
 
682
        $this->_registry['default'] = new PEAR_Registry(
-
 
683
            $this->configuration['default']['php_dir'], false, false,
615
        $this->_registry['default'] = &new PEAR_Registry($this->configuration['default']['php_dir']);
684
            $this->configuration['default']['metadata_dir']);
616
        $this->_registry['default']->setConfig($this);
685
        $this->_registry['default']->setConfig($this, false);
617
        $this->_regInitialized['default'] = false;
686
        $this->_regInitialized['default'] = false;
618
        //$GLOBALS['_PEAR_Config_instance'] = &$this;
687
        //$GLOBALS['_PEAR_Config_instance'] = &$this;
619
    }
688
    }
-
 
689
 
-
 
690
    /**
620
 
691
     * Return the default locations of user and system configuration files
621
    // }}}
692
     */
-
 
693
    public static function getDefaultConfigFiles()
-
 
694
    {
-
 
695
        $sl = DIRECTORY_SEPARATOR;
-
 
696
        if (OS_WINDOWS) {
-
 
697
            return array(
-
 
698
                'user'   => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini',
-
 
699
                'system' =>  PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini'
-
 
700
            );
-
 
701
        }
-
 
702
 
-
 
703
        return array(
-
 
704
            'user'   => getenv('HOME') . $sl . '.pearrc',
-
 
705
            'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf'
-
 
706
        );
622
    // {{{ singleton([file], [defaults_file])
707
    }
623
 
708
 
624
    /**
709
    /**
625
     * Static singleton method.  If you want to keep only one instance
710
     * Static singleton method.  If you want to keep only one instance
626
     * of this class in use, this method will give you a reference to
711
     * of this class in use, this method will give you a reference to
627
     * the last created PEAR_Config object if one exists, or create a
712
     * the last created PEAR_Config object if one exists, or create a
628
     * new object.
713
     * new object.
629
     *
714
     *
630
     * @param string (optional) file to read user-defined options from
715
     * @param string (optional) file to read user-defined options from
631
     * @param string (optional) file to read system-wide defaults from
716
     * @param string (optional) file to read system-wide defaults from
632
     *
717
     *
633
     * @return object an existing or new PEAR_Config instance
718
     * @return object an existing or new PEAR_Config instance
634
     *
719
     *
635
     * @access public
-
 
636
     *
-
 
637
     * @see PEAR_Config::PEAR_Config
720
     * @see PEAR_Config::PEAR_Config
638
     */
721
     */
639
    function &singleton($user_file = '', $system_file = '', $strict = true)
722
    public static function &singleton($user_file = '', $system_file = '', $strict = true)
640
    {
723
    {
641
        if (is_object($GLOBALS['_PEAR_Config_instance'])) {
724
        if (is_object($GLOBALS['_PEAR_Config_instance'])) {
642
            return $GLOBALS['_PEAR_Config_instance'];
725
            return $GLOBALS['_PEAR_Config_instance'];
643
        }
726
        }
644
 
727
 
645
        $t_conf = &new PEAR_Config($user_file, $system_file, false, $strict);
728
        $t_conf = new PEAR_Config($user_file, $system_file, false, $strict);
646
        if ($t_conf->_errorsFound > 0) {
729
        if ($t_conf->_errorsFound > 0) {
647
             return $t_conf->lastError;
730
             return $t_conf->lastError;
648
        }
731
        }
649
 
732
 
650
        $GLOBALS['_PEAR_Config_instance'] = &$t_conf;
733
        $GLOBALS['_PEAR_Config_instance'] = &$t_conf;
651
        return $GLOBALS['_PEAR_Config_instance'];
734
        return $GLOBALS['_PEAR_Config_instance'];
652
    }
735
    }
653
 
-
 
654
    // }}}
-
 
655
    // {{{ validConfiguration()
-
 
656
 
736
 
657
    /**
737
    /**
658
     * Determine whether any configuration files have been detected, and whether a
738
     * Determine whether any configuration files have been detected, and whether a
659
     * registry object can be retrieved from this configuration.
739
     * registry object can be retrieved from this configuration.
660
     * @return bool
740
     * @return bool
661
     * @since PEAR 1.4.0a1
741
     * @since PEAR 1.4.0a1
662
     */
742
     */
663
    function validConfiguration()
743
    function validConfiguration()
664
    {
744
    {
665
        if ($this->isDefinedLayer('user') || $this->isDefinedLayer('system')) {
745
        if ($this->isDefinedLayer('user') || $this->isDefinedLayer('system')) {
666
            return true;
746
            return true;
667
        }
747
        }
-
 
748
 
668
        return false;
749
        return false;
669
    }
750
    }
670
 
-
 
671
    // }}}
-
 
672
    // {{{ readConfigFile([file], [layer])
-
 
673
 
751
 
674
    /**
752
    /**
675
     * Reads configuration data from a file.  All existing values in
753
     * Reads configuration data from a file.  All existing values in
676
     * the config layer are discarded and replaced with data from the
754
     * the config layer are discarded and replaced with data from the
677
     * file.
755
     * file.
678
     * @param string file to read from, if NULL or not specified, the
756
     * @param string file to read from, if NULL or not specified, the
679
     *               last-used file for the same layer (second param) is used
757
     *               last-used file for the same layer (second param) is used
680
     * @param string config layer to insert data into ('user' or 'system')
758
     * @param string config layer to insert data into ('user' or 'system')
681
     * @return bool TRUE on success or a PEAR error on failure
759
     * @return bool TRUE on success or a PEAR error on failure
682
     */
760
     */
683
    function readConfigFile($file = null, $layer = 'user', $strict = true)
761
    function readConfigFile($file = null, $layer = 'user', $strict = true)
684
    {
762
    {
685
        if (empty($this->files[$layer])) {
763
        if (empty($this->files[$layer])) {
686
            return $this->raiseError("unknown config layer `$layer'");
764
            return $this->raiseError("unknown config layer `$layer'");
687
        }
765
        }
688
 
766
 
689
        if ($file === null) {
767
        if ($file === null) {
690
            $file = $this->files[$layer];
768
            $file = $this->files[$layer];
691
        }
769
        }
692
 
770
 
693
        $data = $this->_readConfigDataFrom($file);
771
        $data = $this->_readConfigDataFrom($file);
694
 
-
 
695
        if (PEAR::isError($data)) {
772
        if (PEAR::isError($data)) {
696
            if ($strict) {
773
            if (!$strict) {
697
                $this->_errorsFound++;
-
 
698
                $this->lastError = $data;
-
 
699
 
-
 
700
                return $data;
-
 
701
            } else {
-
 
702
                return true;
774
                return true;
703
            }
775
            }
-
 
776
 
704
        } else {
777
            $this->_errorsFound++;
705
            $this->files[$layer] = $file;
778
            $this->lastError = $data;
-
 
779
 
-
 
780
            return $data;
706
        }
781
        }
-
 
782
 
707
 
783
        $this->files[$layer] = $file;
708
        $this->_decodeInput($data);
784
        $this->_decodeInput($data);
709
        $this->configuration[$layer] = $data;
785
        $this->configuration[$layer] = $data;
710
        $this->_setupChannels();
786
        $this->_setupChannels();
711
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
787
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
712
            $this->_registry[$layer] = &new PEAR_Registry($phpdir);
788
            $this->_registry[$layer] = new PEAR_Registry(
-
 
789
                $phpdir, false, false,
-
 
790
                $this->get('metadata_dir', $layer, 'pear.php.net'));
713
            $this->_registry[$layer]->setConfig($this);
791
            $this->_registry[$layer]->setConfig($this, false);
714
            $this->_regInitialized[$layer] = false;
792
            $this->_regInitialized[$layer] = false;
715
        } else {
793
        } else {
716
            unset($this->_registry[$layer]);
794
            unset($this->_registry[$layer]);
717
        }
795
        }
718
        return true;
796
        return true;
719
    }
797
    }
720
 
-
 
721
    // }}}
-
 
722
 
798
 
723
    /**
799
    /**
724
     * @param string url to the remote config file, like ftp://www.example.com/pear/config.ini
800
     * @param string url to the remote config file, like ftp://www.example.com/pear/config.ini
725
     * @return true|PEAR_Error
801
     * @return true|PEAR_Error
726
     */
802
     */
727
    function readFTPConfigFile($path)
803
    function readFTPConfigFile($path)
728
    {
804
    {
729
        do { // poor man's try
805
        do { // poor man's try
730
            if (!class_exists('PEAR_FTP')) {
806
            if (!class_exists('PEAR_FTP')) {
731
                if (!class_exists('PEAR_Common')) {
807
                if (!class_exists('PEAR_Common')) {
732
                    require_once 'PEAR/Common.php';
808
                    require_once 'PEAR/Common.php';
733
                }
809
                }
734
                if (PEAR_Common::isIncludeable('PEAR/FTP.php')) {
810
                if (PEAR_Common::isIncludeable('PEAR/FTP.php')) {
735
                    require_once 'PEAR/FTP.php';
811
                    require_once 'PEAR/FTP.php';
736
                }
812
                }
737
            }
813
            }
-
 
814
 
738
            if (class_exists('PEAR_FTP')) {
815
            if (!class_exists('PEAR_FTP')) {
739
                $this->_ftp = &new PEAR_FTP;
-
 
740
                $this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN);
816
                return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config');
741
                $e = $this->_ftp->init($path);
-
 
742
                if (PEAR::isError($e)) {
-
 
743
                    $this->_ftp->popErrorHandling();
-
 
744
                    return $e;
-
 
745
                }
817
            }
-
 
818
 
746
                $tmp = System::mktemp('-d');
819
            $this->_ftp = new PEAR_FTP;
747
                PEAR_Common::addTempFile($tmp);
-
 
748
                $e = $this->_ftp->get(basename($path), $tmp . DIRECTORY_SEPARATOR .
820
            $this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN);
749
                    'pear.ini', false, FTP_BINARY);
821
            $e = $this->_ftp->init($path);
750
                if (PEAR::isError($e)) {
822
            if (PEAR::isError($e)) {
751
                    $this->_ftp->popErrorHandling();
-
 
752
                    return $e;
-
 
753
                }
-
 
754
                PEAR_Common::addTempFile($tmp . DIRECTORY_SEPARATOR . 'pear.ini');
-
 
755
                $this->_ftp->disconnect();
-
 
756
                $this->_ftp->popErrorHandling();
823
                $this->_ftp->popErrorHandling();
-
 
824
                return $e;
-
 
825
            }
-
 
826
 
-
 
827
            $tmp = System::mktemp('-d');
-
 
828
            PEAR_Common::addTempFile($tmp);
-
 
829
            $e = $this->_ftp->get(basename($path), $tmp . DIRECTORY_SEPARATOR .
-
 
830
                'pear.ini', false, FTP_BINARY);
-
 
831
            if (PEAR::isError($e)) {
-
 
832
                $this->_ftp->popErrorHandling();
-
 
833
                return $e;
-
 
834
            }
-
 
835
 
-
 
836
            PEAR_Common::addTempFile($tmp . DIRECTORY_SEPARATOR . 'pear.ini');
-
 
837
            $this->_ftp->disconnect();
-
 
838
            $this->_ftp->popErrorHandling();
757
                $this->files['ftp'] = $tmp . DIRECTORY_SEPARATOR . 'pear.ini';
839
            $this->files['ftp'] = $tmp . DIRECTORY_SEPARATOR . 'pear.ini';
758
                $e = $this->readConfigFile(null, 'ftp');
840
            $e = $this->readConfigFile(null, 'ftp');
759
                if (PEAR::isError($e)) {
841
            if (PEAR::isError($e)) {
760
                    return $e;
842
                return $e;
761
                }
843
            }
-
 
844
 
762
                $fail = array();
845
            $fail = array();
763
                foreach ($this->configuration_info as $key => $val) {
846
            foreach ($this->configuration_info as $key => $val) {
764
                    if (in_array($this->getGroup($key),
847
                if (in_array($this->getGroup($key),
765
                          array('File Locations', 'File Locations (Advanced)')) &&
848
                      array('File Locations', 'File Locations (Advanced)')) &&
766
                          $this->getType($key) == 'directory') {
849
                      $this->getType($key) == 'directory') {
767
                        // any directory configs must be set for this to work
850
                    // any directory configs must be set for this to work
768
                        if (!isset($this->configuration['ftp'][$key])) {
851
                    if (!isset($this->configuration['ftp'][$key])) {
769
                            $fail[] = $key;
852
                        $fail[] = $key;
770
                        }
-
 
771
                    }
853
                    }
772
                }
854
                }
773
                if (count($fail)) {
-
 
774
                    $fail = '"' . implode('", "', $fail) . '"';
-
 
775
                    unset($this->files['ftp']);
-
 
776
                    unset($this->configuration['ftp']);
-
 
777
                    return PEAR::raiseError('ERROR: Ftp configuration file must set all ' .
-
 
778
                        'directory configuration variables.  These variables were not set: ' .
-
 
779
                        $fail);
-
 
780
                } else {
-
 
781
                    return true;
-
 
782
                }
-
 
783
            } else {
-
 
784
                return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config');
-
 
785
            }
855
            }
-
 
856
 
-
 
857
            if (!count($fail)) {
-
 
858
                return true;
-
 
859
            }
-
 
860
 
-
 
861
            $fail = '"' . implode('", "', $fail) . '"';
-
 
862
            unset($this->files['ftp']);
-
 
863
            unset($this->configuration['ftp']);
-
 
864
            return PEAR::raiseError('ERROR: Ftp configuration file must set all ' .
-
 
865
                'directory configuration variables.  These variables were not set: ' .
-
 
866
                $fail);
786
        } while (false); // poor man's catch
867
        } while (false); // poor man's catch
787
        unset($this->files['ftp']);
868
        unset($this->files['ftp']);
788
        return PEAR::raiseError('no remote host specified');
869
        return PEAR::raiseError('no remote host specified');
789
    }
870
    }
790
 
-
 
791
    // {{{ _setupChannels()
-
 
792
    
871
 
793
    /**
872
    /**
794
     * Reads the existing configurations and creates the _channels array from it
873
     * Reads the existing configurations and creates the _channels array from it
795
     */
874
     */
796
    function _setupChannels()
875
    function _setupChannels()
797
    {
876
    {
798
        $set = array_flip(array_values($this->_channels));
877
        $set = array_flip(array_values($this->_channels));
799
        foreach ($this->configuration as $layer => $data) {
878
        foreach ($this->configuration as $layer => $data) {
800
            $i = 1000;
879
            $i = 1000;
801
            if (isset($data['__channels']) && is_array($data['__channels'])) {
880
            if (isset($data['__channels']) && is_array($data['__channels'])) {
802
                foreach ($data['__channels'] as $channel => $info) {
881
                foreach ($data['__channels'] as $channel => $info) {
803
                    $set[$channel] = $i++;
882
                    $set[$channel] = $i++;
804
                }
883
                }
805
            }
884
            }
806
        }
885
        }
807
        $this->_channels = array_values(array_flip($set));
886
        $this->_channels = array_values(array_flip($set));
808
        $this->setChannels($this->_channels);
887
        $this->setChannels($this->_channels);
809
    }
888
    }
810
 
-
 
811
    // }}}
-
 
812
    // {{{ deleteChannel(channel)
-
 
813
 
889
 
814
    function deleteChannel($channel)
890
    function deleteChannel($channel)
-
 
891
    {
815
    {
892
        $ch = strtolower($channel);
816
        foreach ($this->configuration as $layer => $data) {
-
 
817
            if (isset($data['__channels'])) {
893
        foreach ($this->configuration as $layer => $data) {
818
                if (isset($data['__channels'][strtolower($channel)])) {
894
            if (isset($data['__channels']) && isset($data['__channels'][$ch])) {
819
                    unset($this->configuration[$layer]['__channels'][strtolower($channel)]);
-
 
820
                }
895
                unset($this->configuration[$layer]['__channels'][$ch]);
821
            }
896
            }
-
 
897
        }
822
        }
898
 
823
        $this->_channels = array_flip($this->_channels);
899
        $this->_channels = array_flip($this->_channels);
824
        unset($this->_channels[strtolower($channel)]);
900
        unset($this->_channels[$ch]);
825
        $this->_channels = array_flip($this->_channels);
901
        $this->_channels = array_flip($this->_channels);
826
    }
902
    }
827
 
-
 
828
    // }}}
-
 
829
    // {{{ mergeConfigFile(file, [override], [layer])
-
 
830
 
903
 
831
    /**
904
    /**
832
     * Merges data into a config layer from a file.  Does the same
905
     * Merges data into a config layer from a file.  Does the same
833
     * thing as readConfigFile, except it does not replace all
906
     * thing as readConfigFile, except it does not replace all
834
     * existing values in the config layer.
907
     * existing values in the config layer.
835
     * @param string file to read from
908
     * @param string file to read from
836
     * @param bool whether to overwrite existing data (default TRUE)
909
     * @param bool whether to overwrite existing data (default TRUE)
837
     * @param string config layer to insert data into ('user' or 'system')
910
     * @param string config layer to insert data into ('user' or 'system')
838
     * @param string if true, errors are returned if file opening fails
911
     * @param string if true, errors are returned if file opening fails
839
     * @return bool TRUE on success or a PEAR error on failure
912
     * @return bool TRUE on success or a PEAR error on failure
840
     */
913
     */
841
    function mergeConfigFile($file, $override = true, $layer = 'user', $strict = true)
914
    function mergeConfigFile($file, $override = true, $layer = 'user', $strict = true)
842
    {
915
    {
843
        if (empty($this->files[$layer])) {
916
        if (empty($this->files[$layer])) {
844
            return $this->raiseError("unknown config layer `$layer'");
917
            return $this->raiseError("unknown config layer `$layer'");
845
        }
918
        }
-
 
919
 
846
        if ($file === null) {
920
        if ($file === null) {
847
            $file = $this->files[$layer];
921
            $file = $this->files[$layer];
848
        }
922
        }
-
 
923
 
849
        $data = $this->_readConfigDataFrom($file);
924
        $data = $this->_readConfigDataFrom($file);
850
        if (PEAR::isError($data)) {
925
        if (PEAR::isError($data)) {
851
            if ($strict) {
926
            if (!$strict) {
852
                $this->_errorsFound++;
-
 
853
                $this->lastError = $data;
-
 
854
 
-
 
855
                return $data;
-
 
856
            } else {
-
 
857
                return true;
927
                return true;
858
            }
928
            }
-
 
929
 
-
 
930
            $this->_errorsFound++;
-
 
931
            $this->lastError = $data;
-
 
932
 
-
 
933
            return $data;
859
        }
934
        }
-
 
935
 
860
        $this->_decodeInput($data);
936
        $this->_decodeInput($data);
861
        if ($override) {
937
        if ($override) {
862
            $this->configuration[$layer] =
938
            $this->configuration[$layer] =
863
                PEAR_Config::arrayMergeRecursive($this->configuration[$layer], $data);
939
                PEAR_Config::arrayMergeRecursive($this->configuration[$layer], $data);
864
        } else {
940
        } else {
865
            $this->configuration[$layer] =
941
            $this->configuration[$layer] =
866
                PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]);
942
                PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]);
867
        }
943
        }
-
 
944
 
868
        $this->_setupChannels();
945
        $this->_setupChannels();
869
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
946
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
870
            $this->_registry[$layer] = &new PEAR_Registry($phpdir);
947
            $this->_registry[$layer] = new PEAR_Registry(
-
 
948
                $phpdir, false, false,
-
 
949
                $this->get('metadata_dir', $layer, 'pear.php.net'));
871
            $this->_registry[$layer]->setConfig($this);
950
            $this->_registry[$layer]->setConfig($this, false);
872
            $this->_regInitialized[$layer] = false;
951
            $this->_regInitialized[$layer] = false;
873
        } else {
952
        } else {
874
            unset($this->_registry[$layer]);
953
            unset($this->_registry[$layer]);
875
        }
954
        }
876
        return true;
955
        return true;
877
    }
956
    }
878
 
-
 
879
    // }}}
-
 
880
    // {{{ arrayMergeRecursive($arr2, $arr1)
957
 
881
    /**
958
    /**
882
     * @param array
959
     * @param array
883
     * @param array
960
     * @param array
884
     * @return array
961
     * @return array
885
     * @static
-
 
886
     */
962
     */
887
    function arrayMergeRecursive($arr2, $arr1)
963
    public static function arrayMergeRecursive($arr2, $arr1)
888
    {
964
    {
889
        $ret = array();
965
        $ret = array();
890
        foreach ($arr2 as $key => $data) {
966
        foreach ($arr2 as $key => $data) {
891
            if (!isset($arr1[$key])) {
967
            if (!isset($arr1[$key])) {
892
                $ret[$key] = $data;
968
                $ret[$key] = $data;
893
                unset($arr1[$key]);
969
                unset($arr1[$key]);
894
                continue;
970
                continue;
895
            }
971
            }
896
            if (is_array($data)) {
972
            if (is_array($data)) {
897
                if (!is_array($arr1[$key])) {
973
                if (!is_array($arr1[$key])) {
898
                    $ret[$key] = $arr1[$key];
974
                    $ret[$key] = $arr1[$key];
899
                    unset($arr1[$key]);
975
                    unset($arr1[$key]);
900
                    continue;
976
                    continue;
901
                }
977
                }
902
                $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
978
                $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
903
                unset($arr1[$key]);
979
                unset($arr1[$key]);
904
            }
980
            }
905
        }
981
        }
-
 
982
 
906
        return array_merge($ret, $arr1);
983
        return array_merge($ret, $arr1);
907
    }
984
    }
908
 
-
 
909
    // }}}
-
 
910
    // {{{ writeConfigFile([file], [layer])
-
 
911
 
985
 
912
    /**
986
    /**
913
     * Writes data into a config layer from a file.
987
     * Writes data into a config layer from a file.
914
     *
988
     *
915
     * @param string|null file to read from, or null for default
989
     * @param string|null file to read from, or null for default
916
     * @param string config layer to insert data into ('user' or
990
     * @param string config layer to insert data into ('user' or
917
     *               'system')
991
     *               'system')
918
     * @param string|null data to write to config file or null for internal data [DEPRECATED]
992
     * @param string|null data to write to config file or null for internal data [DEPRECATED]
919
     * @return bool TRUE on success or a PEAR error on failure
993
     * @return bool TRUE on success or a PEAR error on failure
920
     */
994
     */
921
    function writeConfigFile($file = null, $layer = 'user', $data = null)
995
    function writeConfigFile($file = null, $layer = 'user', $data = null)
922
    {
996
    {
923
        $this->_lazyChannelSetup($layer);
997
        $this->_lazyChannelSetup($layer);
924
        if ($layer == 'both' || $layer == 'all') {
998
        if ($layer == 'both' || $layer == 'all') {
925
            foreach ($this->files as $type => $file) {
999
            foreach ($this->files as $type => $file) {
926
                $err = $this->writeConfigFile($file, $type, $data);
1000
                $err = $this->writeConfigFile($file, $type, $data);
927
                if (PEAR::isError($err)) {
1001
                if (PEAR::isError($err)) {
928
                    return $err;
1002
                    return $err;
929
                }
1003
                }
930
            }
1004
            }
931
            return true;
1005
            return true;
932
        }
1006
        }
-
 
1007
 
933
        if (empty($this->files[$layer])) {
1008
        if (empty($this->files[$layer])) {
934
            return $this->raiseError("unknown config file type `$layer'");
1009
            return $this->raiseError("unknown config file type `$layer'");
935
        }
1010
        }
-
 
1011
 
936
        if ($file === null) {
1012
        if ($file === null) {
937
            $file = $this->files[$layer];
1013
            $file = $this->files[$layer];
938
        }
1014
        }
-
 
1015
 
939
        $data = ($data === null) ? $this->configuration[$layer] : $data;
1016
        $data = ($data === null) ? $this->configuration[$layer] : $data;
940
        $this->_encodeOutput($data);
1017
        $this->_encodeOutput($data);
941
        $opt = array('-p', dirname($file));
1018
        $opt = array('-p', dirname($file));
942
        if (!@System::mkDir($opt)) {
1019
        if (!@System::mkDir($opt)) {
943
            return $this->raiseError("could not create directory: " . dirname($file));
1020
            return $this->raiseError("could not create directory: " . dirname($file));
944
        }
1021
        }
-
 
1022
 
945
        if (file_exists($file) && is_file($file) && !is_writeable($file)) {
1023
        if (file_exists($file) && is_file($file) && !is_writeable($file)) {
946
            return $this->raiseError("no write access to $file!");
1024
            return $this->raiseError("no write access to $file!");
947
        }
1025
        }
-
 
1026
 
948
        $fp = @fopen($file, "w");
1027
        $fp = @fopen($file, "w");
949
        if (!$fp) {
1028
        if (!$fp) {
950
            return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)");
1029
            return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)");
951
        }
1030
        }
-
 
1031
 
952
        $contents = "#PEAR_Config 0.9\n" . serialize($data);
1032
        $contents = "#PEAR_Config 0.9\n" . serialize($data);
953
        if (!@fwrite($fp, $contents)) {
1033
        if (!@fwrite($fp, $contents)) {
954
            return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ($php_errormsg)");
1034
            return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ($php_errormsg)");
955
        }
1035
        }
956
        return true;
1036
        return true;
957
    }
1037
    }
958
 
-
 
959
    // }}}
-
 
960
    // {{{ _readConfigDataFrom(file)
-
 
961
 
1038
 
962
    /**
1039
    /**
963
     * Reads configuration data from a file and returns the parsed data
1040
     * Reads configuration data from a file and returns the parsed data
964
     * in an array.
1041
     * in an array.
965
     *
1042
     *
966
     * @param string file to read from
1043
     * @param string file to read from
967
     *
-
 
968
     * @return array configuration data or a PEAR error on failure
1044
     * @return array configuration data or a PEAR error on failure
969
     *
-
 
970
     * @access private
1045
     * @access private
971
     */
1046
     */
972
    function _readConfigDataFrom($file)
1047
    function _readConfigDataFrom($file)
973
    {
1048
    {
974
        $fp = false;
1049
        $fp = false;
975
        if (file_exists($file)) {
1050
        if (file_exists($file)) {
976
            $fp = @fopen($file, "r");
1051
            $fp = @fopen($file, "r");
977
        }
1052
        }
-
 
1053
 
978
        if (!$fp) {
1054
        if (!$fp) {
979
            return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed");
1055
            return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed");
980
        }
1056
        }
-
 
1057
 
981
        $size = filesize($file);
1058
        $size = filesize($file);
982
        $rt = get_magic_quotes_runtime();
-
 
983
        set_magic_quotes_runtime(0);
-
 
984
        fclose($fp);
1059
        fclose($fp);
985
        $contents = file_get_contents($file);
1060
        $contents = file_get_contents($file);
986
        if (empty($contents)) {
1061
        if (empty($contents)) {
987
            return $this->raiseError('Configuration file "' . $file . '" is empty');
1062
            return $this->raiseError('Configuration file "' . $file . '" is empty');
988
        }
1063
        }
989
        
-
 
990
        set_magic_quotes_runtime($rt);
-
 
991
 
1064
 
992
        $version = false;
1065
        $version = false;
993
        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
1066
        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
994
            $version = $matches[1];
1067
            $version = $matches[1];
995
            $contents = substr($contents, strlen($matches[0]));
1068
            $contents = substr($contents, strlen($matches[0]));
996
        } else {
1069
        } else {
997
            // Museum config file
1070
            // Museum config file
998
            if (substr($contents,0,2) == 'a:') {
1071
            if (substr($contents,0,2) == 'a:') {
999
                $version = '0.1';
1072
                $version = '0.1';
1000
            }
1073
            }
1001
        }
1074
        }
1002
        if ($version && version_compare("$version", '1', '<')) {
-
 
-
 
1075
 
1003
 
1076
        if ($version && version_compare("$version", '1', '<')) {
1004
            // no '@', it is possible that unserialize
1077
            // no '@', it is possible that unserialize
1005
            // raises a notice but it seems to block IO to
1078
            // raises a notice but it seems to block IO to
1006
            // STDOUT if a '@' is used and a notice is raise
1079
            // STDOUT if a '@' is used and a notice is raise
1007
            $data = unserialize($contents);
1080
            $data = unserialize($contents);
1008
 
1081
 
1009
            if (!is_array($data) && !$data) {
1082
            if (!is_array($data) && !$data) {
1010
                if ($contents == serialize(false)) {
1083
                if ($contents == serialize(false)) {
1011
                    $data = array();
1084
                    $data = array();
1012
                } else {
1085
                } else {
1013
                    $err = $this->raiseError("PEAR_Config: bad data in $file");
1086
                    $err = $this->raiseError("PEAR_Config: bad data in $file");
1014
                    return $err;
1087
                    return $err;
1015
                }
1088
                }
1016
            }
1089
            }
1017
            if (!is_array($data)) {
1090
            if (!is_array($data)) {
1018
                if (strlen(trim($contents)) > 0) {
1091
                if (strlen(trim($contents)) > 0) {
1019
                    $error = "PEAR_Config: bad data in $file";
1092
                    $error = "PEAR_Config: bad data in $file";
1020
                    $err = $this->raiseError($error);
1093
                    $err = $this->raiseError($error);
1021
                    return $err;
1094
                    return $err;
1022
                } else {
-
 
1023
                    $data = array();
-
 
1024
                }
1095
                }
-
 
1096
 
-
 
1097
                $data = array();
1025
            }
1098
            }
1026
        // add parsing of newer formats here...
1099
        // add parsing of newer formats here...
1027
        } else {
1100
        } else {
1028
            $err = $this->raiseError("$file: unknown version `$version'");
1101
            $err = $this->raiseError("$file: unknown version `$version'");
1029
            return $err; 
1102
            return $err;
1030
        }
1103
        }
-
 
1104
 
1031
        return $data;
1105
        return $data;
1032
    }
1106
    }
1033
 
-
 
1034
    // }}}
-
 
1035
    // {{{ getConfFile(layer)
1107
 
1036
    /**
1108
    /**
1037
    * Gets the file used for storing the config for a layer
1109
    * Gets the file used for storing the config for a layer
1038
    *
1110
    *
1039
    * @param string $layer 'user' or 'system'
1111
    * @param string $layer 'user' or 'system'
1040
    */
1112
    */
1041
 
-
 
1042
    function getConfFile($layer)
1113
    function getConfFile($layer)
1043
    {
1114
    {
1044
        return $this->files[$layer];
1115
        return $this->files[$layer];
1045
    }
1116
    }
1046
 
-
 
1047
    // }}}
-
 
1048
 
1117
 
-
 
1118
    /**
1049
    /**
1119
     * @param string Configuration class name, used for detecting duplicate calls
1050
     * @param array information on a role as parsed from its xml file
1120
     * @param array information on a role as parsed from its xml file
1051
     * @return true|PEAR_Error
1121
     * @return true|PEAR_Error
1052
     * @access private
1122
     * @access private
1053
     */
1123
     */
1054
    function _addConfigVars($vars)
1124
    function _addConfigVars($class, $vars)
1055
    {
1125
    {
-
 
1126
        static $called = array();
-
 
1127
        if (isset($called[$class])) {
-
 
1128
            return;
-
 
1129
        }
-
 
1130
 
-
 
1131
        $called[$class] = 1;
1056
        if (count($vars) > 3) {
1132
        if (count($vars) > 3) {
1057
            return $this->raiseError('Roles can only define 3 new config variables or less');
1133
            return $this->raiseError('Roles can only define 3 new config variables or less');
1058
        }
1134
        }
-
 
1135
 
1059
        foreach ($vars as $name => $var) {
1136
        foreach ($vars as $name => $var) {
1060
            if (!is_array($var)) {
1137
            if (!is_array($var)) {
1061
                return $this->raiseError('Configuration information must be an array');
1138
                return $this->raiseError('Configuration information must be an array');
1062
            }
1139
            }
-
 
1140
 
1063
            if (!isset($var['type'])) {
1141
            if (!isset($var['type'])) {
1064
                return $this->raiseError('Configuration information must contain a type');
1142
                return $this->raiseError('Configuration information must contain a type');
1065
            } else {
-
 
1066
                if (!in_array($var['type'],
1143
            } elseif (!in_array($var['type'],
1067
                      array('string', 'mask', 'password', 'directory', 'file', 'set'))) {
1144
                    array('string', 'mask', 'password', 'directory', 'file', 'set'))) {
1068
                    return $this->raiseError(
1145
                  return $this->raiseError(
1069
                        'Configuration type must be one of directory, file, string, ' .
1146
                      'Configuration type must be one of directory, file, string, ' .
1070
                        'mask, set, or password');
1147
                      'mask, set, or password');
1071
                }
-
 
1072
            }
1148
            }
1073
            if (!isset($var['default'])) {
1149
            if (!isset($var['default'])) {
1074
                return $this->raiseError(
1150
                return $this->raiseError(
1075
                    'Configuration information must contain a default value ("default" index)');
1151
                    'Configuration information must contain a default value ("default" index)');
1076
            } else {
1152
            }
-
 
1153
 
1077
                if (is_array($var['default'])) {
1154
            if (is_array($var['default'])) {
1078
                    $real_default = '';
1155
                $real_default = '';
1079
                    foreach ($var['default'] as $config_var => $val) {
1156
                foreach ($var['default'] as $config_var => $val) {
1080
                        if (strpos($config_var, 'text') === 0) {
1157
                    if (strpos($config_var, 'text') === 0) {
1081
                            $real_default .= $val;
1158
                        $real_default .= $val;
1082
                        } elseif (strpos($config_var, 'constant') === 0) {
1159
                    } elseif (strpos($config_var, 'constant') === 0) {
1083
                            if (defined($val)) {
1160
                        if (!defined($val)) {
1084
                                $real_default .= constant($val);
-
 
1085
                            } else {
-
 
1086
                                return $this->raiseError(
-
 
1087
                                    'Unknown constant "' . $val . '" requested in ' .
-
 
1088
                                    'default value for configuration variable "' .
-
 
1089
                                    $name . '"');
-
 
1090
                            }
-
 
1091
                        } elseif (isset($this->configuration_info[$config_var])) {
-
 
1092
                            $real_default .=
-
 
1093
                                $this->configuration_info[$config_var]['default'];
-
 
1094
                        } else {
-
 
1095
                            return $this->raiseError(
1161
                            return $this->raiseError(
1096
                                'Unknown request for "' . $config_var . '" value in ' .
1162
                                'Unknown constant "' . $val . '" requested in ' .
1097
                                'default value for configuration variable "' .
1163
                                'default value for configuration variable "' .
1098
                                $name . '"');
1164
                                $name . '"');
1099
                        }
1165
                        }
-
 
1166
 
-
 
1167
                        $real_default .= constant($val);
-
 
1168
                    } elseif (isset($this->configuration_info[$config_var])) {
-
 
1169
                        $real_default .=
-
 
1170
                            $this->configuration_info[$config_var]['default'];
-
 
1171
                    } else {
-
 
1172
                        return $this->raiseError(
-
 
1173
                            'Unknown request for "' . $config_var . '" value in ' .
-
 
1174
                            'default value for configuration variable "' .
-
 
1175
                            $name . '"');
1100
                    }
1176
                    }
1101
                    $var['default'] = $real_default;
-
 
1102
                }
-
 
1103
                if ($var['type'] == 'integer') {
-
 
1104
                    $var['default'] = (integer) $var['default'];
-
 
1105
                }
1177
                }
-
 
1178
                $var['default'] = $real_default;
1106
            }
1179
            }
-
 
1180
 
-
 
1181
            if ($var['type'] == 'integer') {
-
 
1182
                $var['default'] = (integer) $var['default'];
-
 
1183
            }
-
 
1184
 
1107
            if (!isset($var['doc'])) {
1185
            if (!isset($var['doc'])) {
1108
                return $this->raiseError(
1186
                return $this->raiseError(
1109
                    'Configuration information must contain a summary ("doc" index)');
1187
                    'Configuration information must contain a summary ("doc" index)');
1110
            }
1188
            }
-
 
1189
 
1111
            if (!isset($var['prompt'])) {
1190
            if (!isset($var['prompt'])) {
1112
                return $this->raiseError(
1191
                return $this->raiseError(
1113
                    'Configuration information must contain a simple prompt ("prompt" index)');
1192
                    'Configuration information must contain a simple prompt ("prompt" index)');
1114
            }
1193
            }
-
 
1194
 
1115
            if (!isset($var['group'])) {
1195
            if (!isset($var['group'])) {
1116
                return $this->raiseError(
1196
                return $this->raiseError(
1117
                    'Configuration information must contain a simple group ("group" index)');
1197
                    'Configuration information must contain a simple group ("group" index)');
1118
            }
1198
            }
-
 
1199
 
1119
            if (isset($this->configuration_info[$name])) {
1200
            if (isset($this->configuration_info[$name])) {
1120
                return $this->raiseError('Configuration variable "' . $name .
1201
                return $this->raiseError('Configuration variable "' . $name .
1121
                    '" already exists');
1202
                    '" already exists');
1122
            }
1203
            }
-
 
1204
 
1123
            $this->configuration_info[$name] = $var;
1205
            $this->configuration_info[$name] = $var;
1124
            // fix bug #7351: setting custom config variable in a channel fails
1206
            // fix bug #7351: setting custom config variable in a channel fails
1125
            $this->_channelConfigInfo[] = $name;
1207
            $this->_channelConfigInfo[] = $name;
1126
        }
1208
        }
-
 
1209
 
1127
        return true;
1210
        return true;
1128
    }
1211
    }
1129
 
-
 
1130
    // {{{ _encodeOutput(&data)
-
 
1131
 
1212
 
1132
    /**
1213
    /**
1133
     * Encodes/scrambles configuration data before writing to files.
1214
     * Encodes/scrambles configuration data before writing to files.
1134
     * Currently, 'password' values will be base64-encoded as to avoid
1215
     * Currently, 'password' values will be base64-encoded as to avoid
1135
     * that people spot cleartext passwords by accident.
1216
     * that people spot cleartext passwords by accident.
1136
     *
1217
     *
1137
     * @param array (reference) array to encode values in
1218
     * @param array (reference) array to encode values in
1138
     *
-
 
1139
     * @return bool TRUE on success
1219
     * @return bool TRUE on success
1140
     *
-
 
1141
     * @access private
1220
     * @access private
1142
     */
1221
     */
1143
    function _encodeOutput(&$data)
1222
    function _encodeOutput(&$data)
1144
    {
1223
    {
1145
        foreach ($data as $key => $value) {
1224
        foreach ($data as $key => $value) {
1146
            if ($key == '__channels') {
1225
            if ($key == '__channels') {
1147
                foreach ($data['__channels'] as $channel => $blah) {
1226
                foreach ($data['__channels'] as $channel => $blah) {
1148
                    $this->_encodeOutput($data['__channels'][$channel]);
1227
                    $this->_encodeOutput($data['__channels'][$channel]);
1149
                }
1228
                }
1150
            }
1229
            }
-
 
1230
 
1151
            if (!isset($this->configuration_info[$key])) {
1231
            if (!isset($this->configuration_info[$key])) {
1152
                continue;
1232
                continue;
1153
            }
1233
            }
-
 
1234
 
1154
            $type = $this->configuration_info[$key]['type'];
1235
            $type = $this->configuration_info[$key]['type'];
1155
            switch ($type) {
1236
            switch ($type) {
1156
                // we base64-encode passwords so they are at least
1237
                // we base64-encode passwords so they are at least
1157
                // not shown in plain by accident
1238
                // not shown in plain by accident
1158
                case 'password': {
1239
                case 'password': {
1159
                    $data[$key] = base64_encode($data[$key]);
1240
                    $data[$key] = base64_encode($data[$key]);
1160
                    break;
1241
                    break;
1161
                }
1242
                }
1162
                case 'mask': {
1243
                case 'mask': {
1163
                    $data[$key] = octdec($data[$key]);
1244
                    $data[$key] = octdec($data[$key]);
1164
                    break;
1245
                    break;
1165
                }
1246
                }
1166
            }
1247
            }
1167
        }
1248
        }
-
 
1249
 
1168
        return true;
1250
        return true;
1169
    }
1251
    }
1170
 
-
 
1171
    // }}}
-
 
1172
    // {{{ _decodeInput(&data)
-
 
1173
 
1252
 
1174
    /**
1253
    /**
1175
     * Decodes/unscrambles configuration data after reading from files.
1254
     * Decodes/unscrambles configuration data after reading from files.
1176
     *
1255
     *
1177
     * @param array (reference) array to encode values in
1256
     * @param array (reference) array to encode values in
1178
     *
-
 
1179
     * @return bool TRUE on success
1257
     * @return bool TRUE on success
1180
     *
-
 
1181
     * @access private
1258
     * @access private
1182
     *
1259
     *
1183
     * @see PEAR_Config::_encodeOutput
1260
     * @see PEAR_Config::_encodeOutput
1184
     */
1261
     */
1185
    function _decodeInput(&$data)
1262
    function _decodeInput(&$data)
1186
    {
1263
    {
1187
        if (!is_array($data)) {
1264
        if (!is_array($data)) {
1188
            return true;
1265
            return true;
1189
        }
1266
        }
-
 
1267
 
1190
        foreach ($data as $key => $value) {
1268
        foreach ($data as $key => $value) {
1191
            if ($key == '__channels') {
1269
            if ($key == '__channels') {
1192
                foreach ($data['__channels'] as $channel => $blah) {
1270
                foreach ($data['__channels'] as $channel => $blah) {
1193
                    $this->_decodeInput($data['__channels'][$channel]);
1271
                    $this->_decodeInput($data['__channels'][$channel]);
1194
                }
1272
                }
1195
            }
1273
            }
-
 
1274
 
1196
            if (!isset($this->configuration_info[$key])) {
1275
            if (!isset($this->configuration_info[$key])) {
1197
                continue;
1276
                continue;
1198
            }
1277
            }
-
 
1278
 
1199
            $type = $this->configuration_info[$key]['type'];
1279
            $type = $this->configuration_info[$key]['type'];
1200
            switch ($type) {
1280
            switch ($type) {
1201
                case 'password': {
1281
                case 'password': {
1202
                    $data[$key] = base64_decode($data[$key]);
1282
                    $data[$key] = base64_decode($data[$key]);
1203
                    break;
1283
                    break;
1204
                }
1284
                }
1205
                case 'mask': {
1285
                case 'mask': {
1206
                    $data[$key] = decoct($data[$key]);
1286
                    $data[$key] = decoct($data[$key]);
1207
                    break;
1287
                    break;
1208
                }
1288
                }
1209
            }
1289
            }
1210
        }
1290
        }
-
 
1291
 
1211
        return true;
1292
        return true;
1212
    }
1293
    }
1213
 
-
 
1214
    // }}}
-
 
1215
    // {{{ getDefaultChannel([layer])
1294
 
1216
    /**
1295
    /**
1217
     * Retrieve the default channel.
1296
     * Retrieve the default channel.
1218
     *
1297
     *
1219
     * On startup, channels are not initialized, so if the default channel is not
1298
     * On startup, channels are not initialized, so if the default channel is not
1220
     * pear.php.net, then initialize the config.
1299
     * pear.php.net, then initialize the config.
1221
     * @param string registry layer
1300
     * @param string registry layer
1222
     * @return string|false
1301
     * @return string|false
1223
     */
1302
     */
1224
    function getDefaultChannel($layer = null)
1303
    function getDefaultChannel($layer = null)
1225
    {
1304
    {
1226
        $ret = false;
1305
        $ret = false;
1227
        if ($layer === null) {
1306
        if ($layer === null) {
1228
            foreach ($this->layers as $layer) {
1307
            foreach ($this->layers as $layer) {
1229
                if (isset($this->configuration[$layer]['default_channel'])) {
1308
                if (isset($this->configuration[$layer]['default_channel'])) {
1230
                    $ret = $this->configuration[$layer]['default_channel'];
1309
                    $ret = $this->configuration[$layer]['default_channel'];
1231
                    break;
1310
                    break;
1232
                }
1311
                }
1233
            }
1312
            }
1234
        } elseif (isset($this->configuration[$layer]['default_channel'])) {
1313
        } elseif (isset($this->configuration[$layer]['default_channel'])) {
1235
            $ret = $this->configuration[$layer]['default_channel'];
1314
            $ret = $this->configuration[$layer]['default_channel'];
1236
        }
1315
        }
-
 
1316
 
1237
        if ($ret == 'pear.php.net' && defined('PEAR_RUNTYPE') && PEAR_RUNTYPE == 'pecl') {
1317
        if ($ret == 'pear.php.net' && defined('PEAR_RUNTYPE') && PEAR_RUNTYPE == 'pecl') {
1238
            $ret = 'pecl.php.net';
1318
            $ret = 'pecl.php.net';
1239
        }
1319
        }
-
 
1320
 
1240
        if ($ret) {
1321
        if ($ret) {
1241
            if ($ret != 'pear.php.net') {
1322
            if ($ret != 'pear.php.net') {
1242
                $this->_lazyChannelSetup();
1323
                $this->_lazyChannelSetup();
1243
            }
1324
            }
-
 
1325
 
1244
            return $ret;
1326
            return $ret;
1245
        }
1327
        }
-
 
1328
 
1246
        return PEAR_CONFIG_DEFAULT_CHANNEL;
1329
        return PEAR_CONFIG_DEFAULT_CHANNEL;
1247
    }
1330
    }
1248
 
-
 
1249
    // {{{ get(key, [layer])
1331
 
1250
    /**
1332
    /**
1251
     * Returns a configuration value, prioritizing layers as per the
1333
     * Returns a configuration value, prioritizing layers as per the
1252
     * layers property.
1334
     * layers property.
1253
     *
1335
     *
1254
     * @param string config key
1336
     * @param string config key
1255
     *
-
 
1256
     * @return mixed the config value, or NULL if not found
1337
     * @return mixed the config value, or NULL if not found
1257
     *
-
 
1258
     * @access public
1338
     * @access public
1259
     */
1339
     */
1260
    function get($key, $layer = null, $channel = false)
1340
    function get($key, $layer = null, $channel = false)
1261
    {
1341
    {
1262
        if (!isset($this->configuration_info[$key])) {
1342
        if (!isset($this->configuration_info[$key])) {
1263
            return null;
1343
            return null;
1264
        }
1344
        }
-
 
1345
 
1265
        if ($key == '__channels') {
1346
        if ($key == '__channels') {
1266
            return null;
1347
            return null;
1267
        }
1348
        }
-
 
1349
 
1268
        if ($key == 'default_channel') {
1350
        if ($key == 'default_channel') {
1269
            return $this->getDefaultChannel($layer);
1351
            return $this->getDefaultChannel($layer);
1270
        }
1352
        }
-
 
1353
 
1271
        if (!$channel) {
1354
        if (!$channel) {
1272
            $channel = $this->getDefaultChannel();
1355
            $channel = $this->getDefaultChannel();
1273
        } elseif ($channel != 'pear.php.net') {
1356
        } elseif ($channel != 'pear.php.net') {
1274
            $this->_lazyChannelSetup();
1357
            $this->_lazyChannelSetup();
1275
        }
1358
        }
1276
        $channel = strtolower($channel);
1359
        $channel = strtolower($channel);
1277
        
1360
 
1278
        $test = (in_array($key, $this->_channelConfigInfo)) ?
1361
        $test = (in_array($key, $this->_channelConfigInfo)) ?
1279
            $this->_getChannelValue($key, $layer, $channel) :
1362
            $this->_getChannelValue($key, $layer, $channel) :
1280
            null;
1363
            null;
1281
        if ($test !== null) {
1364
        if ($test !== null) {
1282
            if ($this->_installRoot) {
1365
            if ($this->_installRoot) {
1283
                if (in_array($this->getGroup($key),
1366
                if (in_array($this->getGroup($key),
1284
                      array('File Locations', 'File Locations (Advanced)')) &&
1367
                      array('File Locations', 'File Locations (Advanced)')) &&
1285
                      $this->getType($key) == 'directory') {
1368
                      $this->getType($key) == 'directory') {
1286
                    return $this->_prependPath($test, $this->_installRoot);
1369
                    return $this->_prependPath($test, $this->_installRoot);
1287
                }
1370
                }
1288
            }
1371
            }
1289
            return $test;
1372
            return $test;
1290
        }
1373
        }
-
 
1374
 
1291
        if ($layer === null) {
1375
        if ($layer === null) {
1292
            foreach ($this->layers as $layer) {
1376
            foreach ($this->layers as $layer) {
1293
                if (isset($this->configuration[$layer][$key])) {
1377
                if (isset($this->configuration[$layer][$key])) {
1294
                    $test = $this->configuration[$layer][$key];
1378
                    $test = $this->configuration[$layer][$key];
1295
                    if ($this->_installRoot) {
1379
                    if ($this->_installRoot) {
1296
                        if (in_array($this->getGroup($key),
1380
                        if (in_array($this->getGroup($key),
1297
                              array('File Locations', 'File Locations (Advanced)')) &&
1381
                              array('File Locations', 'File Locations (Advanced)')) &&
1298
                              $this->getType($key) == 'directory') {
1382
                              $this->getType($key) == 'directory') {
1299
                            return $this->_prependPath($test, $this->_installRoot);
1383
                            return $this->_prependPath($test, $this->_installRoot);
1300
                        }
1384
                        }
1301
                    }
1385
                    }
-
 
1386
 
1302
                    if ($key == 'preferred_mirror') {
1387
                    if ($key == 'preferred_mirror') {
1303
                        $reg = &$this->getRegistry();
1388
                        $reg = &$this->getRegistry();
1304
                        if (is_object($reg)) {
1389
                        if (is_object($reg)) {
1305
                            $chan = &$reg->getChannel($channel);
1390
                            $chan = $reg->getChannel($channel);
1306
                            if (PEAR::isError($chan)) {
1391
                            if (PEAR::isError($chan)) {
1307
                                return $channel;
1392
                                return $channel;
1308
                            }
1393
                            }
-
 
1394
 
1309
                            if (!$chan->getMirror($test) && $chan->getName() != $test) {
1395
                            if (!$chan->getMirror($test) && $chan->getName() != $test) {
1310
                                return $channel; // mirror does not exist
1396
                                return $channel; // mirror does not exist
1311
                            }
1397
                            }
1312
                        }
1398
                        }
1313
                    }
1399
                    }
1314
                    return $test;
1400
                    return $test;
1315
                }
1401
                }
1316
            }
1402
            }
1317
        } elseif (isset($this->configuration[$layer][$key])) {
1403
        } elseif (isset($this->configuration[$layer][$key])) {
1318
            $test = $this->configuration[$layer][$key];
1404
            $test = $this->configuration[$layer][$key];
1319
            if ($this->_installRoot) {
1405
            if ($this->_installRoot) {
1320
                if (in_array($this->getGroup($key),
1406
                if (in_array($this->getGroup($key),
1321
                      array('File Locations', 'File Locations (Advanced)')) &&
1407
                      array('File Locations', 'File Locations (Advanced)')) &&
1322
                      $this->getType($key) == 'directory') {
1408
                      $this->getType($key) == 'directory') {
1323
                    return $this->_prependPath($test, $this->_installRoot);
1409
                    return $this->_prependPath($test, $this->_installRoot);
1324
                }
1410
                }
1325
            }
1411
            }
-
 
1412
 
1326
            if ($key == 'preferred_mirror') {
1413
            if ($key == 'preferred_mirror') {
1327
                $reg = &$this->getRegistry();
1414
                $reg = &$this->getRegistry();
1328
                if (is_object($reg)) {
1415
                if (is_object($reg)) {
1329
                    $chan = &$reg->getChannel($channel);
1416
                    $chan = $reg->getChannel($channel);
1330
                    if (PEAR::isError($chan)) {
1417
                    if (PEAR::isError($chan)) {
1331
                        return $channel;
1418
                        return $channel;
1332
                    }
1419
                    }
-
 
1420
 
1333
                    if (!$chan->getMirror($test) && $chan->getName() != $test) {
1421
                    if (!$chan->getMirror($test) && $chan->getName() != $test) {
1334
                        return $channel; // mirror does not exist
1422
                        return $channel; // mirror does not exist
1335
                    }
1423
                    }
1336
                }
1424
                }
1337
            }
1425
            }
-
 
1426
 
1338
            return $test;
1427
            return $test;
1339
        }
1428
        }
-
 
1429
 
1340
        return null;
1430
        return null;
1341
    }
1431
    }
1342
 
-
 
1343
    // }}}
-
 
1344
    // {{{ _getChannelValue(key, value, [layer])
1432
 
1345
    /**
1433
    /**
1346
     * Returns a channel-specific configuration value, prioritizing layers as per the
1434
     * Returns a channel-specific configuration value, prioritizing layers as per the
1347
     * layers property.
1435
     * layers property.
1348
     *
1436
     *
1349
     * @param string config key
1437
     * @param string config key
1350
     *
-
 
1351
     * @return mixed the config value, or NULL if not found
1438
     * @return mixed the config value, or NULL if not found
1352
     *
-
 
1353
     * @access private
1439
     * @access private
1354
     */
1440
     */
1355
    function _getChannelValue($key, $layer, $channel)
1441
    function _getChannelValue($key, $layer, $channel)
1356
    {
1442
    {
1357
        if ($key == '__channels' || $channel == 'pear.php.net') {
1443
        if ($key == '__channels' || $channel == 'pear.php.net') {
1358
            return null;
1444
            return null;
1359
        }
1445
        }
-
 
1446
 
1360
        $ret = null;
1447
        $ret = null;
1361
        if ($layer === null) {
1448
        if ($layer === null) {
1362
            foreach ($this->layers as $ilayer) {
1449
            foreach ($this->layers as $ilayer) {
1363
                if (isset($this->configuration[$ilayer]['__channels'][$channel][$key])) {
1450
                if (isset($this->configuration[$ilayer]['__channels'][$channel][$key])) {
1364
                    $ret = $this->configuration[$ilayer]['__channels'][$channel][$key];
1451
                    $ret = $this->configuration[$ilayer]['__channels'][$channel][$key];
1365
                    break;
1452
                    break;
1366
                }
1453
                }
1367
            }
1454
            }
1368
        } elseif (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1455
        } elseif (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1369
            $ret = $this->configuration[$layer]['__channels'][$channel][$key];
1456
            $ret = $this->configuration[$layer]['__channels'][$channel][$key];
1370
        }
1457
        }
-
 
1458
 
1371
        if ($key == 'preferred_mirror') {
1459
        if ($key != 'preferred_mirror') {
-
 
1460
            return $ret;
-
 
1461
        }
-
 
1462
 
-
 
1463
 
1372
            if ($ret !== null) {
1464
        if ($ret !== null) {
1373
                $reg = &$this->getRegistry($layer);
1465
            $reg = &$this->getRegistry($layer);
1374
                if (is_object($reg)) {
1466
            if (is_object($reg)) {
1375
                    $chan = &$reg->getChannel($channel);
1467
                $chan = $reg->getChannel($channel);
1376
                    if (PEAR::isError($chan)) {
1468
                if (PEAR::isError($chan)) {
1377
                        return $channel;
1469
                    return $channel;
1378
                    }
1470
                }
-
 
1471
 
1379
                    if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
1472
                if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
1380
                        return $channel; // mirror does not exist
1473
                    return $channel; // mirror does not exist
1381
                    }
-
 
1382
                }
1474
                }
1383
                return $ret;
-
 
1384
            }
-
 
1385
            if ($channel != $this->getDefaultChannel($layer)) {
-
 
1386
                return $channel; // we must use the channel name as the preferred mirror
-
 
1387
                                 // if the user has not chosen an alternate
-
 
1388
            } else {
-
 
1389
                return $this->getDefaultChannel($layer);
-
 
1390
            }
1475
            }
-
 
1476
 
-
 
1477
            return $ret;
1391
        }
1478
        }
1392
        return $ret;
-
 
1393
    }
-
 
-
 
1479
 
-
 
1480
        if ($channel != $this->getDefaultChannel($layer)) {
-
 
1481
            return $channel; // we must use the channel name as the preferred mirror
-
 
1482
                             // if the user has not chosen an alternate
-
 
1483
        }
1394
 
1484
 
1395
 
-
 
1396
    // }}}
1485
        return $this->getDefaultChannel($layer);
1397
    // {{{ set(key, value, [layer])
1486
    }
1398
 
1487
 
1399
    /**
1488
    /**
1400
     * Set a config value in a specific layer (defaults to 'user').
1489
     * Set a config value in a specific layer (defaults to 'user').
1401
     * Enforces the types defined in the configuration_info array.  An
1490
     * Enforces the types defined in the configuration_info array.  An
1402
     * integer config variable will be cast to int, and a set config
1491
     * integer config variable will be cast to int, and a set config
1403
     * variable will be validated against its legal values.
1492
     * variable will be validated against its legal values.
1404
     *
1493
     *
1405
     * @param string config key
1494
     * @param string config key
1406
     * @param string config value
1495
     * @param string config value
1407
     * @param string (optional) config layer
1496
     * @param string (optional) config layer
1408
     * @param string channel to set this value for, or null for global value
1497
     * @param string channel to set this value for, or null for global value
1409
     * @return bool TRUE on success, FALSE on failure
1498
     * @return bool TRUE on success, FALSE on failure
1410
     */
1499
     */
1411
    function set($key, $value, $layer = 'user', $channel = false)
1500
    function set($key, $value, $layer = 'user', $channel = false)
1412
    {
1501
    {
1413
        if ($key == '__channels') {
1502
        if ($key == '__channels') {
1414
            return false;
1503
            return false;
1415
        }
1504
        }
-
 
1505
 
1416
        if (!isset($this->configuration[$layer])) {
1506
        if (!isset($this->configuration[$layer])) {
1417
            return false;
1507
            return false;
1418
        }
1508
        }
-
 
1509
 
1419
        if ($key == 'default_channel') {
1510
        if ($key == 'default_channel') {
1420
            // can only set this value globally
1511
            // can only set this value globally
1421
            $channel = 'pear.php.net';
1512
            $channel = 'pear.php.net';
1422
            if ($value != 'pear.php.net') {
1513
            if ($value != 'pear.php.net') {
1423
                $this->_lazyChannelSetup($layer);
1514
                $this->_lazyChannelSetup($layer);
1424
            }
1515
            }
1425
        }
1516
        }
-
 
1517
 
1426
        if ($key == 'preferred_mirror') {
1518
        if ($key == 'preferred_mirror') {
1427
            if ($channel == '__uri') {
1519
            if ($channel == '__uri') {
1428
                return false; // can't set the __uri pseudo-channel's mirror
1520
                return false; // can't set the __uri pseudo-channel's mirror
1429
            }
1521
            }
-
 
1522
 
1430
            $reg = &$this->getRegistry($layer);
1523
            $reg = &$this->getRegistry($layer);
1431
            if (is_object($reg)) {
1524
            if (is_object($reg)) {
1432
                $chan = &$reg->getChannel($channel ? $channel : 'pear.php.net');
1525
                $chan = $reg->getChannel($channel ? $channel : 'pear.php.net');
1433
                if (PEAR::isError($chan)) {
1526
                if (PEAR::isError($chan)) {
1434
                    return false;
1527
                    return false;
1435
                }
1528
                }
-
 
1529
 
1436
                if (!$chan->getMirror($value) && $chan->getName() != $value) {
1530
                if (!$chan->getMirror($value) && $chan->getName() != $value) {
1437
                    return false; // mirror does not exist
1531
                    return false; // mirror does not exist
1438
                }
1532
                }
1439
            }
1533
            }
1440
        }
1534
        }
-
 
1535
 
1441
        if (empty($this->configuration_info[$key])) {
1536
        if (!isset($this->configuration_info[$key])) {
1442
            return false;
1537
            return false;
1443
        }
1538
        }
-
 
1539
 
1444
        extract($this->configuration_info[$key]);
1540
        extract($this->configuration_info[$key]);
1445
        switch ($type) {
1541
        switch ($type) {
1446
            case 'integer':
1542
            case 'integer':
1447
                $value = (int)$value;
1543
                $value = (int)$value;
1448
                break;
1544
                break;
1449
            case 'set': {
1545
            case 'set': {
1450
                // If a valid_set is specified, require the value to
1546
                // If a valid_set is specified, require the value to
1451
                // be in the set.  If there is no valid_set, accept
1547
                // be in the set.  If there is no valid_set, accept
1452
                // any value.
1548
                // any value.
1453
                if ($valid_set) {
1549
                if ($valid_set) {
1454
                    reset($valid_set);
1550
                    reset($valid_set);
1455
                    if ((key($valid_set) === 0 && !in_array($value, $valid_set)) ||
1551
                    if ((key($valid_set) === 0 && !in_array($value, $valid_set)) ||
1456
                        (key($valid_set) !== 0 && empty($valid_set[$value])))
1552
                        (key($valid_set) !== 0 && empty($valid_set[$value])))
1457
                    {
1553
                    {
1458
                        return false;
1554
                        return false;
1459
                    }
1555
                    }
1460
                }
1556
                }
1461
                break;
1557
                break;
1462
            }
1558
            }
1463
        }
1559
        }
-
 
1560
 
1464
        if (!$channel) {
1561
        if (!$channel) {
1465
            $channel = $this->get('default_channel', null, 'pear.php.net');
1562
            $channel = $this->get('default_channel', null, 'pear.php.net');
1466
        }
1563
        }
-
 
1564
 
1467
        if (!in_array($channel, $this->_channels)) {
1565
        if (!in_array($channel, $this->_channels)) {
1468
            $this->_lazyChannelSetup($layer);
1566
            $this->_lazyChannelSetup($layer);
1469
            $reg = &$this->getRegistry($layer);
1567
            $reg = &$this->getRegistry($layer);
1470
            if ($reg) {
1568
            if ($reg) {
1471
                $channel = $reg->channelName($channel);
1569
                $channel = $reg->channelName($channel);
1472
            }
1570
            }
-
 
1571
 
1473
            if (!in_array($channel, $this->_channels)) {
1572
            if (!in_array($channel, $this->_channels)) {
1474
                return false;
1573
                return false;
1475
            }
1574
            }
1476
        }
1575
        }
-
 
1576
 
1477
        if ($channel != 'pear.php.net') {
1577
        if ($channel != 'pear.php.net') {
1478
            if (in_array($key, $this->_channelConfigInfo)) {
1578
            if (in_array($key, $this->_channelConfigInfo)) {
1479
                $this->configuration[$layer]['__channels'][$channel][$key] = $value;
1579
                $this->configuration[$layer]['__channels'][$channel][$key] = $value;
1480
                return true;
1580
                return true;
1481
            } else {
-
 
1482
                return false;
-
 
1483
            }
1581
            }
-
 
1582
 
-
 
1583
            return false;
1484
        } else {
1584
        }
-
 
1585
 
1485
            if ($key == 'default_channel') {
1586
        if ($key == 'default_channel') {
1486
                if (!isset($reg)) {
1587
            if (!isset($reg)) {
1487
                    $reg = &$this->getRegistry($layer);
1588
                $reg = &$this->getRegistry($layer);
1488
                    if (!$reg) {
1589
                if (!$reg) {
1489
                        $reg = &$this->getRegistry();
1590
                    $reg = &$this->getRegistry();
1490
                    }
-
 
1491
                }
-
 
1492
                if ($reg) {
-
 
1493
                    $value = $reg->channelName($value);
-
 
1494
                }
-
 
1495
                if (!$value) {
-
 
1496
                    return false;
-
 
1497
                }
1591
                }
1498
            }
1592
            }
-
 
1593
 
-
 
1594
            if ($reg) {
-
 
1595
                $value = $reg->channelName($value);
-
 
1596
            }
-
 
1597
 
-
 
1598
            if (!$value) {
-
 
1599
                return false;
-
 
1600
            }
1499
        }
1601
        }
-
 
1602
 
1500
        $this->configuration[$layer][$key] = $value;
1603
        $this->configuration[$layer][$key] = $value;
1501
        if ($key == 'php_dir' && !$this->_noRegistry) {
1604
        if ($key == 'php_dir' && !$this->_noRegistry) {
1502
            if (!isset($this->_registry[$layer]) ||
1605
            if (!isset($this->_registry[$layer]) ||
1503
                  $value != $this->_registry[$layer]->install_dir) {
1606
                  $value != $this->_registry[$layer]->install_dir) {
1504
                $this->_registry[$layer] = &new PEAR_Registry($value);
1607
                $this->_registry[$layer] = new PEAR_Registry($value);
1505
                $this->_regInitialized[$layer] = false;
1608
                $this->_regInitialized[$layer] = false;
1506
                $this->_registry[$layer]->setConfig($this);
1609
                $this->_registry[$layer]->setConfig($this, false);
1507
            }
1610
            }
1508
        }
1611
        }
-
 
1612
 
1509
        return true;
1613
        return true;
1510
    }
1614
    }
1511
 
-
 
1512
    // }}}
1615
 
1513
    function _lazyChannelSetup($uselayer = false)
1616
    function _lazyChannelSetup($uselayer = false)
1514
    {
1617
    {
1515
        if ($this->_noRegistry) {
1618
        if ($this->_noRegistry) {
1516
            return;
1619
            return;
1517
        }
1620
        }
-
 
1621
 
1518
        $merge = false;
1622
        $merge = false;
1519
        foreach ($this->_registry as $layer => $p) {
1623
        foreach ($this->_registry as $layer => $p) {
1520
            if ($uselayer && $uselayer != $layer) {
1624
            if ($uselayer && $uselayer != $layer) {
1521
                continue;
1625
                continue;
1522
            }
1626
            }
-
 
1627
 
1523
            if (!$this->_regInitialized[$layer]) {
1628
            if (!$this->_regInitialized[$layer]) {
1524
                if ($layer == 'default' && isset($this->_registry['user']) ||
1629
                if ($layer == 'default' && isset($this->_registry['user']) ||
1525
                      isset($this->_registry['system'])) {
1630
                      isset($this->_registry['system'])) {
1526
                    // only use the default registry if there are no alternatives
1631
                    // only use the default registry if there are no alternatives
1527
                    continue;
1632
                    continue;
1528
                }
1633
                }
-
 
1634
 
1529
                if (!is_object($this->_registry[$layer])) {
1635
                if (!is_object($this->_registry[$layer])) {
1530
                    if ($phpdir = $this->get('php_dir', $layer, 'pear.php.net')) {
1636
                    if ($phpdir = $this->get('php_dir', $layer, 'pear.php.net')) {
1531
                        $this->_registry[$layer] = &new PEAR_Registry($phpdir);
1637
                        $this->_registry[$layer] = new PEAR_Registry(
-
 
1638
                            $phpdir, false, false,
-
 
1639
                            $this->get('metadata_dir', $layer, 'pear.php.net'));
1532
                        $this->_registry[$layer]->setConfig($this);
1640
                        $this->_registry[$layer]->setConfig($this, false);
1533
                        $this->_regInitialized[$layer] = false;
1641
                        $this->_regInitialized[$layer] = false;
1534
                    } else {
1642
                    } else {
1535
                        unset($this->_registry[$layer]);
1643
                        unset($this->_registry[$layer]);
1536
                        return;
1644
                        return;
1537
                    }
1645
                    }
1538
                }
1646
                }
-
 
1647
 
1539
                $this->setChannels($this->_registry[$layer]->listChannels(), $merge);
1648
                $this->setChannels($this->_registry[$layer]->listChannels(), $merge);
1540
                $this->_regInitialized[$layer] = true;
1649
                $this->_regInitialized[$layer] = true;
1541
                $merge = true;
1650
                $merge = true;
1542
            }
1651
            }
1543
        }
1652
        }
1544
    }
1653
    }
1545
    // {{{ setChannels()
-
 
1546
    
1654
 
1547
    /**
1655
    /**
1548
     * Set the list of channels.
1656
     * Set the list of channels.
1549
     *
1657
     *
1550
     * This should be set via a call to {@link PEAR_Registry::listChannels()}
1658
     * This should be set via a call to {@link PEAR_Registry::listChannels()}
1551
     * @param array
1659
     * @param array
1552
     * @param bool
1660
     * @param bool
1553
     * @return bool success of operation
1661
     * @return bool success of operation
1554
     */
1662
     */
1555
    function setChannels($channels, $merge = false)
1663
    function setChannels($channels, $merge = false)
1556
    {
1664
    {
1557
        if (!is_array($channels)) {
1665
        if (!is_array($channels)) {
1558
            return false;
1666
            return false;
1559
        }
1667
        }
-
 
1668
 
1560
        if ($merge) {
1669
        if ($merge) {
1561
            $this->_channels = array_merge($this->_channels, $channels);
1670
            $this->_channels = array_merge($this->_channels, $channels);
1562
        } else {
1671
        } else {
1563
            $this->_channels = $channels;
1672
            $this->_channels = $channels;
1564
        }
1673
        }
-
 
1674
 
1565
        foreach ($channels as $channel) {
1675
        foreach ($channels as $channel) {
1566
            $channel = strtolower($channel);
1676
            $channel = strtolower($channel);
1567
            if ($channel == 'pear.php.net') {
1677
            if ($channel == 'pear.php.net') {
1568
                continue;
1678
                continue;
1569
            }
1679
            }
-
 
1680
 
1570
            foreach ($this->layers as $layer) {
1681
            foreach ($this->layers as $layer) {
1571
                if (!isset($this->configuration[$layer]['__channels'])) {
1682
                if (!isset($this->configuration[$layer]['__channels'])) {
1572
                    $this->configuration[$layer]['__channels'] = array();
1683
                    $this->configuration[$layer]['__channels'] = array();
1573
                }
1684
                }
1574
                if (!isset($this->configuration[$layer]['__channels'][$channel])
1685
                if (!isset($this->configuration[$layer]['__channels'][$channel])
1575
                      || !is_array($this->configuration[$layer]['__channels'][$channel])) {
1686
                      || !is_array($this->configuration[$layer]['__channels'][$channel])) {
1576
                    $this->configuration[$layer]['__channels'][$channel] = array();
1687
                    $this->configuration[$layer]['__channels'][$channel] = array();
1577
                }
1688
                }
1578
            }
1689
            }
1579
        }
1690
        }
-
 
1691
 
1580
        return true;
1692
        return true;
1581
    }
1693
    }
1582
 
-
 
1583
    // }}}
-
 
1584
    // {{{ getType(key)
-
 
1585
 
1694
 
1586
    /**
1695
    /**
1587
     * Get the type of a config value.
1696
     * Get the type of a config value.
1588
     *
1697
     *
1589
     * @param string  config key
1698
     * @param string  config key
1590
     *
1699
     *
1591
     * @return string type, one of "string", "integer", "file",
1700
     * @return string type, one of "string", "integer", "file",
1592
     * "directory", "set" or "password".
1701
     * "directory", "set" or "password".
1593
     *
1702
     *
1594
     * @access public
1703
     * @access public
1595
     *
1704
     *
1596
     */
1705
     */
1597
    function getType($key)
1706
    function getType($key)
1598
    {
1707
    {
1599
        if (isset($this->configuration_info[$key])) {
1708
        if (isset($this->configuration_info[$key])) {
1600
            return $this->configuration_info[$key]['type'];
1709
            return $this->configuration_info[$key]['type'];
1601
        }
1710
        }
1602
        return false;
1711
        return false;
1603
    }
1712
    }
1604
 
-
 
1605
    // }}}
-
 
1606
    // {{{ getDocs(key)
-
 
1607
 
1713
 
1608
    /**
1714
    /**
1609
     * Get the documentation for a config value.
1715
     * Get the documentation for a config value.
1610
     *
1716
     *
1611
     * @param string  config key
1717
     * @param string  config key
1612
     *
-
 
1613
     * @return string documentation string
1718
     * @return string documentation string
1614
     *
1719
     *
1615
     * @access public
1720
     * @access public
1616
     *
1721
     *
1617
     */
1722
     */
1618
    function getDocs($key)
1723
    function getDocs($key)
1619
    {
1724
    {
1620
        if (isset($this->configuration_info[$key])) {
1725
        if (isset($this->configuration_info[$key])) {
1621
            return $this->configuration_info[$key]['doc'];
1726
            return $this->configuration_info[$key]['doc'];
1622
        }
1727
        }
-
 
1728
 
1623
        return false;
1729
        return false;
1624
    }
1730
    }
1625
       // }}}
-
 
1626
    // {{{ getPrompt(key)
-
 
1627
 
1731
 
1628
    /**
1732
    /**
1629
     * Get the short documentation for a config value.
1733
     * Get the short documentation for a config value.
1630
     *
1734
     *
1631
     * @param string  config key
1735
     * @param string  config key
1632
     *
-
 
1633
     * @return string short documentation string
1736
     * @return string short documentation string
1634
     *
1737
     *
1635
     * @access public
1738
     * @access public
1636
     *
1739
     *
1637
     */
1740
     */
1638
    function getPrompt($key)
1741
    function getPrompt($key)
1639
    {
1742
    {
1640
        if (isset($this->configuration_info[$key])) {
1743
        if (isset($this->configuration_info[$key])) {
1641
            return $this->configuration_info[$key]['prompt'];
1744
            return $this->configuration_info[$key]['prompt'];
1642
        }
1745
        }
-
 
1746
 
1643
        return false;
1747
        return false;
1644
    }
1748
    }
1645
    // }}}
-
 
1646
    // {{{ getGroup(key)
-
 
1647
 
1749
 
1648
    /**
1750
    /**
1649
     * Get the parameter group for a config key.
1751
     * Get the parameter group for a config key.
1650
     *
1752
     *
1651
     * @param string  config key
1753
     * @param string  config key
1652
     *
-
 
1653
     * @return string parameter group
1754
     * @return string parameter group
1654
     *
1755
     *
1655
     * @access public
1756
     * @access public
1656
     *
1757
     *
1657
     */
1758
     */
1658
    function getGroup($key)
1759
    function getGroup($key)
1659
    {
1760
    {
1660
        if (isset($this->configuration_info[$key])) {
1761
        if (isset($this->configuration_info[$key])) {
1661
            return $this->configuration_info[$key]['group'];
1762
            return $this->configuration_info[$key]['group'];
1662
        }
1763
        }
-
 
1764
 
1663
        return false;
1765
        return false;
1664
    }
1766
    }
1665
 
-
 
1666
    // }}}
-
 
1667
    // {{{ getGroups()
-
 
1668
 
1767
 
1669
    /**
1768
    /**
1670
     * Get the list of parameter groups.
1769
     * Get the list of parameter groups.
1671
     *
1770
     *
1672
     * @return array list of parameter groups
1771
     * @return array list of parameter groups
1673
     *
1772
     *
1674
     * @access public
1773
     * @access public
1675
     *
1774
     *
1676
     */
1775
     */
1677
    function getGroups()
1776
    function getGroups()
1678
    {
1777
    {
1679
        $tmp = array();
1778
        $tmp = array();
1680
        foreach ($this->configuration_info as $key => $info) {
1779
        foreach ($this->configuration_info as $key => $info) {
1681
            $tmp[$info['group']] = 1;
1780
            $tmp[$info['group']] = 1;
1682
        }
1781
        }
-
 
1782
 
1683
        return array_keys($tmp);
1783
        return array_keys($tmp);
1684
    }
1784
    }
1685
 
-
 
1686
    // }}}
-
 
1687
    // {{{ getGroupKeys()
-
 
1688
 
1785
 
1689
    /**
1786
    /**
1690
     * Get the list of the parameters in a group.
1787
     * Get the list of the parameters in a group.
1691
     *
1788
     *
1692
     * @param string $group parameter group
1789
     * @param string $group parameter group
1693
     *
-
 
1694
     * @return array list of parameters in $group
1790
     * @return array list of parameters in $group
1695
     *
1791
     *
1696
     * @access public
1792
     * @access public
1697
     *
1793
     *
1698
     */
1794
     */
1699
    function getGroupKeys($group)
1795
    function getGroupKeys($group)
1700
    {
1796
    {
1701
        $keys = array();
1797
        $keys = array();
1702
        foreach ($this->configuration_info as $key => $info) {
1798
        foreach ($this->configuration_info as $key => $info) {
1703
            if ($info['group'] == $group) {
1799
            if ($info['group'] == $group) {
1704
                $keys[] = $key;
1800
                $keys[] = $key;
1705
            }
1801
            }
1706
        }
1802
        }
-
 
1803
 
1707
        return $keys;
1804
        return $keys;
1708
    }
1805
    }
1709
 
-
 
1710
    // }}}
-
 
1711
    // {{{ getSetValues(key)
-
 
1712
 
1806
 
1713
    /**
1807
    /**
1714
     * Get the list of allowed set values for a config value.  Returns
1808
     * Get the list of allowed set values for a config value.  Returns
1715
     * NULL for config values that are not sets.
1809
     * NULL for config values that are not sets.
1716
     *
1810
     *
1717
     * @param string  config key
1811
     * @param string  config key
1718
     *
-
 
1719
     * @return array enumerated array of set values, or NULL if the
1812
     * @return array enumerated array of set values, or NULL if the
1720
     *               config key is unknown or not a set
1813
     *               config key is unknown or not a set
1721
     *
1814
     *
1722
     * @access public
1815
     * @access public
1723
     *
1816
     *
1724
     */
1817
     */
1725
    function getSetValues($key)
1818
    function getSetValues($key)
1726
    {
1819
    {
1727
        if (isset($this->configuration_info[$key]) &&
1820
        if (isset($this->configuration_info[$key]) &&
1728
            isset($this->configuration_info[$key]['type']) &&
1821
            isset($this->configuration_info[$key]['type']) &&
1729
            $this->configuration_info[$key]['type'] == 'set')
1822
            $this->configuration_info[$key]['type'] == 'set')
1730
        {
1823
        {
1731
            $valid_set = $this->configuration_info[$key]['valid_set'];
1824
            $valid_set = $this->configuration_info[$key]['valid_set'];
1732
            reset($valid_set);
1825
            reset($valid_set);
1733
            if (key($valid_set) === 0) {
1826
            if (key($valid_set) === 0) {
1734
                return $valid_set;
1827
                return $valid_set;
1735
            }
1828
            }
-
 
1829
 
1736
            return array_keys($valid_set);
1830
            return array_keys($valid_set);
1737
        }
1831
        }
-
 
1832
 
1738
        return null;
1833
        return null;
1739
    }
1834
    }
1740
 
-
 
1741
    // }}}
-
 
1742
    // {{{ getKeys()
-
 
1743
 
1835
 
1744
    /**
1836
    /**
1745
     * Get all the current config keys.
1837
     * Get all the current config keys.
1746
     *
1838
     *
1747
     * @return array simple array of config keys
1839
     * @return array simple array of config keys
1748
     *
1840
     *
1749
     * @access public
1841
     * @access public
1750
     */
1842
     */
1751
    function getKeys()
1843
    function getKeys()
1752
    {
1844
    {
1753
        $keys = array();
1845
        $keys = array();
1754
        foreach ($this->layers as $layer) {
1846
        foreach ($this->layers as $layer) {
1755
            $test = $this->configuration[$layer];
1847
            $test = $this->configuration[$layer];
1756
            if (isset($test['__channels'])) {
1848
            if (isset($test['__channels'])) {
1757
                foreach ($test['__channels'] as $channel => $configs) {
1849
                foreach ($test['__channels'] as $channel => $configs) {
1758
                    $keys = array_merge($keys, $configs);
1850
                    $keys = array_merge($keys, $configs);
1759
                }
1851
                }
1760
            }
1852
            }
-
 
1853
 
1761
            unset($test['__channels']);
1854
            unset($test['__channels']);
1762
            $keys = array_merge($keys, $test);
1855
            $keys = array_merge($keys, $test);
-
 
1856
 
1763
        }
1857
        }
1764
        return array_keys($keys);
1858
        return array_keys($keys);
1765
    }
1859
    }
1766
 
-
 
1767
    // }}}
-
 
1768
    // {{{ remove(key, [layer])
-
 
1769
 
1860
 
1770
    /**
1861
    /**
1771
     * Remove the a config key from a specific config layer.
1862
     * Remove the a config key from a specific config layer.
1772
     *
1863
     *
1773
     * @param string config key
1864
     * @param string config key
1774
     *
-
 
1775
     * @param string (optional) config layer
1865
     * @param string (optional) config layer
1776
     *
1866
     * @param string (optional) channel (defaults to default channel)
1777
     * @return bool TRUE on success, FALSE on failure
1867
     * @return bool TRUE on success, FALSE on failure
1778
     *
1868
     *
1779
     * @access public
1869
     * @access public
1780
     */
1870
     */
1781
    function remove($key, $layer = 'user')
1871
    function remove($key, $layer = 'user', $channel = null)
1782
    {
1872
    {
-
 
1873
        if ($channel === null) {
1783
        $channel = $this->getDefaultChannel();
1874
            $channel = $this->getDefaultChannel();
-
 
1875
        }
-
 
1876
 
1784
        if ($channel !== 'pear.php.net') {
1877
        if ($channel !== 'pear.php.net') {
1785
            if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1878
            if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1786
                unset($this->configuration[$layer]['__channels'][$channel][$key]);
1879
                unset($this->configuration[$layer]['__channels'][$channel][$key]);
1787
                return true;
1880
                return true;
1788
            }
1881
            }
1789
        }
1882
        }
-
 
1883
 
1790
        if (isset($this->configuration[$layer][$key])) {
1884
        if (isset($this->configuration[$layer][$key])) {
1791
            unset($this->configuration[$layer][$key]);
1885
            unset($this->configuration[$layer][$key]);
1792
            return true;
1886
            return true;
1793
        }
1887
        }
-
 
1888
 
1794
        return false;
1889
        return false;
1795
    }
1890
    }
1796
 
-
 
1797
    // }}}
-
 
1798
    // {{{ removeLayer(layer)
-
 
1799
 
1891
 
1800
    /**
1892
    /**
1801
     * Temporarily remove an entire config layer.  USE WITH CARE!
1893
     * Temporarily remove an entire config layer.  USE WITH CARE!
1802
     *
1894
     *
1803
     * @param string config key
1895
     * @param string config key
1804
     *
-
 
1805
     * @param string (optional) config layer
1896
     * @param string (optional) config layer
1806
     *
-
 
1807
     * @return bool TRUE on success, FALSE on failure
1897
     * @return bool TRUE on success, FALSE on failure
1808
     *
1898
     *
1809
     * @access public
1899
     * @access public
1810
     */
1900
     */
1811
    function removeLayer($layer)
1901
    function removeLayer($layer)
1812
    {
1902
    {
1813
        if (isset($this->configuration[$layer])) {
1903
        if (isset($this->configuration[$layer])) {
1814
            $this->configuration[$layer] = array();
1904
            $this->configuration[$layer] = array();
1815
            return true;
1905
            return true;
1816
        }
1906
        }
-
 
1907
 
1817
        return false;
1908
        return false;
1818
    }
1909
    }
1819
 
-
 
1820
    // }}}
-
 
1821
    // {{{ store([layer])
-
 
1822
 
1910
 
1823
    /**
1911
    /**
1824
     * Stores configuration data in a layer.
1912
     * Stores configuration data in a layer.
1825
     *
1913
     *
1826
     * @param string config layer to store
1914
     * @param string config layer to store
1827
     *
-
 
1828
     * @return bool TRUE on success, or PEAR error on failure
1915
     * @return bool TRUE on success, or PEAR error on failure
1829
     *
1916
     *
1830
     * @access public
1917
     * @access public
1831
     */
1918
     */
1832
    function store($layer = 'user', $data = null)
1919
    function store($layer = 'user', $data = null)
1833
    {
1920
    {
1834
        return $this->writeConfigFile(null, $layer, $data);
1921
        return $this->writeConfigFile(null, $layer, $data);
1835
    }
1922
    }
1836
 
-
 
1837
    // }}}
-
 
1838
    // {{{ toDefault(key)
-
 
1839
 
-
 
1840
    /**
-
 
1841
     * Unset the user-defined value of a config key, reverting the
-
 
1842
     * value to the system-defined one.
-
 
1843
     *
-
 
1844
     * @param string config key
-
 
1845
     *
-
 
1846
     * @return bool TRUE on success, FALSE on failure
-
 
1847
     *
-
 
1848
     * @access public
-
 
1849
     */
-
 
1850
    function toDefault($key)
-
 
1851
    {
-
 
1852
        trigger_error("PEAR_Config::toDefault() deprecated, use PEAR_Config::remove() instead", E_USER_NOTICE);
-
 
1853
        return $this->remove($key, 'user');
-
 
1854
    }
-
 
1855
 
-
 
1856
    // }}}
-
 
1857
    // {{{ definedBy(key)
-
 
1858
 
1923
 
1859
    /**
1924
    /**
1860
     * Tells what config layer that gets to define a key.
1925
     * Tells what config layer that gets to define a key.
1861
     *
1926
     *
1862
     * @param string config key
1927
     * @param string config key
1863
     * @param boolean return the defining channel
1928
     * @param boolean return the defining channel
1864
     *
1929
     *
1865
     * @return string|array the config layer, or an empty string if not found.
1930
     * @return string|array the config layer, or an empty string if not found.
1866
     *
1931
     *
1867
     *         if $returnchannel, the return is an array array('layer' => layername,
1932
     *         if $returnchannel, the return is an array array('layer' => layername,
1868
     *         'channel' => channelname), or an empty string if not found
1933
     *         'channel' => channelname), or an empty string if not found
1869
     *
1934
     *
1870
     * @access public
1935
     * @access public
1871
     */
1936
     */
1872
    function definedBy($key, $returnchannel = false)
1937
    function definedBy($key, $returnchannel = false)
1873
    {
1938
    {
1874
        foreach ($this->layers as $layer) {
1939
        foreach ($this->layers as $layer) {
1875
            $channel = $this->getDefaultChannel();
1940
            $channel = $this->getDefaultChannel();
1876
            if ($channel !== 'pear.php.net') {
1941
            if ($channel !== 'pear.php.net') {
1877
                if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1942
                if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1878
                    if ($returnchannel) {
1943
                    if ($returnchannel) {
1879
                        return array('layer' => $layer, 'channel' => $channel);
1944
                        return array('layer' => $layer, 'channel' => $channel);
1880
                    }
1945
                    }
1881
                    return $layer;
1946
                    return $layer;
1882
                }
1947
                }
1883
            }
1948
            }
-
 
1949
 
1884
            if (isset($this->configuration[$layer][$key])) {
1950
            if (isset($this->configuration[$layer][$key])) {
1885
                if ($returnchannel) {
1951
                if ($returnchannel) {
1886
                    return array('layer' => $layer, 'channel' => 'pear.php.net');
1952
                    return array('layer' => $layer, 'channel' => 'pear.php.net');
1887
                }
1953
                }
1888
                return $layer;
1954
                return $layer;
1889
            }
1955
            }
1890
        }
1956
        }
1891
        return '';
-
 
1892
    }
-
 
1893
 
-
 
1894
    // }}}
-
 
1895
    // {{{ isDefaulted(key)
-
 
1896
 
-
 
1897
    /**
-
 
1898
     * Tells whether a config value has a system-defined value.
-
 
1899
     *
-
 
1900
     * @param string   config key
-
 
1901
     *
1957
 
1902
     * @return bool
-
 
1903
     *
-
 
1904
     * @access public
-
 
1905
     *
-
 
1906
     * @deprecated
-
 
1907
     */
-
 
1908
    function isDefaulted($key)
-
 
1909
    {
-
 
1910
        trigger_error("PEAR_Config::isDefaulted() deprecated, use PEAR_Config::definedBy() instead", E_USER_NOTICE);
-
 
1911
        return $this->definedBy($key) == 'system';
1958
        return '';
1912
    }
-
 
1913
 
-
 
1914
    // }}}
-
 
1915
    // {{{ isDefined(key)
1959
    }
1916
 
1960
 
1917
    /**
1961
    /**
1918
     * Tells whether a given key exists as a config value.
1962
     * Tells whether a given key exists as a config value.
1919
     *
1963
     *
1920
     * @param string config key
1964
     * @param string config key
1921
     *
-
 
1922
     * @return bool whether <config key> exists in this object
1965
     * @return bool whether <config key> exists in this object
1923
     *
1966
     *
1924
     * @access public
1967
     * @access public
1925
     */
1968
     */
1926
    function isDefined($key)
1969
    function isDefined($key)
1927
    {
1970
    {
1928
        foreach ($this->layers as $layer) {
1971
        foreach ($this->layers as $layer) {
1929
            if (isset($this->configuration[$layer][$key])) {
1972
            if (isset($this->configuration[$layer][$key])) {
1930
                return true;
1973
                return true;
1931
            }
1974
            }
1932
        }
1975
        }
-
 
1976
 
1933
        return false;
1977
        return false;
1934
    }
1978
    }
1935
 
-
 
1936
    // }}}
-
 
1937
    // {{{ isDefinedLayer(key)
-
 
1938
 
1979
 
1939
    /**
1980
    /**
1940
     * Tells whether a given config layer exists.
1981
     * Tells whether a given config layer exists.
1941
     *
1982
     *
1942
     * @param string config layer
1983
     * @param string config layer
1943
     *
-
 
1944
     * @return bool whether <config layer> exists in this object
1984
     * @return bool whether <config layer> exists in this object
1945
     *
1985
     *
1946
     * @access public
1986
     * @access public
1947
     */
1987
     */
1948
    function isDefinedLayer($layer)
1988
    function isDefinedLayer($layer)
1949
    {
1989
    {
1950
        return isset($this->configuration[$layer]);
1990
        return isset($this->configuration[$layer]);
1951
    }
1991
    }
1952
 
-
 
1953
    // }}}
-
 
1954
    // {{{ getLayers()
-
 
1955
 
1992
 
1956
    /**
1993
    /**
1957
     * Returns the layers defined (except the 'default' one)
1994
     * Returns the layers defined (except the 'default' one)
1958
     *
1995
     *
1959
     * @return array of the defined layers
1996
     * @return array of the defined layers
1960
     */
1997
     */
1961
    function getLayers()
1998
    function getLayers()
1962
    {
1999
    {
1963
        $cf = $this->configuration;
2000
        $cf = $this->configuration;
1964
        unset($cf['default']);
2001
        unset($cf['default']);
1965
        return array_keys($cf);
2002
        return array_keys($cf);
1966
    }
2003
    }
1967
 
-
 
1968
    // }}}
-
 
1969
    // {{{ apiVersion()
2004
 
1970
    function apiVersion()
2005
    function apiVersion()
1971
    {
2006
    {
1972
        return '1.1';
2007
        return '1.1';
1973
    }
2008
    }
1974
    // }}}
-
 
1975
 
2009
 
1976
    /**
2010
    /**
1977
     * @return PEAR_Registry
2011
     * @return PEAR_Registry
1978
     */
2012
     */
1979
    function &getRegistry($use = null)
2013
    function &getRegistry($use = null)
1980
    {
2014
    {
1981
        if ($use === null) {
2015
        $layer = $use === null ? 'user' : $use;
1982
            $layer = 'user';
-
 
1983
        } else {
-
 
1984
            $layer = $use;
-
 
1985
        }
-
 
1986
        if (isset($this->_registry[$layer])) {
2016
        if (isset($this->_registry[$layer])) {
1987
            return $this->_registry[$layer];
2017
            return $this->_registry[$layer];
1988
        } elseif ($use === null && isset($this->_registry['system'])) {
2018
        } elseif ($use === null && isset($this->_registry['system'])) {
1989
            return $this->_registry['system'];
2019
            return $this->_registry['system'];
1990
        } elseif ($use === null && isset($this->_registry['default'])) {
2020
        } elseif ($use === null && isset($this->_registry['default'])) {
1991
            return $this->_registry['default'];
2021
            return $this->_registry['default'];
1992
        } elseif ($use) {
2022
        } elseif ($use) {
1993
            $a = false;
2023
            $a = false;
1994
            return $a;
2024
            return $a;
1995
        } else {
-
 
1996
            // only go here if null was passed in
-
 
1997
            echo "CRITICAL ERROR: Registry could not be initialized from any value";
-
 
1998
            exit(1);
-
 
1999
        }
2025
        }
-
 
2026
 
-
 
2027
        // only go here if null was passed in
-
 
2028
        echo "CRITICAL ERROR: Registry could not be initialized from any value";
-
 
2029
        exit(1);
2000
    }
2030
    }
-
 
2031
 
2001
    /**
2032
    /**
2002
     * This is to allow customization like the use of installroot
2033
     * This is to allow customization like the use of installroot
2003
     * @param PEAR_Registry
2034
     * @param PEAR_Registry
2004
     * @return bool
2035
     * @return bool
2005
     */
2036
     */
2006
    function setRegistry(&$reg, $layer = 'user')
2037
    function setRegistry(&$reg, $layer = 'user')
2007
    {
2038
    {
2008
        if ($this->_noRegistry) {
2039
        if ($this->_noRegistry) {
2009
            return false;
2040
            return false;
2010
        }
2041
        }
-
 
2042
 
2011
        if (!in_array($layer, array('user', 'system'))) {
2043
        if (!in_array($layer, array('user', 'system'))) {
2012
            return false;
2044
            return false;
2013
        }
2045
        }
-
 
2046
 
2014
        $this->_registry[$layer] = &$reg;
2047
        $this->_registry[$layer] = &$reg;
2015
        if (is_object($reg)) {
2048
        if (is_object($reg)) {
2016
            $this->_registry[$layer]->setConfig($this);
2049
            $this->_registry[$layer]->setConfig($this, false);
2017
        }
2050
        }
-
 
2051
 
2018
        return true;
2052
        return true;
2019
    }
2053
    }
2020
 
2054
 
2021
    function noRegistry()
2055
    function noRegistry()
2022
    {
2056
    {
2023
        $this->_noRegistry = true;
2057
        $this->_noRegistry = true;
2024
    }
2058
    }
2025
 
2059
 
2026
    /**
2060
    /**
2027
     * @return PEAR_Remote
-
 
2028
     */
-
 
2029
    function &getRemote()
-
 
2030
    {
-
 
2031
        $remote = &new PEAR_Remote($this);
-
 
2032
        return $remote;
-
 
2033
    }
-
 
2034
 
-
 
2035
    /**
-
 
2036
     * @return PEAR_REST
2061
     * @return PEAR_REST
2037
     */
2062
     */
2038
    function &getREST($version, $options = array())
2063
    function &getREST($version, $options = array())
2039
    {
2064
    {
2040
        $version = str_replace('.', '', $version);
2065
        $version = str_replace('.', '', $version);
2041
        if (!class_exists($class = 'PEAR_REST_' . $version)) {
2066
        if (!class_exists($class = 'PEAR_REST_' . $version)) {
2042
            require_once 'PEAR/REST/' . $version . '.php';
2067
            require_once 'PEAR/REST/' . $version . '.php';
2043
        }
2068
        }
-
 
2069
 
2044
        $remote = &new $class($this, $options);
2070
        $remote = new $class($this, $options);
2045
        return $remote;
2071
        return $remote;
2046
    }
2072
    }
2047
 
2073
 
2048
    /**
2074
    /**
2049
     * The ftp server is set in {@link readFTPConfigFile()}.  It exists only if a
2075
     * The ftp server is set in {@link readFTPConfigFile()}.  It exists only if a
2050
     * remote configuration file has been specified
2076
     * remote configuration file has been specified
2051
     * @return PEAR_FTP|false
2077
     * @return PEAR_FTP|false
2052
     */
2078
     */
2053
    function &getFTP()
2079
    function &getFTP()
2054
    {
2080
    {
2055
        if (isset($this->_ftp)) {
2081
        if (isset($this->_ftp)) {
2056
            return $this->_ftp;
2082
            return $this->_ftp;
2057
        } else {
-
 
2058
            $a = false;
-
 
2059
            return $a;
-
 
2060
        }
2083
        }
2061
    }
-
 
-
 
2084
 
2062
 
2085
        $a = false;
-
 
2086
        return $a;
2063
    // {{{ _prependPath($path, $prepend)
2087
    }
2064
 
2088
 
2065
    function _prependPath($path, $prepend)
2089
    function _prependPath($path, $prepend)
2066
    {
2090
    {
2067
        if (strlen($prepend) > 0) {
2091
        if (strlen($prepend) > 0) {
2068
            if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
2092
            if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
2069
                if (preg_match('/^[a-z]:/i', $prepend)) {
2093
                if (preg_match('/^[a-z]:/i', $prepend)) {
2070
                    $prepend = substr($prepend, 2);
2094
                    $prepend = substr($prepend, 2);
2071
                } elseif ($prepend{0} != '\\') {
2095
                } elseif ($prepend{0} != '\\') {
2072
                    $prepend = "\\$prepend";
2096
                    $prepend = "\\$prepend";
2073
                }
2097
                }
2074
                $path = substr($path, 0, 2) . $prepend . substr($path, 2);
2098
                $path = substr($path, 0, 2) . $prepend . substr($path, 2);
2075
            } else {
2099
            } else {
2076
                $path = $prepend . $path;
2100
                $path = $prepend . $path;
2077
            }
2101
            }
2078
        }
2102
        }
2079
        return $path;
2103
        return $path;
2080
    }
2104
    }
2081
    // }}}
-
 
2082
 
2105
 
2083
    /**
2106
    /**
2084
     * @param string|false installation directory to prepend to all _dir variables, or false to
2107
     * @param string|false installation directory to prepend to all _dir variables, or false to
2085
     *                     disable
2108
     *                     disable
2086
     */
2109
     */
2087
    function setInstallRoot($root)
2110
    function setInstallRoot($root)
2088
    {
2111
    {
2089
        if (substr($root, -1) == DIRECTORY_SEPARATOR) {
2112
        if (substr($root, -1) == DIRECTORY_SEPARATOR) {
2090
            $root = substr($root, 0, -1);
2113
            $root = substr($root, 0, -1);
2091
        }
2114
        }
2092
        $old = $this->_installRoot;
2115
        $old = $this->_installRoot;
2093
        $this->_installRoot = $root;
2116
        $this->_installRoot = $root;
2094
        if (($old != $root) && !$this->_noRegistry) {
2117
        if (($old != $root) && !$this->_noRegistry) {
2095
            foreach (array_keys($this->_registry) as $layer) {
2118
            foreach (array_keys($this->_registry) as $layer) {
2096
                if ($layer == 'ftp' || !isset($this->_registry[$layer])) {
2119
                if ($layer == 'ftp' || !isset($this->_registry[$layer])) {
2097
                    continue;
2120
                    continue;
2098
                }
2121
                }
2099
                $this->_registry[$layer] =
2122
                $this->_registry[$layer] =
-
 
2123
                    new PEAR_Registry(
-
 
2124
                        $this->get('php_dir', $layer, 'pear.php.net'), false, false,
2100
                    &new PEAR_Registry($this->get('php_dir', $layer, 'pear.php.net'));
2125
                        $this->get('metadata_dir', $layer, 'pear.php.net'));
2101
                $this->_registry[$layer]->setConfig($this);
2126
                $this->_registry[$layer]->setConfig($this, false);
2102
                $this->_regInitialized[$layer] = false;
2127
                $this->_regInitialized[$layer] = false;
2103
            }
2128
            }
2104
        }
2129
        }
2105
    }
2130
    }
2106
}
2131
}
2107
 
-
 
2108
?>
-