@@ -0,0 +1,2228 @@
+<?php
+/**
+ * PEAR_Registry
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category pear
+ * @package PEAR
+ * @author Stig Bakken <ssb@php.net>
+ * @author Tomas V. V. Cox <cox@idecnet.com>
+ * @author Greg Beaver <cellog@php.net>
+ * @copyright 1997-2006 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version CVS: $Id: Registry.php,v 1.167.2.1 2007/09/08 15:02:49 cellog Exp $
+ * @link http://pear.php.net/package/PEAR
+ * @since File available since Release 0.1
+ */
+
+/**
+ * for PEAR_Error
+ */
+require_once 'PEAR.php';
+require_once 'PEAR/DependencyDB.php';
+
+define('PEAR_REGISTRY_ERROR_LOCK', -2);
+define('PEAR_REGISTRY_ERROR_FORMAT', -3);
+define('PEAR_REGISTRY_ERROR_FILE', -4);
+define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
+define('PEAR_REGISTRY_ERROR_CHANNEL_FILE', -6);
+
+/**
+ * Administration class used to maintain the installed package database.
+ * @category pear
+ * @package PEAR
+ * @author Stig Bakken <ssb@php.net>
+ * @author Tomas V. V. Cox <cox@idecnet.com>
+ * @author Greg Beaver <cellog@php.net>
+ * @copyright 1997-2006 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/PEAR
+ * @since Class available since Release 1.4.0a1
+ */
+class PEAR_Registry extends PEAR
+{
+ // {{{ properties
+
+ /**
+ * File containing all channel information.
+ * @var string
+ */
+ var $channels = '';
+
+ /** Directory where registry files are stored.
+ * @var string
+ */
+ var $statedir = '';
+
+ /** File where the file map is stored
+ * @var string
+ */
+ var $filemap = '';
+
+ /** Directory where registry files for channels are stored.
+ * @var string
+ */
+ var $channelsdir = '';
+
+ /** Name of file used for locking the registry
+ * @var string
+ */
+ var $lockfile = '';
+
+ /** File descriptor used during locking
+ * @var resource
+ */
+ var $lock_fp = null;
+
+ /** Mode used during locking
+ * @var int
+ */
+ var $lock_mode = 0; // XXX UNUSED
+
+ /** Cache of package information. Structure:
+ * array(
+ * 'package' => array('id' => ... ),
+ * ... )
+ * @var array
+ */
+ var $pkginfo_cache = array();
+
+ /** Cache of file map. Structure:
+ * array( '/path/to/file' => 'package', ... )
+ * @var array
+ */
+ var $filemap_cache = array();
+
+ /**
+ * @var false|PEAR_ChannelFile
+ */
+ var $_pearChannel;
+
+ /**
+ * @var false|PEAR_ChannelFile
+ */
+ var $_peclChannel;
+
+ /**
+ * @var PEAR_DependencyDB
+ */
+ var $_dependencyDB;
+
+ /**
+ * @var PEAR_Config
+ */
+ var $_config;
+ // }}}
+
+ // {{{ constructor
+
+ /**
+ * PEAR_Registry constructor.
+ *
+ * @param string (optional) PEAR install directory (for .php files)
+ * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
+ * default values are not desired. Only used the very first time a PEAR
+ * repository is initialized
+ * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
+ * default values are not desired. Only used the very first time a PEAR
+ * repository is initialized
+ *
+ * @access public
+ */
+ function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
+ $pecl_channel = false)
+ {
+ parent::PEAR();
+ $ds = DIRECTORY_SEPARATOR;
+ $this->install_dir = $pear_install_dir;
+ $this->channelsdir = $pear_install_dir.$ds.'.channels';
+ $this->statedir = $pear_install_dir.$ds.'.registry';
+ $this->filemap = $pear_install_dir.$ds.'.filemap';
+ $this->lockfile = $pear_install_dir.$ds.'.lock';
+ $this->_pearChannel = $pear_channel;
+ $this->_peclChannel = $pecl_channel;
+ $this->_config = false;
+ }
+
+ function hasWriteAccess()
+ {
+ if (!file_exists($this->install_dir)) {
+ $dir = $this->install_dir;
+ while ($dir && $dir != '.') {
+ $olddir = $dir;
+ $dir = dirname($dir); // cd ..
+ if ($dir != '.' && file_exists($dir)) {
+ if (is_writeable($dir)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ if ($dir == $olddir) { // this can happen in safe mode
+ return @is_writable($dir);
+ }
+ }
+ return false;
+ }
+ return is_writeable($this->install_dir);
+ }
+
+ function setConfig(&$config)
+ {
+ $this->_config = &$config;
+ }
+
+ function _initializeChannelDirs()
+ {
+ static $running = false;
+ if (!$running) {
+ $running = true;
+ $ds = DIRECTORY_SEPARATOR;
+ if (!is_dir($this->channelsdir) ||
+ !file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
+ !file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
+ !file_exists($this->channelsdir . $ds . '__uri.reg')) {
+ if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
+ $pear_channel = $this->_pearChannel;
+ if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
+ if (!class_exists('PEAR_ChannelFile')) {
+ require_once 'PEAR/ChannelFile.php';
+ }
+ $pear_channel = new PEAR_ChannelFile;
|