20require_once
'PEAR.php';
21require_once
'PEAR/Registry.php';
22require_once
'PEAR/Installer/Role.php';
23require_once
'System.php';
30if (!defined(
'PEAR_INSTALL_DIR') || !PEAR_INSTALL_DIR) {
31 $PEAR_INSTALL_DIR = PHP_LIBDIR . DIRECTORY_SEPARATOR .
'pear';
33 $PEAR_INSTALL_DIR = PEAR_INSTALL_DIR;
44if (!defined(
'PEAR_RUNTYPE')) {
45 define(
'PEAR_RUNTYPE',
'pear');
49 define(
'PEAR_CONFIG_DEFAULT_CHANNEL',
'pear.php.net');
51 define(
'PEAR_CONFIG_DEFAULT_CHANNEL',
'pecl.php.net');
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')) {
59 define(
'PEAR_CONFIG_SYSCONFDIR', dirname(__DIR__, 2));
60} elseif (getenv(
'SystemRoot')) {
61 define(
'PEAR_CONFIG_SYSCONFDIR', getenv(
'SystemRoot'));
63 define(
'PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
67if (getenv(
'PHP_PEAR_MASTER_SERVER')) {
68 define(
'PEAR_CONFIG_DEFAULT_MASTER_SERVER', getenv(
'PHP_PEAR_MASTER_SERVER'));
70 define(
'PEAR_CONFIG_DEFAULT_MASTER_SERVER',
'pear.php.net');
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'));
79 define(
'PEAR_CONFIG_DEFAULT_HTTP_PROXY',
'');
88if (getenv(
'PHP_PEAR_INSTALL_DIR')) {
89 define(
'PEAR_CONFIG_DEFAULT_PHP_DIR', getenv(
'PHP_PEAR_INSTALL_DIR'));
91 define(
'PEAR_CONFIG_DEFAULT_PHP_DIR',
96if (getenv(
'PHP_PEAR_METADATA_DIR')) {
97 define(
'PEAR_CONFIG_DEFAULT_METADATA_DIR', getenv(
'PHP_PEAR_METADATA_DIR'));
99 define(
'PEAR_CONFIG_DEFAULT_METADATA_DIR',
'');
103if (getenv(
'PHP_PEAR_EXTENSION_DIR')) {
104 define(
'PEAR_CONFIG_DEFAULT_EXT_DIR', getenv(
'PHP_PEAR_EXTENSION_DIR'));
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);
114 define(
'PEAR_CONFIG_DEFAULT_EXT_DIR',
'.');
119if (getenv(
'PHP_PEAR_DOC_DIR')) {
120 define(
'PEAR_CONFIG_DEFAULT_DOC_DIR', getenv(
'PHP_PEAR_DOC_DIR'));
122 define(
'PEAR_CONFIG_DEFAULT_DOC_DIR',
127if (getenv(
'PHP_PEAR_BIN_DIR')) {
128 define(
'PEAR_CONFIG_DEFAULT_BIN_DIR', getenv(
'PHP_PEAR_BIN_DIR'));
134if (getenv(
'PHP_PEAR_DATA_DIR')) {
135 define(
'PEAR_CONFIG_DEFAULT_DATA_DIR', getenv(
'PHP_PEAR_DATA_DIR'));
137 define(
'PEAR_CONFIG_DEFAULT_DATA_DIR',
142if (getenv(
'PHP_PEAR_CFG_DIR')) {
143 define(
'PEAR_CONFIG_DEFAULT_CFG_DIR', getenv(
'PHP_PEAR_CFG_DIR'));
145 define(
'PEAR_CONFIG_DEFAULT_CFG_DIR',
150if (getenv(
'PHP_PEAR_WWW_DIR')) {
151 define(
'PEAR_CONFIG_DEFAULT_WWW_DIR', getenv(
'PHP_PEAR_WWW_DIR'));
153 define(
'PEAR_CONFIG_DEFAULT_WWW_DIR',
158if (getenv(
'PHP_PEAR_MAN_DIR')) {
159 define(
'PEAR_CONFIG_DEFAULT_MAN_DIR', getenv(
'PHP_PEAR_MAN_DIR'));
161 define(
'PEAR_CONFIG_DEFAULT_MAN_DIR',
163 DIRECTORY_SEPARATOR.
'man');
167if (getenv(
'PHP_PEAR_TEST_DIR')) {
168 define(
'PEAR_CONFIG_DEFAULT_TEST_DIR', getenv(
'PHP_PEAR_TEST_DIR'));
170 define(
'PEAR_CONFIG_DEFAULT_TEST_DIR',
175if (getenv(
'PHP_PEAR_TEMP_DIR')) {
176 define(
'PEAR_CONFIG_DEFAULT_TEMP_DIR', getenv(
'PHP_PEAR_TEMP_DIR'));
178 define(
'PEAR_CONFIG_DEFAULT_TEMP_DIR',
179 System::tmpdir() . DIRECTORY_SEPARATOR .
'pear' .
180 DIRECTORY_SEPARATOR .
'temp');
184if (getenv(
'PHP_PEAR_CACHE_DIR')) {
185 define(
'PEAR_CONFIG_DEFAULT_CACHE_DIR', getenv(
'PHP_PEAR_CACHE_DIR'));
187 define(
'PEAR_CONFIG_DEFAULT_CACHE_DIR',
188 System::tmpdir() . DIRECTORY_SEPARATOR .
'pear' .
189 DIRECTORY_SEPARATOR .
'cache');
193if (getenv(
'PHP_PEAR_DOWNLOAD_DIR')) {
194 define(
'PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR', getenv(
'PHP_PEAR_DOWNLOAD_DIR'));
196 define(
'PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR',
197 System::tmpdir() . DIRECTORY_SEPARATOR .
'pear' .
198 DIRECTORY_SEPARATOR .
'download');
202if (getenv(
'PHP_PEAR_PHP_BIN')) {
203 define(
'PEAR_CONFIG_DEFAULT_PHP_BIN', getenv(
'PHP_PEAR_PHP_BIN'));
205 define(
'PEAR_CONFIG_DEFAULT_PHP_BIN',
206 dirname(__DIR__, 3).DIRECTORY_SEPARATOR.
'php'.
207 (OS_WINDOWS ?
'.exe' :
''));
211if (getenv(
'PHP_PEAR_VERBOSE')) {
212 define(
'PEAR_CONFIG_DEFAULT_VERBOSE', getenv(
'PHP_PEAR_VERBOSE'));
214 define(
'PEAR_CONFIG_DEFAULT_VERBOSE', 1);
218if (getenv(
'PHP_PEAR_PREFERRED_STATE')) {
219 define(
'PEAR_CONFIG_DEFAULT_PREFERRED_STATE', getenv(
'PHP_PEAR_PREFERRED_STATE'));
221 define(
'PEAR_CONFIG_DEFAULT_PREFERRED_STATE',
'stable');
225if (getenv(
'PHP_PEAR_UMASK')) {
226 define(
'PEAR_CONFIG_DEFAULT_UMASK', getenv(
'PHP_PEAR_UMASK'));
228 define(
'PEAR_CONFIG_DEFAULT_UMASK', decoct(umask()));
232if (getenv(
'PHP_PEAR_CACHE_TTL')) {
233 define(
'PEAR_CONFIG_DEFAULT_CACHE_TTL', getenv(
'PHP_PEAR_CACHE_TTL'));
235 define(
'PEAR_CONFIG_DEFAULT_CACHE_TTL', 3600);
239if (getenv(
'PHP_PEAR_SIG_TYPE')) {
240 define(
'PEAR_CONFIG_DEFAULT_SIG_TYPE', getenv(
'PHP_PEAR_SIG_TYPE'));
242 define(
'PEAR_CONFIG_DEFAULT_SIG_TYPE',
'gpg');
246if (getenv(
'PHP_PEAR_SIG_BIN')) {
247 define(
'PEAR_CONFIG_DEFAULT_SIG_BIN', getenv(
'PHP_PEAR_SIG_BIN'));
249 define(
'PEAR_CONFIG_DEFAULT_SIG_BIN',
251 'gpg', OS_WINDOWS ?
'c:\gnupg\gpg.exe' :
'/usr/local/bin/gpg'));
255if (getenv(
'PHP_PEAR_SIG_KEYDIR')) {
256 define(
'PEAR_CONFIG_DEFAULT_SIG_KEYDIR', getenv(
'PHP_PEAR_SIG_KEYDIR'));
258 define(
'PEAR_CONFIG_DEFAULT_SIG_KEYDIR',
259 PEAR_CONFIG_SYSCONFDIR . DIRECTORY_SEPARATOR .
'pearkeys');
275class PEAR_Config
extends PEAR
287 var $layers = array();
301 var $configuration = array(
304 'default' => array(),
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'
326 var $_channels = array(
'pear.php.net',
'pecl.php.net',
'__uri');
334 var $_installRoot =
false;
341 var $_registry = array();
347 var $_regInitialized = array();
353 var $_noRegistry =
false;
360 var $_errorsFound = 0;
361 var $_lastError =
null;
370 var $configuration_info = array(
372 'default_channel' => array(
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',
379 'preferred_mirror' => array(
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',
386 'remote_config' => array(
387 'type' =>
'password',
389 'doc' =>
'ftp url of remote configuration file to use for synchronized install',
390 'prompt' =>
'Remote Configuration File',
391 'group' =>
'Internet Access',
393 'auto_discover' => array(
396 'doc' =>
'whether to automatically discover new channels',
397 'prompt' =>
'Auto-discover new Channels',
398 'group' =>
'Internet Access',
401 'master_server' => array(
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',
408 'http_proxy' => array(
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',
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',
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',
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',
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',
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)',
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)',
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)',
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)',
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)',
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)',
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)',
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)',
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)',
507 'php_prefix' => array(
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)',
514 'php_suffix' => array(
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)',
524 'doc' =>
'location of php.ini in which to enable PECL extensions on install',
525 'prompt' =>
'php.ini location',
526 'group' =>
'File Locations (Advanced)',
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)',
539 'doc' =>
'(maintainers) your PEAR account name',
540 'prompt' =>
'PEAR username (for maintainers)',
541 'group' =>
'Maintainers',
544 'type' =>
'password',
546 'doc' =>
'(maintainers) your PEAR account password',
547 'prompt' =>
'PEAR password (for maintainers)',
548 'group' =>
'Maintainers',
553 'default' => PEAR_CONFIG_DEFAULT_VERBOSE,
554 'doc' =>
'verbosity level
559 'prompt' =>
'Debug Log Level',
560 'group' =>
'Advanced',
562 'preferred_state' => array(
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',
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',
578 'cache_ttl' => array(
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',
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',
595 'default' => PEAR_CONFIG_DEFAULT_SIG_BIN,
596 'doc' =>
'which package signature mechanism to use',
597 'prompt' =>
'Signature Handling Program',
598 'group' =>
'Maintainers',
600 'sig_keyid' => array(
603 'doc' =>
'which key to use for signing with',
604 'prompt' =>
'Signature Key Id',
605 'group' =>
'Maintainers',
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',
631 function __construct($user_file =
'', $system_file =
'', $ftp_file =
false,
634 parent::__construct();
636 $sl = DIRECTORY_SEPARATOR;
637 if (empty($user_file)) {
639 $user_file = PEAR_CONFIG_SYSCONFDIR . $sl .
'pear.ini';
641 $user_file = getenv(
'HOME') . $sl .
'.pearrc';
645 if (empty($system_file)) {
646 $system_file = PEAR_CONFIG_SYSCONFDIR . $sl;
648 $system_file .=
'pearsys.ini';
650 $system_file .=
'pear.conf';
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)) {
659 $this->readConfigFile($user_file,
'user', $strict);
660 $this->popErrorHandling();
661 if ($this->_errorsFound > 0) {
666 if ($system_file && @file_exists($system_file)) {
667 $this->mergeConfigFile($system_file,
false,
'system', $strict);
668 if ($this->_errorsFound > 0) {
675 $ftp_file = $this->
get(
'remote_config');
678 if ($ftp_file && defined(
'PEAR_REMOTEINSTALL_OK')) {
679 $this->readFTPConfigFile($ftp_file);
682 foreach ($this->configuration_info as $key => $info) {
683 $this->configuration[
'default'][$key] = $info[
'default'];
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;
697 public static function getDefaultConfigFiles()
699 $sl = DIRECTORY_SEPARATOR;
702 'user' => PEAR_CONFIG_SYSCONFDIR . $sl .
'pear.ini',
703 'system' => PEAR_CONFIG_SYSCONFDIR . $sl .
'pearsys.ini'
708 'user' => getenv(
'HOME') . $sl .
'.pearrc',
709 'system' => PEAR_CONFIG_SYSCONFDIR . $sl .
'pear.conf'
726 public static function &singleton($user_file =
'', $system_file =
'', $strict =
true)
728 if (is_object(
$GLOBALS[
'_PEAR_Config_instance'])) {
729 return $GLOBALS[
'_PEAR_Config_instance'];
732 $t_conf =
new PEAR_Config($user_file, $system_file,
false, $strict);
733 if ($t_conf->_errorsFound > 0) {
734 return $t_conf->_lastError;
737 $GLOBALS[
'_PEAR_Config_instance'] = &$t_conf;
738 return $GLOBALS[
'_PEAR_Config_instance'];
747 function validConfiguration()
749 if ($this->isDefinedLayer(
'user') || $this->isDefinedLayer(
'system')) {
765 function readConfigFile($file =
null, $layer =
'user', $strict =
true)
767 if (empty($this->files[$layer])) {
768 return $this->raiseError(
"unknown config layer `$layer'");
771 if ($file ===
null) {
772 $file = $this->files[$layer];
775 $data = $this->_readConfigDataFrom($file);
776 if (PEAR::isError($data)) {
781 $this->_errorsFound++;
782 $this->_lastError = $data;
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;
798 unset($this->_registry[$layer]);
807 function readFTPConfigFile($path)
810 if (!class_exists(
'PEAR_FTP')) {
811 if (!class_exists(
'PEAR_Common')) {
812 require_once
'PEAR/Common.php';
815 require_once
'PEAR/FTP.php';
819 if (!class_exists(
'PEAR_FTP')) {
820 return PEAR::raiseError(
'PEAR_RemoteInstaller must be installed to use remote config');
823 $this->_ftp =
new PEAR_FTP;
825 $e = $this->_ftp->init($path);
826 if (PEAR::isError($e)) {
827 $this->_ftp->popErrorHandling();
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();
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)) {
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') {
855 if (!isset($this->configuration[
'ftp'][$key])) {
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: ' .
872 unset($this->files[
'ftp']);
873 return PEAR::raiseError(
'no remote host specified');
879 function _setupChannels()
881 $set = array_flip(array_values($this->_channels));
882 foreach ($this->configuration as $layer => $data) {
884 if (isset($data[
'__channels']) && is_array($data[
'__channels'])) {
885 foreach ($data[
'__channels'] as $channel => $info) {
886 $set[$channel] = $i++;
890 $this->_channels = array_values(array_flip($set));
891 $this->setChannels($this->_channels);
894 function deleteChannel($channel)
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]);
903 $this->_channels = array_flip($this->_channels);
904 unset($this->_channels[$ch]);
905 $this->_channels = array_flip($this->_channels);
918 function mergeConfigFile($file, $override =
true, $layer =
'user', $strict =
true)
920 if (empty($this->files[$layer])) {
921 return $this->raiseError(
"unknown config layer `$layer'");
924 if ($file ===
null) {
925 $file = $this->files[$layer];
928 $data = $this->_readConfigDataFrom($file);
929 if (PEAR::isError($data)) {
934 $this->_errorsFound++;
935 $this->_lastError = $data;
940 $this->_decodeInput($data);
942 $this->configuration[$layer] =
943 PEAR_Config::arrayMergeRecursive($this->configuration[$layer], $data);
945 $this->configuration[$layer] =
946 PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]);
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;
957 unset($this->_registry[$layer]);
967 public static function arrayMergeRecursive($arr2, $arr1)
970 foreach ($arr2 as $key => $data) {
971 if (!isset($arr1[$key])) {
976 if (is_array($data)) {
977 if (!is_array($arr1[$key])) {
978 $ret[$key] = $arr1[$key];
982 $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
987 return array_merge($ret, $arr1);
999 function writeConfigFile($file =
null, $layer =
'user', $data =
null)
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)) {
1012 if (empty($this->files[$layer])) {
1013 return $this->raiseError(
"unknown config file type `$layer'");
1016 if ($file ===
null) {
1017 $file = $this->files[$layer];
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));
1027 if (file_exists($file) && is_file($file) && !is_writeable($file)) {
1028 return $this->raiseError(
"no write access to $file!");
1031 $fp = @fopen($file,
"w");
1033 return $this->raiseError(
"PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)");
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)");
1051 function _readConfigDataFrom($file)
1054 if (file_exists($file)) {
1055 $fp = @fopen($file,
"r");
1059 return $this->raiseError(
"PEAR_Config::readConfigFile fopen('$file','r') failed");
1062 $size = filesize($file);
1064 $contents = file_get_contents($file);
1065 if (empty($contents)) {
1066 return $this->raiseError(
'Configuration file "' . $file .
'" is empty');
1070 if (preg_match(
'/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
1071 $version = $matches[1];
1072 $contents = substr($contents, strlen($matches[0]));
1075 if (substr($contents,0,2) ==
'a:') {
1080 if ($version && version_compare(
"$version",
'1',
'<')) {
1081 $data = @unserialize($contents);
1083 if (!is_array($data) && !$data) {
1084 if ($contents == serialize(
false)) {
1087 $err = $this->raiseError(
"PEAR_Config: bad data in $file");
1091 if (!is_array($data)) {
1092 if (strlen(trim($contents)) > 0) {
1093 $error =
"PEAR_Config: bad data in $file";
1094 $err = $this->raiseError($error);
1102 $err = $this->raiseError(
"$file: unknown version `$version'");
1114 function getConfFile($layer)
1116 return $this->files[$layer];
1125 function _addConfigVars($class, $vars)
1127 static $called = array();
1128 if (isset($called[$class])) {
1132 $called[$class] = 1;
1133 if (count($vars) > 3) {
1134 return $this->raiseError(
'Roles can only define 3 new config variables or less');
1137 foreach ($vars as $name => $var) {
1138 if (!is_array($var)) {
1139 return $this->raiseError(
'Configuration information must be an array');
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');
1150 if (!isset($var[
'default'])) {
1151 return $this->raiseError(
1152 'Configuration information must contain a default value ("default" index)');
1155 if (is_array($var[
'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 "' .
1168 $real_default .= constant($val);
1169 } elseif (isset($this->configuration_info[$config_var])) {
1171 $this->configuration_info[$config_var][
'default'];
1173 return $this->raiseError(
1174 'Unknown request for "' . $config_var .
'" value in ' .
1175 'default value for configuration variable "' .
1179 $var[
'default'] = $real_default;
1182 if ($var[
'type'] ==
'integer') {
1183 $var[
'default'] = (integer) $var[
'default'];
1186 if (!isset($var[
'doc'])) {
1187 return $this->raiseError(
1188 'Configuration information must contain a summary ("doc" index)');
1191 if (!isset($var[
'prompt'])) {
1192 return $this->raiseError(
1193 'Configuration information must contain a simple prompt ("prompt" index)');
1196 if (!isset($var[
'group'])) {
1197 return $this->raiseError(
1198 'Configuration information must contain a simple group ("group" index)');
1201 if (isset($this->configuration_info[$name])) {
1202 return $this->raiseError(
'Configuration variable "' . $name .
1203 '" already exists');
1206 $this->configuration_info[$name] = $var;
1208 $this->_channelConfigInfo[] = $name;
1223 function _encodeOutput(&$data)
1225 foreach ($data as $key => $value) {
1226 if ($key ==
'__channels') {
1227 foreach ($data[
'__channels'] as $channel => $blah) {
1228 $this->_encodeOutput($data[
'__channels'][$channel]);
1232 if (!isset($this->configuration_info[$key])) {
1236 $type = $this->configuration_info[$key][
'type'];
1241 $data[$key] = base64_encode($data[$key]);
1245 $data[$key] = octdec($data[$key]);
1263 function _decodeInput(&$data)
1265 if (!is_array($data)) {
1269 foreach ($data as $key => $value) {
1270 if ($key ==
'__channels') {
1271 foreach ($data[
'__channels'] as $channel => $blah) {
1272 $this->_decodeInput($data[
'__channels'][$channel]);
1276 if (!isset($this->configuration_info[$key])) {
1280 $type = $this->configuration_info[$key][
'type'];
1283 $data[$key] = base64_decode($data[$key]);
1287 $data[$key] = decoct($data[$key]);
1304 function getDefaultChannel($layer =
null)
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'];
1314 } elseif (isset($this->configuration[$layer][
'default_channel'])) {
1315 $ret = $this->configuration[$layer][
'default_channel'];
1318 if ($ret ==
'pear.php.net' && defined(
'PEAR_RUNTYPE') &&
PEAR_RUNTYPE ==
'pecl') {
1319 $ret =
'pecl.php.net';
1323 if ($ret !=
'pear.php.net') {
1324 $this->_lazyChannelSetup();
1330 return PEAR_CONFIG_DEFAULT_CHANNEL;
1341 function get($key, $layer =
null, $channel =
false)
1343 if (!isset($this->configuration_info[$key])) {
1347 if ($key ==
'__channels') {
1351 if ($key ==
'default_channel') {
1352 return $this->getDefaultChannel($layer);
1356 $channel = $this->getDefaultChannel();
1357 } elseif ($channel !=
'pear.php.net') {
1358 $this->_lazyChannelSetup();
1360 $channel = strtolower($channel);
1362 $test = (in_array($key, $this->_channelConfigInfo)) ?
1363 $this->_getChannelValue($key, $layer, $channel) :
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);
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);
1388 if ($key ==
'preferred_mirror') {
1389 $reg = &$this->getRegistry();
1390 if (is_object($reg)) {
1391 $chan = $reg->getChannel($channel);
1392 if (PEAR::isError($chan)) {
1396 if (!$chan->getMirror($test) && $chan->getName() != $test) {
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);
1414 if ($key ==
'preferred_mirror') {
1415 $reg = &$this->getRegistry();
1416 if (is_object($reg)) {
1417 $chan = $reg->getChannel($channel);
1418 if (PEAR::isError($chan)) {
1422 if (!$chan->getMirror($test) && $chan->getName() != $test) {
1442 function _getChannelValue($key, $layer, $channel)
1444 if ($key ==
'__channels' || $channel ==
'pear.php.net') {
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];
1456 } elseif (isset($this->configuration[$layer][
'__channels'][$channel][$key])) {
1457 $ret = $this->configuration[$layer][
'__channels'][$channel][$key];
1460 if ($key !=
'preferred_mirror') {
1465 if ($ret !==
null) {
1466 $reg = &$this->getRegistry($layer);
1467 if (is_object($reg)) {
1468 $chan = $reg->getChannel($channel);
1469 if (PEAR::isError($chan)) {
1473 if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
1481 if ($channel != $this->getDefaultChannel($layer)) {
1486 return $this->getDefaultChannel($layer);
1501 function set($key, $value, $layer =
'user', $channel =
false)
1503 if ($key ==
'__channels') {
1507 if (!isset($this->configuration[$layer])) {
1511 if ($key ==
'default_channel') {
1513 $channel =
'pear.php.net';
1514 if ($value !=
'pear.php.net') {
1515 $this->_lazyChannelSetup($layer);
1519 if ($key ==
'preferred_mirror') {
1520 if ($channel ==
'__uri') {
1524 $reg = &$this->getRegistry($layer);
1525 if (is_object($reg)) {
1526 $chan = $reg->getChannel($channel ? $channel :
'pear.php.net');
1527 if (PEAR::isError($chan)) {
1531 if (!$chan->getMirror($value) && $chan->getName() != $value) {
1537 if (!isset($this->configuration_info[$key])) {
1541 extract($this->configuration_info[$key]);
1544 $value = (int)$value;
1552 if ((key($valid_set) === 0 && !in_array($value, $valid_set)) ||
1553 (key($valid_set) !== 0 && empty($valid_set[$value])))
1563 $channel = $this->
get(
'default_channel',
null,
'pear.php.net');
1566 if (!in_array($channel, $this->_channels)) {
1567 $this->_lazyChannelSetup($layer);
1568 $reg = &$this->getRegistry($layer);
1570 $channel = $reg->channelName($channel);
1573 if (!in_array($channel, $this->_channels)) {
1578 if ($channel !=
'pear.php.net') {
1579 if (in_array($key, $this->_channelConfigInfo)) {
1580 $this->configuration[$layer][
'__channels'][$channel][$key] = $value;
1587 if ($key ==
'default_channel') {
1589 $reg = &$this->getRegistry($layer);
1591 $reg = &$this->getRegistry();
1596 $value = $reg->channelName($value);
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);
1617 function _lazyChannelSetup($uselayer =
false)
1619 if ($this->_noRegistry) {
1624 foreach ($this->_registry as $layer => $p) {
1625 if ($uselayer && $uselayer != $layer) {
1629 if (!$this->_regInitialized[$layer]) {
1630 if ($layer ==
'default' && isset($this->_registry[
'user']) ||
1631 isset($this->_registry[
'system'])) {
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;
1644 unset($this->_registry[$layer]);
1649 $this->setChannels($this->_registry[$layer]->listChannels(), $merge);
1650 $this->_regInitialized[$layer] =
true;
1664 function setChannels($channels, $merge =
false)
1666 if (!is_array($channels)) {
1671 $this->_channels = array_merge($this->_channels, $channels);
1673 $this->_channels = $channels;
1676 foreach ($channels as $channel) {
1677 $channel = strtolower($channel);
1678 if ($channel ==
'pear.php.net') {
1682 foreach ($this->layers as $layer) {
1683 if (!isset($this->configuration[$layer][
'__channels'])) {
1684 $this->configuration[$layer][
'__channels'] = array();
1686 if (!isset($this->configuration[$layer][
'__channels'][$channel])
1687 || !is_array($this->configuration[$layer][
'__channels'][$channel])) {
1688 $this->configuration[$layer][
'__channels'][$channel] = array();
1707 function getType($key)
1709 if (isset($this->configuration_info[$key])) {
1710 return $this->configuration_info[$key][
'type'];
1724 function getDocs($key)
1726 if (isset($this->configuration_info[$key])) {
1727 return $this->configuration_info[$key][
'doc'];
1742 function getPrompt($key)
1744 if (isset($this->configuration_info[$key])) {
1745 return $this->configuration_info[$key][
'prompt'];
1760 function getGroup($key)
1762 if (isset($this->configuration_info[$key])) {
1763 return $this->configuration_info[$key][
'group'];
1777 function getGroups()
1780 foreach ($this->configuration_info as $key => $info) {
1781 $tmp[$info[
'group']] = 1;
1784 return array_keys($tmp);
1796 function getGroupKeys($group)
1799 foreach ($this->configuration_info as $key => $info) {
1800 if ($info[
'group'] == $group) {
1819 function getSetValues($key)
1821 if (isset($this->configuration_info[$key]) &&
1822 isset($this->configuration_info[$key][
'type']) &&
1823 $this->configuration_info[$key][
'type'] ==
'set')
1825 $valid_set = $this->configuration_info[$key][
'valid_set'];
1827 if (key($valid_set) === 0) {
1831 return array_keys($valid_set);
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);
1855 unset($test[
'__channels']);
1856 $keys = array_merge($keys, $test);
1859 return array_keys($keys);
1872 function remove($key, $layer =
'user', $channel =
null)
1874 if ($channel ===
null) {
1875 $channel = $this->getDefaultChannel();
1878 if ($channel !==
'pear.php.net') {
1879 if (isset($this->configuration[$layer][
'__channels'][$channel][$key])) {
1880 unset($this->configuration[$layer][
'__channels'][$channel][$key]);
1885 if (isset($this->configuration[$layer][$key])) {
1886 unset($this->configuration[$layer][$key]);
1902 function removeLayer($layer)
1904 if (isset($this->configuration[$layer])) {
1905 $this->configuration[$layer] = array();
1920 function store($layer =
'user', $data =
null)
1922 return $this->writeConfigFile(
null, $layer, $data);
1938 function definedBy($key, $returnchannel =
false)
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);
1951 if (isset($this->configuration[$layer][$key])) {
1952 if ($returnchannel) {
1953 return array(
'layer' => $layer,
'channel' =>
'pear.php.net');
1970 function isDefined($key)
1972 foreach ($this->layers as $layer) {
1973 if (isset($this->configuration[$layer][$key])) {
1989 function isDefinedLayer($layer)
1991 return isset($this->configuration[$layer]);
1999 function getLayers()
2001 $cf = $this->configuration;
2002 unset($cf[
'default']);
2003 return array_keys($cf);
2006 function apiVersion()
2014 function &getRegistry($use =
null)
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'];
2029 echo
"CRITICAL ERROR: Registry could not be initialized from any value";
2038 function setRegistry(&$reg, $layer =
'user')
2040 if ($this->_noRegistry) {
2044 if (!in_array($layer, array(
'user',
'system'))) {
2048 $this->_registry[$layer] = &$reg;
2049 if (is_object($reg)) {
2050 $this->_registry[$layer]->setConfig($this,
false);
2056 function noRegistry()
2058 $this->_noRegistry =
true;
2064 function &getREST($version,
$options = array())
2066 $version = str_replace(
'.',
'', $version);
2067 if (!class_exists($class =
'PEAR_REST_' . $version)) {
2068 require_once
'PEAR/REST/' . $version .
'.php';
2071 $remote =
new $class($this,
$options);
2082 if (isset($this->_ftp)) {
2090 static function _prependPath($path, $prepend)
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";
2099 $path = substr($path, 0, 2) . $prepend . substr($path, 2);
2101 $path = $prepend . $path;
2111 function setInstallRoot($root)
2113 if (substr($root, -1) == DIRECTORY_SEPARATOR) {
2114 $root = substr($root, 0, -1);
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])) {
2123 $this->_registry[$layer] =
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;
$GLOBALS['_PEAR_default_error_mode']
static addTempFile($file)
static isIncludeable($path)
static initializeConfig(&$config)
static mktemp($args=null)