Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
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
 */
Line 23... Line 16...
23
 
16
 
Line 26... Line 19...
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';
-
 
Line 32... Line 24...
32
 
24
 
33
/**
25
/**
34
 * Last created PEAR_Config instance.
26
 * Last created PEAR_Config instance.
35
 * @var object
27
 * @var object
Line 47... Line 39...
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_*.
Line 49... Line 41...
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
-
 
43
// the "pear" or the "pecl" command
-
 
44
if (!defined('PEAR_RUNTYPE')) {
-
 
45
    define('PEAR_RUNTYPE', 'pear');
Line 51... Line 46...
51
// the "pear" or the "pecl" command
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 {
Line 82... Line 77...
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',
-
 
89
               $PEAR_INSTALL_DIR);
83
        define('PEAR_CONFIG_DEFAULT_PHP_DIR', $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
    }
Line -... Line 87...
-
 
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', '');
93
}
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'));
Line 129... Line 130...
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
}
Line -... Line 134...
-
 
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 {
Line 231... Line 260...
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
     */
Line 252... Line 279...
252
        'system' => '',
279
        'system' => '',
253
        'user' => '',
280
        'user' => '',
254
        );
281
        );
Line 255... Line 282...
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.
Line 270... Line 297...
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
        );
Line 288... Line 315...
288
 
315
 
289
    /**
316
    /**
290
     * Channels that can be accessed
317
     * Channels that can be accessed
Line 415... Line 442...
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',
Line 438... Line 486...
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(
Line 450... Line 498...
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',
Line 539... Line 608...
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
        );
Line 543... Line -...
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
Line 557... Line 622...
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
        }
Line 582... Line 649...
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
            }
Line 593... Line 660...
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) {
Line 610... Line 677...
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'];
Line 613... Line 680...
613
        }
680
        }
-
 
681
 
-
 
682
        $this->_registry['default'] = new PEAR_Registry(
614
 
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;
Line -... Line 687...
-
 
687
        //$GLOBALS['_PEAR_Config_instance'] = &$this;
-
 
688
    }
618
        //$GLOBALS['_PEAR_Config_instance'] = &$this;
689
 
619
    }
690
    /**
-
 
691
     * Return the default locations of user and system configuration files
-
 
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',
Line 620... Line 705...
620
 
705
            'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf'
621
    // }}}
706
        );
622
    // {{{ singleton([file], [defaults_file])
707
    }
623
 
708
 
Line 630... Line 715...
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
        }
Line 644... Line 727...
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;
Line 648... Line 731...
648
        }
731
        }
649
 
732
 
650
        $GLOBALS['_PEAR_Config_instance'] = &$t_conf;
733
        $GLOBALS['_PEAR_Config_instance'] = &$t_conf;
Line 651... Line -...
651
        return $GLOBALS['_PEAR_Config_instance'];
-
 
652
    }
-
 
653
 
-
 
654
    // }}}
734
        return $GLOBALS['_PEAR_Config_instance'];
655
    // {{{ validConfiguration()
735
    }
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
Line 663... Line 743...
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
    }
Line 670... Line -...
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.
Line 689... Line 767...
689
        if ($file === null) {
767
        if ($file === null) {
690
            $file = $this->files[$layer];
768
            $file = $this->files[$layer];
691
        }
769
        }
Line 692... Line 770...
692
 
770
 
693
        $data = $this->_readConfigDataFrom($file);
-
 
694
 
771
        $data = $this->_readConfigDataFrom($file);
695
        if (PEAR::isError($data)) {
772
        if (PEAR::isError($data)) {
696
            if ($strict) {
-
 
697
                $this->_errorsFound++;
-
 
698
                $this->lastError = $data;
-
 
699
 
-
 
700
                return $data;
-
 
701
            } else {
773
            if (!$strict) {
702
                return true;
774
                return true;
-
 
775
            }
703
            }
776
 
704
        } else {
777
            $this->_errorsFound++;
-
 
778
            $this->lastError = $data;
-
 
779
 
705
            $this->files[$layer] = $file;
780
            return $data;
Line -... Line 781...
-
 
781
        }
706
        }
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();
-
 
787
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
-
 
788
            $this->_registry[$layer] = new PEAR_Registry(
711
        if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
789
                $phpdir, false, false,
712
            $this->_registry[$layer] = &new PEAR_Registry($phpdir);
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
        }
Line 718... Line -...
718
        return true;
-
 
719
    }
-
 
720
 
796
        return true;
721
    // }}}
797
    }
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
Line 733... Line 809...
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
    }
Line 790... Line -...
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()
Line 806... Line 885...
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
    }
Line 810... Line -...
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);
Line 826... Line -...
826
    }
-
 
827
 
-
 
828
    // }}}
-
 
829
    // {{{ mergeConfigFile(file, [override], [layer])
902
    }
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
Line 841... Line 914...
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
    }
Line 878... Line -...
878
 
-
 
879
    // }}}
-
 
880
    // {{{ arrayMergeRecursive($arr2, $arr1)
957
 
881
    /**
958
    /**
882
     * @param array
959
     * @param array
883
     * @param array
960
     * @param array
884
     * @return array
-
 
885
     * @static
961
     * @return array
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])) {
Line 901... Line 977...
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
    }
Line 908... Line -...
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
Line 928... Line 1002...
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
    }
Line 958... Line -...
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
-
 
967
     *
1043
     * @param string file to read from
968
     * @return array configuration data or a PEAR error on failure
-
 
969
     *
1044
     * @return array configuration data or a PEAR error on failure
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");
-
 
1052
        }
977
        }
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");
-
 
1056
        }
980
        }
1057
 
981
        $size = filesize($file);
-
 
982
        $rt = get_magic_quotes_runtime();
-
 
983
        set_magic_quotes_runtime(0);
1058
        $size = filesize($file);
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
        }
-
 
989
        
-
 
Line 990... Line 1063...
990
        set_magic_quotes_runtime($rt);
1063
        }
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)) {
Line 997... Line 1070...
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', '<')) {
-
 
Line -... Line 1075...
-
 
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
Line 1017... Line 1090...
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
    }
Line 1033... Line -...
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
    */
