Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Config.php
Go to the documentation of this file.
1<?php
16
20require_once 'PEAR.php';
21require_once 'PEAR/Registry.php';
22require_once 'PEAR/Installer/Role.php';
23require_once 'System.php';
24
29$GLOBALS['_PEAR_Config_instance'] = null;
30if (!defined('PEAR_INSTALL_DIR') || !PEAR_INSTALL_DIR) {
31 $PEAR_INSTALL_DIR = PHP_LIBDIR . DIRECTORY_SEPARATOR . 'pear';
32} else {
33 $PEAR_INSTALL_DIR = PEAR_INSTALL_DIR;
34}
35
36// Below we define constants with default values for all configuration
37// parameters except username/password. All of them can have their
38// defaults set through environment variables. The reason we use the
39// PHP_ prefix is for some security, PHP protects environment
40// variables starting with PHP_*.
41
42// default channel and preferred mirror is based on whether we are invoked through
43// the "pear" or the "pecl" command
44if (!defined('PEAR_RUNTYPE')) {
45 define('PEAR_RUNTYPE', 'pear');
46}
47
48if (PEAR_RUNTYPE == 'pear') {
49 define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pear.php.net');
50} else {
51 define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pecl.php.net');
52}
53
54if (getenv('PHP_PEAR_SYSCONF_DIR')) {
55 define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
56} elseif (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'pearsys.ini')) {
57 // portable fallback: keep configuration next to the bundled trees instead of
58 // writing into %SystemRoot% when no sysconf dir is provided by the launcher
59 define('PEAR_CONFIG_SYSCONFDIR', dirname(__DIR__, 2));
60} elseif (getenv('SystemRoot')) {
61 define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
62} else {
63 define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
64}
65
66// Default for master_server
67if (getenv('PHP_PEAR_MASTER_SERVER')) {
68 define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', getenv('PHP_PEAR_MASTER_SERVER'));
69} else {
70 define('PEAR_CONFIG_DEFAULT_MASTER_SERVER', 'pear.php.net');
71}
72
73// Default for http_proxy
74if (getenv('PHP_PEAR_HTTP_PROXY')) {
75 define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('PHP_PEAR_HTTP_PROXY'));
76} elseif (getenv('http_proxy')) {
77 define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', getenv('http_proxy'));
78} else {
79 define('PEAR_CONFIG_DEFAULT_HTTP_PROXY', '');
80}
81
82// The bundled PEAR base lives next to this file, so the directory defaults can
83// be derived from the runtime location instead of the machine where this bundle
84// was assembled (the build machine's compile-time paths are meaningless here).
85$bearsamppPearBase = dirname(__DIR__, 2);
86
87// Default for php_dir
88if (getenv('PHP_PEAR_INSTALL_DIR')) {
89 define('PEAR_CONFIG_DEFAULT_PHP_DIR', getenv('PHP_PEAR_INSTALL_DIR'));
90} else {
91 define('PEAR_CONFIG_DEFAULT_PHP_DIR',
92 $bearsamppPearBase.DIRECTORY_SEPARATOR.'pear');
93}
94
95// Default for metadata_dir
96if (getenv('PHP_PEAR_METADATA_DIR')) {
97 define('PEAR_CONFIG_DEFAULT_METADATA_DIR', getenv('PHP_PEAR_METADATA_DIR'));
98} else {
99 define('PEAR_CONFIG_DEFAULT_METADATA_DIR', '');
100}
101
102// Default for ext_dir
103if (getenv('PHP_PEAR_EXTENSION_DIR')) {
104 define('PEAR_CONFIG_DEFAULT_EXT_DIR', getenv('PHP_PEAR_EXTENSION_DIR'));
105} else {
106 if (ini_get('extension_dir')) {
107 define('PEAR_CONFIG_DEFAULT_EXT_DIR', ini_get('extension_dir'));
108 } elseif (defined('PEAR_EXTENSION_DIR') &&
109 file_exists(PEAR_EXTENSION_DIR) && is_dir(PEAR_EXTENSION_DIR)) {
110 define('PEAR_CONFIG_DEFAULT_EXT_DIR', PEAR_EXTENSION_DIR);
111 } elseif (defined('PHP_EXTENSION_DIR')) {
112 define('PEAR_CONFIG_DEFAULT_EXT_DIR', PHP_EXTENSION_DIR);
113 } else {
114 define('PEAR_CONFIG_DEFAULT_EXT_DIR', '.');
115 }
116}
117
118// Default for doc_dir
119if (getenv('PHP_PEAR_DOC_DIR')) {
120 define('PEAR_CONFIG_DEFAULT_DOC_DIR', getenv('PHP_PEAR_DOC_DIR'));
121} else {
122 define('PEAR_CONFIG_DEFAULT_DOC_DIR',
123 $bearsamppPearBase.DIRECTORY_SEPARATOR.'docs');
124}
125
126// Default for bin_dir
127if (getenv('PHP_PEAR_BIN_DIR')) {
128 define('PEAR_CONFIG_DEFAULT_BIN_DIR', getenv('PHP_PEAR_BIN_DIR'));
129} else {
130 define('PEAR_CONFIG_DEFAULT_BIN_DIR', $bearsamppPearBase);
131}
132
133// Default for data_dir
134if (getenv('PHP_PEAR_DATA_DIR')) {
135 define('PEAR_CONFIG_DEFAULT_DATA_DIR', getenv('PHP_PEAR_DATA_DIR'));
136} else {
137 define('PEAR_CONFIG_DEFAULT_DATA_DIR',
138 $bearsamppPearBase.DIRECTORY_SEPARATOR.'data');
139}
140
141// Default for cfg_dir
142if (getenv('PHP_PEAR_CFG_DIR')) {
143 define('PEAR_CONFIG_DEFAULT_CFG_DIR', getenv('PHP_PEAR_CFG_DIR'));
144} else {
145 define('PEAR_CONFIG_DEFAULT_CFG_DIR',
146 $bearsamppPearBase.DIRECTORY_SEPARATOR.'cfg');
147}
148
149// Default for www_dir
150if (getenv('PHP_PEAR_WWW_DIR')) {
151 define('PEAR_CONFIG_DEFAULT_WWW_DIR', getenv('PHP_PEAR_WWW_DIR'));
152} else {
153 define('PEAR_CONFIG_DEFAULT_WWW_DIR',
154 $bearsamppPearBase.DIRECTORY_SEPARATOR.'www');
155}
156
157// Default for man_dir
158if (getenv('PHP_PEAR_MAN_DIR')) {
159 define('PEAR_CONFIG_DEFAULT_MAN_DIR', getenv('PHP_PEAR_MAN_DIR'));
160} else {
161 define('PEAR_CONFIG_DEFAULT_MAN_DIR',
162 $bearsamppPearBase.DIRECTORY_SEPARATOR.'docs'.
163 DIRECTORY_SEPARATOR.'man');
164}
165
166// Default for test_dir
167if (getenv('PHP_PEAR_TEST_DIR')) {
168 define('PEAR_CONFIG_DEFAULT_TEST_DIR', getenv('PHP_PEAR_TEST_DIR'));
169} else {
170 define('PEAR_CONFIG_DEFAULT_TEST_DIR',
171 $bearsamppPearBase.DIRECTORY_SEPARATOR.'tests');
172}
173
174// Default for temp_dir
175if (getenv('PHP_PEAR_TEMP_DIR')) {
176 define('PEAR_CONFIG_DEFAULT_TEMP_DIR', getenv('PHP_PEAR_TEMP_DIR'));
177} else {
178 define('PEAR_CONFIG_DEFAULT_TEMP_DIR',
179 System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
180 DIRECTORY_SEPARATOR . 'temp');
181}
182
183// Default for cache_dir
184if (getenv('PHP_PEAR_CACHE_DIR')) {
185 define('PEAR_CONFIG_DEFAULT_CACHE_DIR', getenv('PHP_PEAR_CACHE_DIR'));
186} else {
187 define('PEAR_CONFIG_DEFAULT_CACHE_DIR',
188 System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
189 DIRECTORY_SEPARATOR . 'cache');
190}
191
192// Default for download_dir
193if (getenv('PHP_PEAR_DOWNLOAD_DIR')) {
194 define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR', getenv('PHP_PEAR_DOWNLOAD_DIR'));
195} else {
196 define('PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR',
197 System::tmpdir() . DIRECTORY_SEPARATOR . 'pear' .
198 DIRECTORY_SEPARATOR . 'download');
199}
200
201// Default for php_bin
202if (getenv('PHP_PEAR_PHP_BIN')) {
203 define('PEAR_CONFIG_DEFAULT_PHP_BIN', getenv('PHP_PEAR_PHP_BIN'));
204} else {
205 define('PEAR_CONFIG_DEFAULT_PHP_BIN',
206 dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'php'.
207 (OS_WINDOWS ? '.exe' : ''));
208}
209
210// Default for verbose
211if (getenv('PHP_PEAR_VERBOSE')) {
212 define('PEAR_CONFIG_DEFAULT_VERBOSE', getenv('PHP_PEAR_VERBOSE'));
213} else {
214 define('PEAR_CONFIG_DEFAULT_VERBOSE', 1);
215}
216
217// Default for preferred_state
218if (getenv('PHP_PEAR_PREFERRED_STATE')) {
219 define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', getenv('PHP_PEAR_PREFERRED_STATE'));
220} else {
221 define('PEAR_CONFIG_DEFAULT_PREFERRED_STATE', 'stable');
222}
223
224// Default for umask
225if (getenv('PHP_PEAR_UMASK')) {
226 define('PEAR_CONFIG_DEFAULT_UMASK', getenv('PHP_PEAR_UMASK'));
227} else {
228 define('PEAR_CONFIG_DEFAULT_UMASK', decoct(umask()));
229}
230
231// Default for cache_ttl
232if (getenv('PHP_PEAR_CACHE_TTL')) {
233 define('PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv('PHP_PEAR_CACHE_TTL'));
234} else {
235 define('PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600);
236}
237
238// Default for sig_type
239if (getenv('PHP_PEAR_SIG_TYPE')) {
240 define('PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv('PHP_PEAR_SIG_TYPE'));
241} else {
242 define('PEAR_CONFIG_DEFAULT_SIG_TYPE', 'gpg');
243}
244
245// Default for sig_bin
246if (getenv('PHP_PEAR_SIG_BIN')) {
247 define('PEAR_CONFIG_DEFAULT_SIG_BIN', getenv('PHP_PEAR_SIG_BIN'));
248} else {
249 define('PEAR_CONFIG_DEFAULT_SIG_BIN',
250 System::which(
251 'gpg', OS_WINDOWS ? 'c:\gnupg\gpg.exe' : '/usr/local/bin/gpg'));
252}
253
254// Default for sig_keydir
255if (getenv('PHP_PEAR_SIG_KEYDIR')) {
256 define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv('PHP_PEAR_SIG_KEYDIR'));
257} else {
258 define('PEAR_CONFIG_DEFAULT_SIG_KEYDIR',
259 PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR . 'pearkeys');
260}
261
275class PEAR_Config extends PEAR
276{
282 var $files = array(
283 'system' => '',
284 'user' => '',
285 );
286
287 var $layers = array();
288
301 var $configuration = array(
302 'user' => array(),
303 'system' => array(),
304 'default' => array(),
305 );
306
314 var $_channelConfigInfo = array(
315 'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'cfg_dir',
316 'test_dir', 'www_dir', 'php_bin', 'php_prefix', 'php_suffix', 'username',
317 'password', 'verbose', 'preferred_state', 'umask', 'preferred_mirror', 'php_ini'
318 );
319
326 var $_channels = array('pear.php.net', 'pecl.php.net', '__uri');
327
334 var $_installRoot = false;
335
341 var $_registry = array();
342
347 var $_regInitialized = array();
348
353 var $_noRegistry = false;
354
360 var $_errorsFound = 0;
361 var $_lastError = null;
362
370 var $configuration_info = array(
371 // Channels/Internet Access
372 'default_channel' => array(
373 'type' => 'string',
374 'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
375 'doc' => 'the default channel to use for all non explicit commands',
376 'prompt' => 'Default Channel',
377 'group' => 'Internet Access',
378 ),
379 'preferred_mirror' => array(
380 'type' => 'string',
381 'default' => PEAR_CONFIG_DEFAULT_CHANNEL,
382 'doc' => 'the default server or mirror to use for channel actions',
383 'prompt' => 'Default Channel Mirror',
384 'group' => 'Internet Access',
385 ),
386 'remote_config' => array(
387 'type' => 'password',
388 'default' => '',
389 'doc' => 'ftp url of remote configuration file to use for synchronized install',
390 'prompt' => 'Remote Configuration File',
391 'group' => 'Internet Access',
392 ),
393 'auto_discover' => array(
394 'type' => 'integer',
395 'default' => 0,
396 'doc' => 'whether to automatically discover new channels',
397 'prompt' => 'Auto-discover new Channels',
398 'group' => 'Internet Access',
399 ),
400 // Internet Access
401 'master_server' => array(
402 'type' => 'string',
403 'default' => 'pear.php.net',
404 'doc' => 'name of the main PEAR server [NOT USED IN THIS VERSION]',
405 'prompt' => 'PEAR server [DEPRECATED]',
406 'group' => 'Internet Access',
407 ),
408 'http_proxy' => array(
409 'type' => 'string',
410 'default' => PEAR_CONFIG_DEFAULT_HTTP_PROXY,
411 'doc' => 'HTTP proxy (host:port) to use when downloading packages',
412 'prompt' => 'HTTP Proxy Server Address',
413 'group' => 'Internet Access',
414 ),
415 // File Locations
416 'php_dir' => array(
417 'type' => 'directory',
418 'default' => PEAR_CONFIG_DEFAULT_PHP_DIR,
419 'doc' => 'directory where .php files are installed',
420 'prompt' => 'PEAR directory',
421 'group' => 'File Locations',
422 ),
423 'ext_dir' => array(
424 'type' => 'directory',
425 'default' => PEAR_CONFIG_DEFAULT_EXT_DIR,
426 'doc' => 'directory where loadable extensions are installed',
427 'prompt' => 'PHP extension directory',
428 'group' => 'File Locations',
429 ),
430 'doc_dir' => array(
431 'type' => 'directory',
432 'default' => PEAR_CONFIG_DEFAULT_DOC_DIR,
433 'doc' => 'directory where documentation is installed',
434 'prompt' => 'PEAR documentation directory',
435 'group' => 'File Locations',
436 ),
437 'bin_dir' => array(
438 'type' => 'directory',
439 'default' => PEAR_CONFIG_DEFAULT_BIN_DIR,
440 'doc' => 'directory where executables are installed',
441 'prompt' => 'PEAR executables directory',
442 'group' => 'File Locations',
443 ),
444 'data_dir' => array(
445 'type' => 'directory',
446 'default' => PEAR_CONFIG_DEFAULT_DATA_DIR,
447 'doc' => 'directory where data files are installed',
448 'prompt' => 'PEAR data directory',
449 'group' => 'File Locations (Advanced)',
450 ),
451 'cfg_dir' => array(
452 'type' => 'directory',
453 'default' => PEAR_CONFIG_DEFAULT_CFG_DIR,
454 'doc' => 'directory where modifiable configuration files are installed',
455 'prompt' => 'PEAR configuration file directory',
456 'group' => 'File Locations (Advanced)',
457 ),
458 'www_dir' => array(
459 'type' => 'directory',
460 'default' => PEAR_CONFIG_DEFAULT_WWW_DIR,
461 'doc' => 'directory where www frontend files (html/js) are installed',
462 'prompt' => 'PEAR www files directory',
463 'group' => 'File Locations (Advanced)',
464 ),
465 'man_dir' => array(
466 'type' => 'directory',
467 'default' => PEAR_CONFIG_DEFAULT_MAN_DIR,
468 'doc' => 'directory where unix manual pages are installed',
469 'prompt' => 'Systems manpage files directory',
470 'group' => 'File Locations (Advanced)',
471 ),
472 'test_dir' => array(
473 'type' => 'directory',
474 'default' => PEAR_CONFIG_DEFAULT_TEST_DIR,
475 'doc' => 'directory where regression tests are installed',
476 'prompt' => 'PEAR test directory',
477 'group' => 'File Locations (Advanced)',
478 ),
479 'cache_dir' => array(
480 'type' => 'directory',
481 'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
482 'doc' => 'directory which is used for web service cache',
483 'prompt' => 'PEAR Installer cache directory',
484 'group' => 'File Locations (Advanced)',
485 ),
486 'temp_dir' => array(
487 'type' => 'directory',
488 'default' => PEAR_CONFIG_DEFAULT_TEMP_DIR,
489 'doc' => 'directory which is used for all temp files',
490 'prompt' => 'PEAR Installer temp directory',
491 'group' => 'File Locations (Advanced)',
492 ),
493 'download_dir' => array(
494 'type' => 'directory',
495 'default' => PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR,
496 'doc' => 'directory which is used for all downloaded files',
497 'prompt' => 'PEAR Installer download directory',
498 'group' => 'File Locations (Advanced)',
499 ),
500 'php_bin' => array(
501 'type' => 'file',
502 'default' => PEAR_CONFIG_DEFAULT_PHP_BIN,
503 'doc' => 'PHP CLI/CGI binary for executing scripts',
504 'prompt' => 'PHP CLI/CGI binary',
505 'group' => 'File Locations (Advanced)',
506 ),
507 'php_prefix' => array(
508 'type' => 'string',
509 'default' => '',
510 'doc' => '--program-prefix for php_bin\'s ./configure, used for pecl installs',
511 'prompt' => '--program-prefix passed to PHP\'s ./configure',
512 'group' => 'File Locations (Advanced)',
513 ),
514 'php_suffix' => array(
515 'type' => 'string',
516 'default' => '',
517 'doc' => '--program-suffix for php_bin\'s ./configure, used for pecl installs',
518 'prompt' => '--program-suffix passed to PHP\'s ./configure',
519 'group' => 'File Locations (Advanced)',
520 ),
521 'php_ini' => array(
522 'type' => 'file',
523 'default' => '',
524 'doc' => 'location of php.ini in which to enable PECL extensions on install',
525 'prompt' => 'php.ini location',
526 'group' => 'File Locations (Advanced)',
527 ),
528 'metadata_dir' => array(
529 'type' => 'directory',
530 'default' => PEAR_CONFIG_DEFAULT_METADATA_DIR,
531 'doc' => 'directory where metadata files are installed (registry, filemap, channels, ...)',
532 'prompt' => 'PEAR metadata directory',
533 'group' => 'File Locations (Advanced)',
534 ),
535 // Maintainers
536 'username' => array(
537 'type' => 'string',
538 'default' => '',
539 'doc' => '(maintainers) your PEAR account name',
540 'prompt' => 'PEAR username (for maintainers)',
541 'group' => 'Maintainers',
542 ),
543 'password' => array(
544 'type' => 'password',
545 'default' => '',
546 'doc' => '(maintainers) your PEAR account password',
547 'prompt' => 'PEAR password (for maintainers)',
548 'group' => 'Maintainers',
549 ),
550 // Advanced
551 'verbose' => array(
552 'type' => 'integer',
553 'default' => PEAR_CONFIG_DEFAULT_VERBOSE,
554 'doc' => 'verbosity level
5550: really quiet
5561: somewhat quiet
5572: verbose
5583: debug',
559 'prompt' => 'Debug Log Level',
560 'group' => 'Advanced',
561 ),
562 'preferred_state' => array(
563 'type' => 'set',
564 'default' => PEAR_CONFIG_DEFAULT_PREFERRED_STATE,
565 'doc' => 'the installer will prefer releases with this state when installing packages without a version or state specified',
566 'valid_set' => array(
567 'stable', 'beta', 'alpha', 'devel', 'snapshot'),
568 'prompt' => 'Preferred Package State',
569 'group' => 'Advanced',
570 ),
571 'umask' => array(
572 'type' => 'mask',
573 'default' => PEAR_CONFIG_DEFAULT_UMASK,
574 'doc' => 'umask used when creating files (Unix-like systems only)',
575 'prompt' => 'Unix file mask',
576 'group' => 'Advanced',
577 ),
578 'cache_ttl' => array(
579 'type' => 'integer',
580 'default' => PEAR_CONFIG_DEFAULT_CACHE_TTL,
581 'doc' => 'amount of secs where the local cache is used and not updated',
582 'prompt' => 'Cache TimeToLive',
583 'group' => 'Advanced',
584 ),
585 'sig_type' => array(
586 'type' => 'set',
587 'default' => PEAR_CONFIG_DEFAULT_SIG_TYPE,
588 'doc' => 'which package signature mechanism to use',
589 'valid_set' => array('gpg'),
590 'prompt' => 'Package Signature Type',
591 'group' => 'Maintainers',
592 ),
593 'sig_bin' => array(
594 'type' => 'string',
595 'default' => PEAR_CONFIG_DEFAULT_SIG_BIN,
596 'doc' => 'which package signature mechanism to use',
597 'prompt' => 'Signature Handling Program',
598 'group' => 'Maintainers',
599 ),
600 'sig_keyid' => array(
601 'type' => 'string',
602 'default' => '',
603 'doc' => 'which key to use for signing with',
604 'prompt' => 'Signature Key Id',
605 'group' => 'Maintainers',
606 ),
607 'sig_keydir' => array(
608 'type' => 'directory',
609 'default' => PEAR_CONFIG_DEFAULT_SIG_KEYDIR,
610 'doc' => 'directory where signature keys are located',
611 'prompt' => 'Signature Key Directory',
612 'group' => 'Maintainers',
613 ),
614 // __channels is reserved - used for channel-specific configuration
615 );
616
631 function __construct($user_file = '', $system_file = '', $ftp_file = false,
632 $strict = true)
633 {
634 parent::__construct();
636 $sl = DIRECTORY_SEPARATOR;
637 if (empty($user_file)) {
638 if (OS_WINDOWS) {
639 $user_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini';
640 } else {
641 $user_file = getenv('HOME') . $sl . '.pearrc';
642 }
643 }
644
645 if (empty($system_file)) {
646 $system_file = PEAR_CONFIG_SYSCONFDIR . $sl;
647 if (OS_WINDOWS) {
648 $system_file .= 'pearsys.ini';
649 } else {
650 $system_file .= 'pear.conf';
651 }
652 }
653
654 $this->layers = array_keys($this->configuration);
655 $this->files['user'] = $user_file;
656 $this->files['system'] = $system_file;
657 if ($user_file && file_exists($user_file)) {
658 $this->pushErrorHandling(PEAR_ERROR_RETURN);
659 $this->readConfigFile($user_file, 'user', $strict);
660 $this->popErrorHandling();
661 if ($this->_errorsFound > 0) {
662 return;
663 }
664 }
665
666 if ($system_file && @file_exists($system_file)) {
667 $this->mergeConfigFile($system_file, false, 'system', $strict);
668 if ($this->_errorsFound > 0) {
669 return;
670 }
671
672 }
673
674 if (!$ftp_file) {
675 $ftp_file = $this->get('remote_config');
676 }
677
678 if ($ftp_file && defined('PEAR_REMOTEINSTALL_OK')) {
679 $this->readFTPConfigFile($ftp_file);
680 }
681
682 foreach ($this->configuration_info as $key => $info) {
683 $this->configuration['default'][$key] = $info['default'];
684 }
685
686 $this->_registry['default'] = new PEAR_Registry(
687 $this->configuration['default']['php_dir'], false, false,
688 $this->configuration['default']['metadata_dir']);
689 $this->_registry['default']->setConfig($this, false);
690 $this->_regInitialized['default'] = false;
691 //$GLOBALS['_PEAR_Config_instance'] = &$this;
692 }
693
697 public static function getDefaultConfigFiles()
698 {
699 $sl = DIRECTORY_SEPARATOR;
700 if (OS_WINDOWS) {
701 return array(
702 'user' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini',
703 'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini'
704 );
705 }
706
707 return array(
708 'user' => getenv('HOME') . $sl . '.pearrc',
709 'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf'
710 );
711 }
712
726 public static function &singleton($user_file = '', $system_file = '', $strict = true)
727 {
728 if (is_object($GLOBALS['_PEAR_Config_instance'])) {
729 return $GLOBALS['_PEAR_Config_instance'];
730 }
731
732 $t_conf = new PEAR_Config($user_file, $system_file, false, $strict);
733 if ($t_conf->_errorsFound > 0) {
734 return $t_conf->_lastError;
735 }
736
737 $GLOBALS['_PEAR_Config_instance'] = &$t_conf;
738 return $GLOBALS['_PEAR_Config_instance'];
739 }
740
747 function validConfiguration()
748 {
749 if ($this->isDefinedLayer('user') || $this->isDefinedLayer('system')) {
750 return true;
751 }
752
753 return false;
754 }
755
765 function readConfigFile($file = null, $layer = 'user', $strict = true)
766 {
767 if (empty($this->files[$layer])) {
768 return $this->raiseError("unknown config layer `$layer'");
769 }
770
771 if ($file === null) {
772 $file = $this->files[$layer];
773 }
774
775 $data = $this->_readConfigDataFrom($file);
776 if (PEAR::isError($data)) {
777 if (!$strict) {
778 return true;
779 }
780
781 $this->_errorsFound++;
782 $this->_lastError = $data;
783
784 return $data;
785 }
786
787 $this->files[$layer] = $file;
788 $this->_decodeInput($data);
789 $this->configuration[$layer] = $data;
790 $this->_setupChannels();
791 if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
792 $this->_registry[$layer] = new PEAR_Registry(
793 $phpdir, false, false,
794 $this->get('metadata_dir', $layer, 'pear.php.net'));
795 $this->_registry[$layer]->setConfig($this, false);
796 $this->_regInitialized[$layer] = false;
797 } else {
798 unset($this->_registry[$layer]);
799 }
800 return true;
801 }
802
807 function readFTPConfigFile($path)
808 {
809 do { // poor man's try
810 if (!class_exists('PEAR_FTP')) {
811 if (!class_exists('PEAR_Common')) {
812 require_once 'PEAR/Common.php';
813 }
814 if (PEAR_Common::isIncludeable('PEAR/FTP.php')) {
815 require_once 'PEAR/FTP.php';
816 }
817 }
818
819 if (!class_exists('PEAR_FTP')) {
820 return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config');
821 }
822
823 $this->_ftp = new PEAR_FTP;
824 $this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN);
825 $e = $this->_ftp->init($path);
826 if (PEAR::isError($e)) {
827 $this->_ftp->popErrorHandling();
828 return $e;
829 }
830
831 $tmp = System::mktemp('-d');
833 $e = $this->_ftp->get(basename($path), $tmp . DIRECTORY_SEPARATOR .
834 'pear.ini', false, FTP_BINARY);
835 if (PEAR::isError($e)) {
836 $this->_ftp->popErrorHandling();
837 return $e;
838 }
839
840 PEAR_Common::addTempFile($tmp . DIRECTORY_SEPARATOR . 'pear.ini');
841 $this->_ftp->disconnect();
842 $this->_ftp->popErrorHandling();
843 $this->files['ftp'] = $tmp . DIRECTORY_SEPARATOR . 'pear.ini';
844 $e = $this->readConfigFile(null, 'ftp');
845 if (PEAR::isError($e)) {
846 return $e;
847 }
848
849 $fail = array();
850 foreach ($this->configuration_info as $key => $val) {
851 if (in_array($this->getGroup($key),
852 array('File Locations', 'File Locations (Advanced)')) &&
853 $this->getType($key) == 'directory') {
854 // any directory configs must be set for this to work
855 if (!isset($this->configuration['ftp'][$key])) {
856 $fail[] = $key;
857 }
858 }
859 }
860
861 if (!count($fail)) {
862 return true;
863 }
864
865 $fail = '"' . implode('", "', $fail) . '"';
866 unset($this->files['ftp']);
867 unset($this->configuration['ftp']);
868 return PEAR::raiseError('ERROR: Ftp configuration file must set all ' .
869 'directory configuration variables. These variables were not set: ' .
870 $fail);
871 } while (false); // poor man's catch
872 unset($this->files['ftp']);
873 return PEAR::raiseError('no remote host specified');
874 }
875
879 function _setupChannels()
880 {
881 $set = array_flip(array_values($this->_channels));
882 foreach ($this->configuration as $layer => $data) {
883 $i = 1000;
884 if (isset($data['__channels']) && is_array($data['__channels'])) {
885 foreach ($data['__channels'] as $channel => $info) {
886 $set[$channel] = $i++;
887 }
888 }
889 }
890 $this->_channels = array_values(array_flip($set));
891 $this->setChannels($this->_channels);
892 }
893
894 function deleteChannel($channel)
895 {
896 $ch = strtolower($channel);
897 foreach ($this->configuration as $layer => $data) {
898 if (isset($data['__channels']) && isset($data['__channels'][$ch])) {
899 unset($this->configuration[$layer]['__channels'][$ch]);
900 }
901 }
902
903 $this->_channels = array_flip($this->_channels);
904 unset($this->_channels[$ch]);
905 $this->_channels = array_flip($this->_channels);
906 }
907
918 function mergeConfigFile($file, $override = true, $layer = 'user', $strict = true)
919 {
920 if (empty($this->files[$layer])) {
921 return $this->raiseError("unknown config layer `$layer'");
922 }
923
924 if ($file === null) {
925 $file = $this->files[$layer];
926 }
927
928 $data = $this->_readConfigDataFrom($file);
929 if (PEAR::isError($data)) {
930 if (!$strict) {
931 return true;
932 }
933
934 $this->_errorsFound++;
935 $this->_lastError = $data;
936
937 return $data;
938 }
939
940 $this->_decodeInput($data);
941 if ($override) {
942 $this->configuration[$layer] =
943 PEAR_Config::arrayMergeRecursive($this->configuration[$layer], $data);
944 } else {
945 $this->configuration[$layer] =
946 PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]);
947 }
948
949 $this->_setupChannels();
950 if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
951 $this->_registry[$layer] = new PEAR_Registry(
952 $phpdir, false, false,
953 $this->get('metadata_dir', $layer, 'pear.php.net'));
954 $this->_registry[$layer]->setConfig($this, false);
955 $this->_regInitialized[$layer] = false;
956 } else {
957 unset($this->_registry[$layer]);
958 }
959 return true;
960 }
961
967 public static function arrayMergeRecursive($arr2, $arr1)
968 {
969 $ret = array();
970 foreach ($arr2 as $key => $data) {
971 if (!isset($arr1[$key])) {
972 $ret[$key] = $data;
973 unset($arr1[$key]);
974 continue;
975 }
976 if (is_array($data)) {
977 if (!is_array($arr1[$key])) {
978 $ret[$key] = $arr1[$key];
979 unset($arr1[$key]);
980 continue;
981 }
982 $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
983 unset($arr1[$key]);
984 }
985 }
986
987 return array_merge($ret, $arr1);
988 }
989
999 function writeConfigFile($file = null, $layer = 'user', $data = null)
1000 {
1001 $this->_lazyChannelSetup($layer);
1002 if ($layer == 'both' || $layer == 'all') {
1003 foreach ($this->files as $type => $file) {
1004 $err = $this->writeConfigFile($file, $type, $data);
1005 if (PEAR::isError($err)) {
1006 return $err;
1007 }
1008 }
1009 return true;
1010 }
1011
1012 if (empty($this->files[$layer])) {
1013 return $this->raiseError("unknown config file type `$layer'");
1014 }
1015
1016 if ($file === null) {
1017 $file = $this->files[$layer];
1018 }
1019
1020 $data = ($data === null) ? $this->configuration[$layer] : $data;
1021 $this->_encodeOutput($data);
1022 $opt = array('-p', dirname($file));
1023 if (!@System::mkDir($opt)) {
1024 return $this->raiseError("could not create directory: " . dirname($file));
1025 }
1026
1027 if (file_exists($file) && is_file($file) && !is_writeable($file)) {
1028 return $this->raiseError("no write access to $file!");
1029 }
1030
1031 $fp = @fopen($file, "w");
1032 if (!$fp) {
1033 return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)");
1034 }
1035
1036 $contents = "#PEAR_Config 0.9\n" . serialize($data);
1037 if (!@fwrite($fp, $contents)) {
1038 return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ($php_errormsg)");
1039 }
1040 return true;
1041 }
1042
1051 function _readConfigDataFrom($file)
1052 {
1053 $fp = false;
1054 if (file_exists($file)) {
1055 $fp = @fopen($file, "r");
1056 }
1057
1058 if (!$fp) {
1059 return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed");
1060 }
1061
1062 $size = filesize($file);
1063 fclose($fp);
1064 $contents = file_get_contents($file);
1065 if (empty($contents)) {
1066 return $this->raiseError('Configuration file "' . $file . '" is empty');
1067 }
1068
1069 $version = false;
1070 if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
1071 $version = $matches[1];
1072 $contents = substr($contents, strlen($matches[0]));
1073 } else {
1074 // Museum config file
1075 if (substr($contents,0,2) == 'a:') {
1076 $version = '0.1';
1077 }
1078 }
1079
1080 if ($version && version_compare("$version", '1', '<')) {
1081 $data = @unserialize($contents);
1082
1083 if (!is_array($data) && !$data) {
1084 if ($contents == serialize(false)) {
1085 $data = array();
1086 } else {
1087 $err = $this->raiseError("PEAR_Config: bad data in $file");
1088 return $err;
1089 }
1090 }
1091 if (!is_array($data)) {
1092 if (strlen(trim($contents)) > 0) {
1093 $error = "PEAR_Config: bad data in $file";
1094 $err = $this->raiseError($error);
1095 return $err;
1096 }
1097
1098 $data = array();
1099 }
1100 // add parsing of newer formats here...
1101 } else {
1102 $err = $this->raiseError("$file: unknown version `$version'");
1103 return $err;
1104 }
1105
1106 return $data;
1107 }
1108
1114 function getConfFile($layer)
1115 {
1116 return $this->files[$layer];
1117 }
1118
1125 function _addConfigVars($class, $vars)
1126 {
1127 static $called = array();
1128 if (isset($called[$class])) {
1129 return;
1130 }
1131
1132 $called[$class] = 1;
1133 if (count($vars) > 3) {
1134 return $this->raiseError('Roles can only define 3 new config variables or less');
1135 }
1136
1137 foreach ($vars as $name => $var) {
1138 if (!is_array($var)) {
1139 return $this->raiseError('Configuration information must be an array');
1140 }
1141
1142 if (!isset($var['type'])) {
1143 return $this->raiseError('Configuration information must contain a type');
1144 } elseif (!in_array($var['type'],
1145 array('string', 'mask', 'password', 'directory', 'file', 'set'))) {
1146 return $this->raiseError(
1147 'Configuration type must be one of directory, file, string, ' .
1148 'mask, set, or password');
1149 }
1150 if (!isset($var['default'])) {
1151 return $this->raiseError(
1152 'Configuration information must contain a default value ("default" index)');
1153 }
1154
1155 if (is_array($var['default'])) {
1156 $real_default = '';
1157 foreach ($var['default'] as $config_var => $val) {
1158 if (strpos($config_var, 'text') === 0) {
1159 $real_default .= $val;
1160 } elseif (strpos($config_var, 'constant') === 0) {
1161 if (!defined($val)) {
1162 return $this->raiseError(
1163 'Unknown constant "' . $val . '" requested in ' .
1164 'default value for configuration variable "' .
1165 $name . '"');
1166 }
1167
1168 $real_default .= constant($val);
1169 } elseif (isset($this->configuration_info[$config_var])) {
1170 $real_default .=
1171 $this->configuration_info[$config_var]['default'];
1172 } else {
1173 return $this->raiseError(
1174 'Unknown request for "' . $config_var . '" value in ' .
1175 'default value for configuration variable "' .
1176 $name . '"');
1177 }
1178 }
1179 $var['default'] = $real_default;
1180 }
1181
1182 if ($var['type'] == 'integer') {
1183 $var['default'] = (integer) $var['default'];
1184 }
1185
1186 if (!isset($var['doc'])) {
1187 return $this->raiseError(
1188 'Configuration information must contain a summary ("doc" index)');
1189 }
1190
1191 if (!isset($var['prompt'])) {
1192 return $this->raiseError(
1193 'Configuration information must contain a simple prompt ("prompt" index)');
1194 }
1195
1196 if (!isset($var['group'])) {
1197 return $this->raiseError(
1198 'Configuration information must contain a simple group ("group" index)');
1199 }
1200
1201 if (isset($this->configuration_info[$name])) {
1202 return $this->raiseError('Configuration variable "' . $name .
1203 '" already exists');
1204 }
1205
1206 $this->configuration_info[$name] = $var;
1207 // fix bug #7351: setting custom config variable in a channel fails
1208 $this->_channelConfigInfo[] = $name;
1209 }
1210
1211 return true;
1212 }
1213
1223 function _encodeOutput(&$data)
1224 {
1225 foreach ($data as $key => $value) {
1226 if ($key == '__channels') {
1227 foreach ($data['__channels'] as $channel => $blah) {
1228 $this->_encodeOutput($data['__channels'][$channel]);
1229 }
1230 }
1231
1232 if (!isset($this->configuration_info[$key])) {
1233 continue;
1234 }
1235
1236 $type = $this->configuration_info[$key]['type'];
1237 switch ($type) {
1238 // we base64-encode passwords so they are at least
1239 // not shown in plain by accident
1240 case 'password': {
1241 $data[$key] = base64_encode($data[$key]);
1242 break;
1243 }
1244 case 'mask': {
1245 $data[$key] = octdec($data[$key]);
1246 break;
1247 }
1248 }
1249 }
1250
1251 return true;
1252 }
1253
1263 function _decodeInput(&$data)
1264 {
1265 if (!is_array($data)) {
1266 return true;
1267 }
1268
1269 foreach ($data as $key => $value) {
1270 if ($key == '__channels') {
1271 foreach ($data['__channels'] as $channel => $blah) {
1272 $this->_decodeInput($data['__channels'][$channel]);
1273 }
1274 }
1275
1276 if (!isset($this->configuration_info[$key])) {
1277 continue;
1278 }
1279
1280 $type = $this->configuration_info[$key]['type'];
1281 switch ($type) {
1282 case 'password': {
1283 $data[$key] = base64_decode($data[$key]);
1284 break;
1285 }
1286 case 'mask': {
1287 $data[$key] = decoct($data[$key]);
1288 break;
1289 }
1290 }
1291 }
1292
1293 return true;
1294 }
1295
1304 function getDefaultChannel($layer = null)
1305 {
1306 $ret = false;
1307 if ($layer === null) {
1308 foreach ($this->layers as $layer) {
1309 if (isset($this->configuration[$layer]['default_channel'])) {
1310 $ret = $this->configuration[$layer]['default_channel'];
1311 break;
1312 }
1313 }
1314 } elseif (isset($this->configuration[$layer]['default_channel'])) {
1315 $ret = $this->configuration[$layer]['default_channel'];
1316 }
1317
1318 if ($ret == 'pear.php.net' && defined('PEAR_RUNTYPE') && PEAR_RUNTYPE == 'pecl') {
1319 $ret = 'pecl.php.net';
1320 }
1321
1322 if ($ret) {
1323 if ($ret != 'pear.php.net') {
1324 $this->_lazyChannelSetup();
1325 }
1326
1327 return $ret;
1328 }
1329
1330 return PEAR_CONFIG_DEFAULT_CHANNEL;
1331 }
1332
1341 function get($key, $layer = null, $channel = false)
1342 {
1343 if (!isset($this->configuration_info[$key])) {
1344 return null;
1345 }
1346
1347 if ($key == '__channels') {
1348 return null;
1349 }
1350
1351 if ($key == 'default_channel') {
1352 return $this->getDefaultChannel($layer);
1353 }
1354
1355 if (!$channel) {
1356 $channel = $this->getDefaultChannel();
1357 } elseif ($channel != 'pear.php.net') {
1358 $this->_lazyChannelSetup();
1359 }
1360 $channel = strtolower($channel);
1361
1362 $test = (in_array($key, $this->_channelConfigInfo)) ?
1363 $this->_getChannelValue($key, $layer, $channel) :
1364 null;
1365 if ($test !== null) {
1366 if ($this->_installRoot) {
1367 if (in_array($this->getGroup($key),
1368 array('File Locations', 'File Locations (Advanced)')) &&
1369 $this->getType($key) == 'directory') {
1370 return $this->_prependPath($test, $this->_installRoot);
1371 }
1372 }
1373 return $test;
1374 }
1375
1376 if ($layer === null) {
1377 foreach ($this->layers as $layer) {
1378 if (isset($this->configuration[$layer][$key])) {
1379 $test = $this->configuration[$layer][$key];
1380 if ($this->_installRoot) {
1381 if (in_array($this->getGroup($key),
1382 array('File Locations', 'File Locations (Advanced)')) &&
1383 $this->getType($key) == 'directory') {
1384 return $this->_prependPath($test, $this->_installRoot);
1385 }
1386 }
1387
1388 if ($key == 'preferred_mirror') {
1389 $reg = &$this->getRegistry();
1390 if (is_object($reg)) {
1391 $chan = $reg->getChannel($channel);
1392 if (PEAR::isError($chan)) {
1393 return $channel;
1394 }
1395
1396 if (!$chan->getMirror($test) && $chan->getName() != $test) {
1397 return $channel; // mirror does not exist
1398 }
1399 }
1400 }
1401 return $test;
1402 }
1403 }
1404 } elseif (isset($this->configuration[$layer][$key])) {
1405 $test = $this->configuration[$layer][$key];
1406 if ($this->_installRoot) {
1407 if (in_array($this->getGroup($key),
1408 array('File Locations', 'File Locations (Advanced)')) &&
1409 $this->getType($key) == 'directory') {
1410 return $this->_prependPath($test, $this->_installRoot);
1411 }
1412 }
1413
1414 if ($key == 'preferred_mirror') {
1415 $reg = &$this->getRegistry();
1416 if (is_object($reg)) {
1417 $chan = $reg->getChannel($channel);
1418 if (PEAR::isError($chan)) {
1419 return $channel;
1420 }
1421
1422 if (!$chan->getMirror($test) && $chan->getName() != $test) {
1423 return $channel; // mirror does not exist
1424 }
1425 }
1426 }
1427
1428 return $test;
1429 }
1430
1431 return null;
1432 }
1433
1442 function _getChannelValue($key, $layer, $channel)
1443 {
1444 if ($key == '__channels' || $channel == 'pear.php.net') {
1445 return null;
1446 }
1447
1448 $ret = null;
1449 if ($layer === null) {
1450 foreach ($this->layers as $ilayer) {
1451 if (isset($this->configuration[$ilayer]['__channels'][$channel][$key])) {
1452 $ret = $this->configuration[$ilayer]['__channels'][$channel][$key];
1453 break;
1454 }
1455 }
1456 } elseif (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1457 $ret = $this->configuration[$layer]['__channels'][$channel][$key];
1458 }
1459
1460 if ($key != 'preferred_mirror') {
1461 return $ret;
1462 }
1463
1464
1465 if ($ret !== null) {
1466 $reg = &$this->getRegistry($layer);
1467 if (is_object($reg)) {
1468 $chan = $reg->getChannel($channel);
1469 if (PEAR::isError($chan)) {
1470 return $channel;
1471 }
1472
1473 if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
1474 return $channel; // mirror does not exist
1475 }
1476 }
1477
1478 return $ret;
1479 }
1480
1481 if ($channel != $this->getDefaultChannel($layer)) {
1482 return $channel; // we must use the channel name as the preferred mirror
1483 // if the user has not chosen an alternate
1484 }
1485
1486 return $this->getDefaultChannel($layer);
1487 }
1488
1501 function set($key, $value, $layer = 'user', $channel = false)
1502 {
1503 if ($key == '__channels') {
1504 return false;
1505 }
1506
1507 if (!isset($this->configuration[$layer])) {
1508 return false;
1509 }
1510
1511 if ($key == 'default_channel') {
1512 // can only set this value globally
1513 $channel = 'pear.php.net';
1514 if ($value != 'pear.php.net') {
1515 $this->_lazyChannelSetup($layer);
1516 }
1517 }
1518
1519 if ($key == 'preferred_mirror') {
1520 if ($channel == '__uri') {
1521 return false; // can't set the __uri pseudo-channel's mirror
1522 }
1523
1524 $reg = &$this->getRegistry($layer);
1525 if (is_object($reg)) {
1526 $chan = $reg->getChannel($channel ? $channel : 'pear.php.net');
1527 if (PEAR::isError($chan)) {
1528 return false;
1529 }
1530
1531 if (!$chan->getMirror($value) && $chan->getName() != $value) {
1532 return false; // mirror does not exist
1533 }
1534 }
1535 }
1536
1537 if (!isset($this->configuration_info[$key])) {
1538 return false;
1539 }
1540
1541 extract($this->configuration_info[$key]);
1542 switch ($type) {
1543 case 'integer':
1544 $value = (int)$value;
1545 break;
1546 case 'set': {
1547 // If a valid_set is specified, require the value to
1548 // be in the set. If there is no valid_set, accept
1549 // any value.
1550 if ($valid_set) {
1551 reset($valid_set);
1552 if ((key($valid_set) === 0 && !in_array($value, $valid_set)) ||
1553 (key($valid_set) !== 0 && empty($valid_set[$value])))
1554 {
1555 return false;
1556 }
1557 }
1558 break;
1559 }
1560 }
1561
1562 if (!$channel) {
1563 $channel = $this->get('default_channel', null, 'pear.php.net');
1564 }
1565
1566 if (!in_array($channel, $this->_channels)) {
1567 $this->_lazyChannelSetup($layer);
1568 $reg = &$this->getRegistry($layer);
1569 if ($reg) {
1570 $channel = $reg->channelName($channel);
1571 }
1572
1573 if (!in_array($channel, $this->_channels)) {
1574 return false;
1575 }
1576 }
1577
1578 if ($channel != 'pear.php.net') {
1579 if (in_array($key, $this->_channelConfigInfo)) {
1580 $this->configuration[$layer]['__channels'][$channel][$key] = $value;
1581 return true;
1582 }
1583
1584 return false;
1585 }
1586
1587 if ($key == 'default_channel') {
1588 if (!isset($reg)) {
1589 $reg = &$this->getRegistry($layer);
1590 if (!$reg) {
1591 $reg = &$this->getRegistry();
1592 }
1593 }
1594
1595 if ($reg) {
1596 $value = $reg->channelName($value);
1597 }
1598
1599 if (!$value) {
1600 return false;
1601 }
1602 }
1603
1604 $this->configuration[$layer][$key] = $value;
1605 if ($key == 'php_dir' && !$this->_noRegistry) {
1606 if (!isset($this->_registry[$layer]) ||
1607 $value != $this->_registry[$layer]->install_dir) {
1608 $this->_registry[$layer] = new PEAR_Registry($value);
1609 $this->_regInitialized[$layer] = false;
1610 $this->_registry[$layer]->setConfig($this, false);
1611 }
1612 }
1613
1614 return true;
1615 }
1616
1617 function _lazyChannelSetup($uselayer = false)
1618 {
1619 if ($this->_noRegistry) {
1620 return;
1621 }
1622
1623 $merge = false;
1624 foreach ($this->_registry as $layer => $p) {
1625 if ($uselayer && $uselayer != $layer) {
1626 continue;
1627 }
1628
1629 if (!$this->_regInitialized[$layer]) {
1630 if ($layer == 'default' && isset($this->_registry['user']) ||
1631 isset($this->_registry['system'])) {
1632 // only use the default registry if there are no alternatives
1633 continue;
1634 }
1635
1636 if (!is_object($this->_registry[$layer])) {
1637 if ($phpdir = $this->get('php_dir', $layer, 'pear.php.net')) {
1638 $this->_registry[$layer] = new PEAR_Registry(
1639 $phpdir, false, false,
1640 $this->get('metadata_dir', $layer, 'pear.php.net'));
1641 $this->_registry[$layer]->setConfig($this, false);
1642 $this->_regInitialized[$layer] = false;
1643 } else {
1644 unset($this->_registry[$layer]);
1645 return;
1646 }
1647 }
1648
1649 $this->setChannels($this->_registry[$layer]->listChannels(), $merge);
1650 $this->_regInitialized[$layer] = true;
1651 $merge = true;
1652 }
1653 }
1654 }
1655
1664 function setChannels($channels, $merge = false)
1665 {
1666 if (!is_array($channels)) {
1667 return false;
1668 }
1669
1670 if ($merge) {
1671 $this->_channels = array_merge($this->_channels, $channels);
1672 } else {
1673 $this->_channels = $channels;
1674 }
1675
1676 foreach ($channels as $channel) {
1677 $channel = strtolower($channel);
1678 if ($channel == 'pear.php.net') {
1679 continue;
1680 }
1681
1682 foreach ($this->layers as $layer) {
1683 if (!isset($this->configuration[$layer]['__channels'])) {
1684 $this->configuration[$layer]['__channels'] = array();
1685 }
1686 if (!isset($this->configuration[$layer]['__channels'][$channel])
1687 || !is_array($this->configuration[$layer]['__channels'][$channel])) {
1688 $this->configuration[$layer]['__channels'][$channel] = array();
1689 }
1690 }
1691 }
1692
1693 return true;
1694 }
1695
1707 function getType($key)
1708 {
1709 if (isset($this->configuration_info[$key])) {
1710 return $this->configuration_info[$key]['type'];
1711 }
1712 return false;
1713 }
1714
1724 function getDocs($key)
1725 {
1726 if (isset($this->configuration_info[$key])) {
1727 return $this->configuration_info[$key]['doc'];
1728 }
1729
1730 return false;
1731 }
1732
1742 function getPrompt($key)
1743 {
1744 if (isset($this->configuration_info[$key])) {
1745 return $this->configuration_info[$key]['prompt'];
1746 }
1747
1748 return false;
1749 }
1750
1760 function getGroup($key)
1761 {
1762 if (isset($this->configuration_info[$key])) {
1763 return $this->configuration_info[$key]['group'];
1764 }
1765
1766 return false;
1767 }
1768
1777 function getGroups()
1778 {
1779 $tmp = array();
1780 foreach ($this->configuration_info as $key => $info) {
1781 $tmp[$info['group']] = 1;
1782 }
1783
1784 return array_keys($tmp);
1785 }
1786
1796 function getGroupKeys($group)
1797 {
1798 $keys = array();
1799 foreach ($this->configuration_info as $key => $info) {
1800 if ($info['group'] == $group) {
1801 $keys[] = $key;
1802 }
1803 }
1804
1805 return $keys;
1806 }
1807
1819 function getSetValues($key)
1820 {
1821 if (isset($this->configuration_info[$key]) &&
1822 isset($this->configuration_info[$key]['type']) &&
1823 $this->configuration_info[$key]['type'] == 'set')
1824 {
1825 $valid_set = $this->configuration_info[$key]['valid_set'];
1826 reset($valid_set);
1827 if (key($valid_set) === 0) {
1828 return $valid_set;
1829 }
1830
1831 return array_keys($valid_set);
1832 }
1833
1834 return null;
1835 }
1836
1844 function getKeys()
1845 {
1846 $keys = array();
1847 foreach ($this->layers as $layer) {
1848 $test = $this->configuration[$layer];
1849 if (isset($test['__channels'])) {
1850 foreach ($test['__channels'] as $channel => $configs) {
1851 $keys = array_merge($keys, $configs);
1852 }
1853 }
1854
1855 unset($test['__channels']);
1856 $keys = array_merge($keys, $test);
1857
1858 }
1859 return array_keys($keys);
1860 }
1861
1872 function remove($key, $layer = 'user', $channel = null)
1873 {
1874 if ($channel === null) {
1875 $channel = $this->getDefaultChannel();
1876 }
1877
1878 if ($channel !== 'pear.php.net') {
1879 if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1880 unset($this->configuration[$layer]['__channels'][$channel][$key]);
1881 return true;
1882 }
1883 }
1884
1885 if (isset($this->configuration[$layer][$key])) {
1886 unset($this->configuration[$layer][$key]);
1887 return true;
1888 }
1889
1890 return false;
1891 }
1892
1902 function removeLayer($layer)
1903 {
1904 if (isset($this->configuration[$layer])) {
1905 $this->configuration[$layer] = array();
1906 return true;
1907 }
1908
1909 return false;
1910 }
1911
1920 function store($layer = 'user', $data = null)
1921 {
1922 return $this->writeConfigFile(null, $layer, $data);
1923 }
1924
1938 function definedBy($key, $returnchannel = false)
1939 {
1940 foreach ($this->layers as $layer) {
1941 $channel = $this->getDefaultChannel();
1942 if ($channel !== 'pear.php.net') {
1943 if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
1944 if ($returnchannel) {
1945 return array('layer' => $layer, 'channel' => $channel);
1946 }
1947 return $layer;
1948 }
1949 }
1950
1951 if (isset($this->configuration[$layer][$key])) {
1952 if ($returnchannel) {
1953 return array('layer' => $layer, 'channel' => 'pear.php.net');
1954 }
1955 return $layer;
1956 }
1957 }
1958
1959 return '';
1960 }
1961
1970 function isDefined($key)
1971 {
1972 foreach ($this->layers as $layer) {
1973 if (isset($this->configuration[$layer][$key])) {
1974 return true;
1975 }
1976 }
1977
1978 return false;
1979 }
1980
1989 function isDefinedLayer($layer)
1990 {
1991 return isset($this->configuration[$layer]);
1992 }
1993
1999 function getLayers()
2000 {
2001 $cf = $this->configuration;
2002 unset($cf['default']);
2003 return array_keys($cf);
2004 }
2005
2006 function apiVersion()
2007 {
2008 return '1.1';
2009 }
2010
2014 function &getRegistry($use = null)
2015 {
2016 $layer = $use === null ? 'user' : $use;
2017 if (isset($this->_registry[$layer])) {
2018 return $this->_registry[$layer];
2019 } elseif ($use === null && isset($this->_registry['system'])) {
2020 return $this->_registry['system'];
2021 } elseif ($use === null && isset($this->_registry['default'])) {
2022 return $this->_registry['default'];
2023 } elseif ($use) {
2024 $a = false;
2025 return $a;
2026 }
2027
2028 // only go here if null was passed in
2029 echo "CRITICAL ERROR: Registry could not be initialized from any value";
2030 exit(1);
2031 }
2032
2038 function setRegistry(&$reg, $layer = 'user')
2039 {
2040 if ($this->_noRegistry) {
2041 return false;
2042 }
2043
2044 if (!in_array($layer, array('user', 'system'))) {
2045 return false;
2046 }
2047
2048 $this->_registry[$layer] = &$reg;
2049 if (is_object($reg)) {
2050 $this->_registry[$layer]->setConfig($this, false);
2051 }
2052
2053 return true;
2054 }
2055
2056 function noRegistry()
2057 {
2058 $this->_noRegistry = true;
2059 }
2060
2064 function &getREST($version, $options = array())
2065 {
2066 $version = str_replace('.', '', $version);
2067 if (!class_exists($class = 'PEAR_REST_' . $version)) {
2068 require_once 'PEAR/REST/' . $version . '.php';
2069 }
2070
2071 $remote = new $class($this, $options);
2072 return $remote;
2073 }
2074
2080 function &getFTP()
2081 {
2082 if (isset($this->_ftp)) {
2083 return $this->_ftp;
2084 }
2085
2086 $a = false;
2087 return $a;
2088 }
2089
2090 static function _prependPath($path, $prepend)
2091 {
2092 if (strlen($prepend) > 0) {
2093 if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
2094 if (preg_match('/^[a-z]:/i', $prepend)) {
2095 $prepend = substr($prepend, 2);
2096 } elseif ($prepend[0] != '\\') {
2097 $prepend = "\\$prepend";
2098 }
2099 $path = substr($path, 0, 2) . $prepend . substr($path, 2);
2100 } else {
2101 $path = $prepend . $path;
2102 }
2103 }
2104 return $path;
2105 }
2106
2111 function setInstallRoot($root)
2112 {
2113 if (substr($root, -1) == DIRECTORY_SEPARATOR) {
2114 $root = substr($root, 0, -1);
2115 }
2116 $old = $this->_installRoot;
2117 $this->_installRoot = $root;
2118 if (($old != $root) && !$this->_noRegistry) {
2119 foreach (array_keys($this->_registry) as $layer) {
2120 if ($layer == 'ftp' || !isset($this->_registry[$layer])) {
2121 continue;
2122 }
2123 $this->_registry[$layer] =
2124 new PEAR_Registry(
2125 $this->get('php_dir', $layer, 'pear.php.net'), false, false,
2126 $this->get('metadata_dir', $layer, 'pear.php.net'));
2127 $this->_registry[$layer]->setConfig($this, false);
2128 $this->_regInitialized[$layer] = false;
2129 }
2130 }
2131 }
2132}
$bearsamppPearBase
Definition Config.php:85
const PEAR_ERROR_RETURN
Definition PEAR.php:24
$GLOBALS['_PEAR_default_error_mode']
Definition PEAR.php:46
static addTempFile($file)
Definition Common.php:208
static isIncludeable($path)
Definition Common.php:432
static initializeConfig(&$config)
Definition Role.php:39
static mktemp($args=null)
Definition System.php:395
$options
Definition pearcmd.php:145
const PEAR_RUNTYPE
Definition peclcmd.php:28