-
 
1041
 
1112
    */
1042
    function getConfFile($layer)
1113
    function getConfFile($layer)
1043
    {
1114
    {
1044
        return $this->files[$layer];
1115
        return $this->files[$layer];
Line 1045... Line -...
1045
    }
-
 
1046
 
-
 
1047
    // }}}
1116
    }
-
 
1117
 
1048
 
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
     */
-
 
1124
    function _addConfigVars($class, $vars)
-
 
1125
    {
-
 
1126
        static $called = array();
-
 
1127
        if (isset($called[$class])) {
-
 
1128
            return;
-
 
1129
        }
1054
    function _addConfigVars($vars)
1130
 
1055
    {
1131
        $called[$class] = 1;
1056
        if (count($vars) > 3) {
1132
        if (count($vars) > 3) {
-
 
1133
            return $this->raiseError('Roles can only define 3 new config variables or less');
1057
            return $this->raiseError('Roles can only define 3 new config variables or less');
1134
        }
1058
        }
1135
 
1059
        foreach ($vars as $name => $var) {
1136
        foreach ($vars as $name => $var) {
1060
            if (!is_array($var)) {
1137
            if (!is_array($var)) {
-
 
1138
                return $this->raiseError('Configuration information must be an array');
1061
                return $this->raiseError('Configuration information must be an array');
1139
            }
1062
            }
1140
 
1063
            if (!isset($var['type'])) {
-
 
1064
                return $this->raiseError('Configuration information must contain a type');
1141
            if (!isset($var['type'])) {
1065
            } else {
1142
                return $this->raiseError('Configuration information must contain a type');
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, ' .
-
 
1070
                        'mask, set, or password');
1146
                      'Configuration type must be one of directory, file, string, ' .
1071
                }
1147
                      'mask, set, or password');
1072
            }
1148
            }
1073
            if (!isset($var['default'])) {
1149
            if (!isset($var['default'])) {
1074
                return $this->raiseError(
1150
                return $this->raiseError(
-
 
1151
                    'Configuration information must contain a default value ("default" index)');
1075
                    'Configuration information must contain a default value ("default" index)');
1152
            }
1076
            } else {
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) {
-
 
1083
                            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'];
1159
                    } elseif (strpos($config_var, 'constant') === 0) {
1094
                        } else {
1160
                        if (!defined($val)) {
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 "' .
-
 
1164
                                $name . '"');
-
 
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 ' .
1098
                                $name . '"');
1174
                            'default value for configuration variable "' .
1099
                        }
-
 
1100
                    }
-
 
1101
                    $var['default'] = $real_default;
-
 
1102
                }
-
 
1103
                if ($var['type'] == 'integer') {
1175
                            $name . '"');
-
 
1176
                    }
1104
                    $var['default'] = (integer) $var['default'];
1177
                }
-
 
1178
                $var['default'] = $real_default;
-
 
1179
            }
-
 
1180
 
-
 
1181
            if ($var['type'] == 'integer') {
-
 
1182
                $var['default'] = (integer) $var['default'];
1105
                }
1183
            }
1106
            }
1184
 
1107
            if (!isset($var['doc'])) {
1185
            if (!isset($var['doc'])) {
1108
                return $this->raiseError(
1186
                return $this->raiseError(
-
 
1187
                    'Configuration information must contain a summary ("doc" index)');
1109
                    'Configuration information must contain a summary ("doc" index)');
1188
            }
1110
            }
1189
 
1111
            if (!isset($var['prompt'])) {
1190
            if (!isset($var['prompt'])) {
1112
                return $this->raiseError(
1191
                return $this->raiseError(
-
 
1192
                    'Configuration information must contain a simple prompt ("prompt" index)');
1113
                    'Configuration information must contain a simple prompt ("prompt" index)');
1193
            }
1114
            }
1194
 
1115
            if (!isset($var['group'])) {
1195
            if (!isset($var['group'])) {
1116
                return $this->raiseError(
1196
                return $this->raiseError(
-
 
1197
                    'Configuration information must contain a simple group ("group" index)');
1117
                    'Configuration information must contain a simple group ("group" index)');
1198
            }
1118
            }
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 .
-
 
1202
                    '" already exists');
1121
                    '" already exists');
1203
            }
1122
            }
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
-
 
1207
            $this->_channelConfigInfo[] = $name;
1125
            $this->_channelConfigInfo[] = $name;
1208
        }
1126
        }
1209
 
Line 1127... Line -...
1127
        return true;
-
 
1128
    }
-
 
1129
 
1210
        return true;
1130
    // {{{ _encodeOutput(&data)
1211
    }
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.
-
 
1136
     *
1216
     * that people spot cleartext passwords by accident.
1137
     * @param array (reference) array to encode values in
-
 
1138
     *
1217
     *
1139
     * @return bool TRUE on success
1218
     * @param array (reference) array to encode values in
1140
     *
1219
     * @return bool TRUE on success
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) {
-
 
1227
                    $this->_encodeOutput($data['__channels'][$channel]);
1148
                    $this->_encodeOutput($data['__channels'][$channel]);
1228
                }
1149
                }
1229
            }
1150
            }
1230
 
-
 
1231
            if (!isset($this->configuration_info[$key])) {
1151
            if (!isset($this->configuration_info[$key])) {
1232
                continue;
1152
                continue;
1233
            }
1153
            }
1234
 
1154
            $type = $this->configuration_info[$key]['type'];
1235
            $type = $this->configuration_info[$key]['type'];
1155
            switch ($type) {
1236
            switch ($type) {
Line 1163... Line 1244...
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
    }
Line 1170... Line -...
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
-
 
1178
     *
1256
     * @param array (reference) array to encode values in
1179
     * @return bool TRUE on success
-
 
1180
     *
1257
     * @return bool TRUE on success
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;
-
 
1266
        }
1189
        }
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
                }
-
 
1273
            }
1195
            }
1274
 
1196
            if (!isset($this->configuration_info[$key])) {
1275
            if (!isset($this->configuration_info[$key])) {
1197
                continue;
1276
                continue;
-
 
1277
            }
1198
            }
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]);
Line 1206... Line 1286...
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
    }
Line 1213... Line -...
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
Line 1232... Line 1311...
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
    }
Line 1248... Line -...
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
-
 
1255
     *
1336
     * @param string config key
1256
     * @return mixed the config value, or NULL if not found
-
 
1257
     *
1337
     * @return mixed the config value, or NULL if not found
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;
-
 
1344
        }
1264
        }
1345
 
1265
        if ($key == '__channels') {
1346
        if ($key == '__channels') {
1266
            return null;
1347
            return null;
-
 
1348
        }
1267
        }
1349
 
1268
        if ($key == 'default_channel') {
1350
        if ($key == 'default_channel') {
1269
            return $this->getDefaultChannel($layer);
1351
            return $this->getDefaultChannel($layer);
-
 
1352
        }
1270
        }
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) {
Line 1286... Line 1369...
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) {
Line 1297... Line 1381...
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
                    }
Line 1321... Line 1407...
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
    }
Line 1342... Line -...
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
-
 
1350
     *
1437
     * @param string config key
1351
     * @return mixed the config value, or NULL if not found
-
 
1352
     *
1438
     * @return mixed the config value, or NULL if not found
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;
-
 
1445
        }
1359
        }
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])) {
Line 1366... Line 1453...
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
    }
-
 
Line -... Line 1479...
-
 
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
Line -... Line 1483...
-
 
1483
        }
1394
 
1484
 
1395
 
-
 
Line 1396... Line 1485...
1396
    // }}}
1485
        return $this->getDefaultChannel($layer);
1397
    // {{{ set(key, value, [layer])
1486
    }
1398
 
1487
 
1399
    /**
1488
    /**
Line 1411... Line 1500...
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;
Line 1459... Line 1555...
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
    }
Line 1511... Line -...
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;
-
 
1620
        }
1517
        }
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;
-
 
1626
            }
1522
            }
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;
-
 
1633
                }
1528
                }
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')) {
-
 
1637
                        $this->_registry[$layer] = new PEAR_Registry(
-
 
1638
                            $phpdir, false, false,
1531
                        $this->_registry[$layer] = &new PEAR_Registry($phpdir);
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
                    }
-
 
1646
                }
1538
                }
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
    }
-
 
1545
    // {{{ setChannels()
1653
    }
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()}
Line 1555... Line 1663...
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
    }
Line 1582... Line -...
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
Line 1600... Line 1709...
1600
            return $this->configuration_info[$key]['type'];
1709
            return $this->configuration_info[$key]['type'];
1601
        }
1710
        }
1602
        return false;
1711
        return false;
1603
    }
1712
    }
Line 1604... Line -...
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
-
 
1612
     *
1717
     * @param string  config key
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'];
-
 
1727
        }
1622
        }
1728
 
1623
        return false;
1729
        return false;
1624
    }
-
 
1625
       // }}}
-
 
Line 1626... Line 1730...
1626
    // {{{ getPrompt(key)
1730
    }
1627
 
1731
 
1628
    /**
1732
    /**
1629
     * Get the short documentation for a config value.
1733
     * Get the short documentation for a config value.
1630
     *
-
 
1631
     * @param string  config key
1734
     *
1632
     *
1735
     * @param string  config key
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])) {
-
 
1744
            return $this->configuration_info[$key]['prompt'];
1641
            return $this->configuration_info[$key]['prompt'];
1745
        }
1642
        }
1746
 
1643
        return false;
-
 
1644
    }
-
 
Line 1645... Line 1747...
1645
    // }}}
1747
        return false;
1646
    // {{{ getGroup(key)
1748
    }
1647
 
1749
 
1648
    /**
1750
    /**
1649
     * Get the parameter group for a config key.
-
 
1650
     *
1751
     * Get the parameter group for a config key.
1651
     * @param string  config key
1752
     *
1652
     *
1753
     * @param string  config key
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
    {
-
 
1761
        if (isset($this->configuration_info[$key])) {
1660
        if (isset($this->configuration_info[$key])) {
1762
            return $this->configuration_info[$key]['group'];
1661
            return $this->configuration_info[$key]['group'];
1763
        }
Line 1662... Line -...
1662
        }
-
 
1663
        return false;
-
 
1664
    }
-
 
1665
 
1764
 
1666
    // }}}
1765
        return false;
1667
    // {{{ getGroups()
1766
    }
1668
 
1767
 
1669
    /**
1768
    /**
Line 1678... Line 1777...
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
    }
Line 1685... Line -...
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
-
 
1693
     *
1789
     * @param string $group parameter group
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
     *
Line 1702... Line 1798...
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
    }
Line 1709... Line -...
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
-
 
1718
     *
1811
     * @param string  config key
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
Line 1731... Line 1824...
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
    }
Line 1740... Line -...
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
Line 1756... Line 1848...
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
    }
Line 1766... Line -...
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
-
 
1774
     *
1864
     * @param string config key
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)
-
 
1872
    {
1782
    {
1873
        if ($channel === null) {
-
 
1874
            $channel = $this->getDefaultChannel();
-
 
1875
        }
1783
        $channel = $this->getDefaultChannel();
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
            }
-
 
1882
        }
1789
        }
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;
-
 
1887
        }
1793
        }
1888
 
1794
        return false;
1889
        return false;
Line 1795... Line -...
1795
    }
-
 
1796
 
-
 
1797
    // }}}
-
 
1798
    // {{{ removeLayer(layer)
1890
    }
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
     *
-
 
1803
     * @param string config key
1894
     *
1804
     *
-
 
1805
     * @param string (optional) config layer
1895
     * @param string config key
1806
     *
1896
     * @param string (optional) config layer
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();
-
 
1905
            return true;
1815
            return true;
1906
        }
1816
        }
1907
 
Line 1817... Line -...
1817
        return false;
-
 
1818
    }
-
 
1819
 
-
 
1820
    // }}}
1908
        return false;
1821
    // {{{ store([layer])
1909
    }
1822
 
1910
 
1823
    /**
1911
    /**
1824
     * Stores configuration data in a layer.
-
 
1825
     *
1912
     * Stores configuration data in a layer.
1826
     * @param string config layer to store
1913
     *
1827
     *
1914
     * @param string config layer to store
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)
Line 1833... Line -...
1833
    {
-
 
1834
        return $this->writeConfigFile(null, $layer, $data);
-
 
1835
    }
-
 
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
 
1920
    {
1856
    // }}}
1921
        return $this->writeConfigFile(null, $layer, $data);
1857
    // {{{ definedBy(key)
1922
    }
1858
 
1923
 
1859
    /**
1924
    /**
Line 1879... Line 1944...
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
    }
-
 
Line 1893... Line -...
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 '';
Line 1912... Line -...
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
     *
-
 
1920
     * @param string config key
1963
     *
1921
     *
1964
     * @param string config key
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
Line 1928... Line 1971...
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
    }
Line 1935... Line -...
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
-
 
1943
     *
1983
     * @param string config layer
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]);
Line 1951... Line -...
1951
    }
-
 
1952
 
-
 
1953
    // }}}
-
 
1954
    // {{{ getLayers()
1991
    }
1955
 
1992
 
1956
    /**
1993
    /**
1957
     * Returns the layers defined (except the 'default' one)
1994
     * Returns the layers defined (except the 'default' one)
1958
     *
1995
     *
Line 1963... Line 2000...
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
    }
Line 1967... Line -...
1967
 
-
 
1968
    // }}}
-
 
1969
    // {{{ apiVersion()
2004
 
1970
    function apiVersion()
2005
    function apiVersion()
1971
    {
2006
    {
1972
        return '1.1';
2007
        return '1.1';
1973
    }
-
 
Line 1974... Line 2008...
1974
    // }}}
2008
    }
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
    {
-
 
1981
        if ($use === null) {
-
 
1982
            $layer = 'user';
-
 
1983
        } else {
-
 
1984
            $layer = $use;
2014
    {
1985
        }
2015
        $layer = $use === null ? 'user' : $use;
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;
-
 
1994
            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";
2023
            $a = false;
-
 
2024
            return $a;
-
 
2025
        }
-
 
2026
 
-
 
2027
        // only go here if null was passed in
1998
            exit(1);
2028
        echo "CRITICAL ERROR: Registry could not be initialized from any value";
-
 
2029
        exit(1);
1999
        }
2030
    }
2000
    }
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) {
-
 
2040
            return false;
2009
            return false;
2041
        }
2010
        }
2042
 
2011
        if (!in_array($layer, array('user', 'system'))) {
2043
        if (!in_array($layer, array('user', 'system'))) {
-
 
2044
            return false;
2012
            return false;
2045
        }
2013
        }
2046
 
2014
        $this->_registry[$layer] = &$reg;
2047
        $this->_registry[$layer] = &$reg;
2015
        if (is_object($reg)) {
2048
        if (is_object($reg)) {
-
 
2049
            $this->_registry[$layer]->setConfig($this, false);
2016
            $this->_registry[$layer]->setConfig($this);
2050
        }
2017
        }
2051
 
Line 2018... Line 2052...
2018
        return true;
2052
        return true;
2019
    }
2053
    }
2020
 
2054
 
2021
    function noRegistry()
2055
    function noRegistry()
Line 2022... Line 2056...
2022
    {
2056
    {
2023
        $this->_noRegistry = true;
-
 
2024
    }
-
 
2025
 
-
 
2026
    /**
-
 
2027
     * @return PEAR_Remote
-
 
2028
     */
-
 
2029
    function &getRemote()
-
 
2030
    {
-
 
2031
        $remote = &new PEAR_Remote($this);
-
 
2032
        return $remote;
2057
        $this->_noRegistry = true;
2033
    }
2058
    }
2034
 
2059
 
2035
    /**
2060
    /**
2036
     * @return PEAR_REST
2061
     * @return PEAR_REST
2037
     */
2062
     */
2038
    function &getREST($version, $options = array())
2063
    function &getREST($version, $options = array())
2039
    {
2064
    {
-
 
2065
        $version = str_replace('.', '', $version);
2040
        $version = str_replace('.', '', $version);
2066
        if (!class_exists($class = 'PEAR_REST_' . $version)) {
2041
        if (!class_exists($class = 'PEAR_REST_' . $version)) {
2067
            require_once 'PEAR/REST/' . $version . '.php';
2042
            require_once 'PEAR/REST/' . $version . '.php';
2068
        }
Line 2043... Line 2069...
2043
        }
2069
 
2044
        $remote = &new $class($this, $options);
2070
        $remote = new $class($this, $options);
Line 2052... Line 2078...
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
    }
-
 
Line -... Line 2084...
-
 
2084
 
2062
 
2085
        $a = false;
-
 
2086
        return $a;
Line 2063... Line 2087...
2063
    // {{{ _prependPath($path, $prepend)
2087
    }
2064
 
2088
 
2065
    function _prependPath($path, $prepend)
2089
    function _prependPath($path, $prepend)
2066
    {
2090
    {
Line 2076... Line 2100...
2076
                $path = $prepend . $path;
2100
                $path = $prepend . $path;
2077
            }
2101
            }
2078
        }
2102
        }
2079
        return $path;
2103
        return $path;
2080
    }
2104
    }
2081
    // }}}
-
 
Line 2082... Line 2105...
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
Line 2095... Line 2118...
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
?>
-