⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 5 页
字号:
    /**     * Make sure the directory where we keep registry files for channels exists     *     * @return bool TRUE if directory exists, FALSE if it could not be     * created     *     * @access private     */    function _assertChannelDir()    {        if (!@is_dir($this->channelsdir)) {            if (!$this->hasWriteAccess()) {                return false;            }            require_once 'System.php';            if (!System::mkdir(array('-p', $this->channelsdir))) {                return $this->raiseError("could not create directory '{$this->channelsdir}'");            }        }        if (!@is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {            if (!$this->hasWriteAccess()) {                return false;            }            require_once 'System.php';            if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) {                return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'");            }        }        return true;    }    // }}}    // {{{ _packageFileName()    /**     * Get the name of the file where data for a given package is stored.     *     * @param string channel name, or false if this is a PEAR package     * @param string package name     *     * @return string registry file name     *     * @access public     */    function _packageFileName($package, $channel = false)    {        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {            return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .                strtolower($package) . '.reg';        }        return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';    }    // }}}    // {{{ _channelFileName()    /**     * Get the name of the file where data for a given channel is stored.     * @param string channel name     * @return string registry file name     */    function _channelFileName($channel, $noaliases = false)    {        if (!$noaliases) {            if (@file_exists($this->_getChannelAliasFileName($channel))) {                $channel = implode('', file($this->_getChannelAliasFileName($channel)));            }        }        return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',            strtolower($channel)) . '.reg';    }    // }}}    // {{{ getChannelAliasFileName()    /**     * @param string     * @return string     */    function _getChannelAliasFileName($alias)    {        return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .              DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';    }    // }}}    // {{{ _getChannelFromAlias()    /**     * Get the name of a channel from its alias     */    function _getChannelFromAlias($channel)    {        if (!$this->_channelExists($channel)) {            if ($channel == 'pear.php.net') {                return 'pear.php.net';            }            if ($channel == 'pecl.php.net') {                return 'pecl.php.net';            }            if ($channel == '__uri') {                return '__uri';            }            return false;        }        $channel = strtolower($channel);        if (file_exists($this->_getChannelAliasFileName($channel))) {            // translate an alias to an actual channel            return implode('', file($this->_getChannelAliasFileName($channel)));        } else {            return $channel;        }    }        // }}}    // {{{ _getChannelFromAlias()    /**     * Get the alias of a channel from its alias or its name     */    function _getAlias($channel)    {        if (!$this->_channelExists($channel)) {            if ($channel == 'pear.php.net') {                return 'pear';            }            if ($channel == 'pecl.php.net') {                return 'pecl';            }            return false;        }        $channel = $this->_getChannel($channel);        if (PEAR::isError($channel)) {            return $channel;        }        return $channel->getAlias();    }        // }}}    // {{{ _channelDirectoryName()    /**     * Get the name of the file where data for a given package is stored.     *     * @param string channel name, or false if this is a PEAR package     * @param string package name     *     * @return string registry file name     *     * @access public     */    function _channelDirectoryName($channel)    {        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {            return $this->statedir;        } else {            $ch = $this->_getChannelFromAlias($channel);            if (!$ch) {                $ch = $channel;            }            return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .                str_replace('/', '_', $ch));        }    }    // }}}    // {{{ _openPackageFile()    function _openPackageFile($package, $mode, $channel = false)    {        if (!$this->_assertStateDir($channel)) {            return null;        }        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {            return null;        }        $file = $this->_packageFileName($package, $channel);        $fp = @fopen($file, $mode);        if (!$fp) {            return null;        }        return $fp;    }    // }}}    // {{{ _closePackageFile()    function _closePackageFile($fp)    {        fclose($fp);    }    // }}}    // {{{ _openPackageFile()    function _openChannelFile($channel, $mode)    {        if (!$this->_assertChannelDir()) {            return null;        }        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {            return null;        }        $file = $this->_channelFileName($channel);        $fp = @fopen($file, $mode);        if (!$fp) {            return null;        }        return $fp;    }    // }}}    // {{{ _closePackageFile()    function _closeChannelFile($fp)    {        fclose($fp);    }    // }}}    // {{{ _rebuildFileMap()    function _rebuildFileMap()    {        if (!class_exists('PEAR_Installer_Role')) {            require_once 'PEAR/Installer/Role.php';        }        $channels = $this->_listAllPackages();        $files = array();        foreach ($channels as $channel => $packages) {            foreach ($packages as $package) {                $version = $this->_packageInfo($package, 'version', $channel);                $filelist = $this->_packageInfo($package, 'filelist', $channel);                if (!is_array($filelist)) {                    continue;                }                foreach ($filelist as $name => $attrs) {                    if (isset($attrs['attribs'])) {                        $attrs = $attrs['attribs'];                    }                    // it is possible for conflicting packages in different channels to                    // conflict with data files/doc files                    if ($name == 'dirtree') {                        continue;                    }                    if (isset($attrs['role']) && !in_array($attrs['role'],                          PEAR_Installer_Role::getInstallableRoles())) {                        // these are not installed                        continue;                    }                    if (isset($attrs['role']) && !in_array($attrs['role'],                          PEAR_Installer_Role::getBaseinstallRoles())) {                        $attrs['baseinstalldir'] = $package;                    }                    if (isset($attrs['baseinstalldir'])) {                        $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;                    } else {                        $file = $name;                    }                    $file = preg_replace(',^/+,', '', $file);                    if ($channel != 'pear.php.net') {                        $files[$attrs['role']][$file] = array(strtolower($channel),                            strtolower($package));                    } else {                        $files[$attrs['role']][$file] = strtolower($package);                    }                }            }        }        $this->_assertStateDir();        if (!$this->hasWriteAccess()) {            return false;        }        $fp = @fopen($this->filemap, 'wb');        if (!$fp) {            return false;        }        $this->filemap_cache = $files;        fwrite($fp, serialize($files));        fclose($fp);        return true;    }    // }}}    // {{{ _readFileMap()    function _readFileMap()    {        $fp = @fopen($this->filemap, 'r');        if (!$fp) {            return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);        }        clearstatcache();        $rt = get_magic_quotes_runtime();        set_magic_quotes_runtime(0);        $fsize = filesize($this->filemap);        if (function_exists('file_get_contents')) {            fclose($fp);            $data = file_get_contents($this->filemap);        } else {            $data = fread($fp, $fsize);            fclose($fp);        }        set_magic_quotes_runtime($rt);        $tmp = unserialize($data);        if (!$tmp && $fsize > 7) {            return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);        }        $this->filemap_cache = $tmp;        return true;    }    // }}}    // {{{ _lock()    /**     * Lock the registry.     *     * @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.     *                See flock manual for more information.     *     * @return bool TRUE on success, FALSE if locking failed, or a     *              PEAR error if some other error occurs (such as the     *              lock file not being writable).     *     * @access private     */    function _lock($mode = LOCK_EX)    {        if (!eregi('Windows 9', php_uname())) {            if ($mode != LOCK_UN && is_resource($this->lock_fp)) {                // XXX does not check type of lock (LOCK_SH/LOCK_EX)                return true;            }            if (!$this->_assertStateDir()) {                if ($mode == LOCK_EX) {                    return $this->raiseError('Registry directory is not writeable by the current user');                } else {                    return true;                }            }            $open_mode = 'w';            // XXX People reported problems with LOCK_SH and 'w'            if ($mode === LOCK_SH || $mode === LOCK_UN) {                if (@!is_file($this->lockfile)) {                    touch($this->lockfile);                }                $open_mode = 'r';            }            if (!is_resource($this->lock_fp)) {                $this->lock_fp = @fopen($this->lockfile, $open_mode);            }            if (!is_resource($this->lock_fp)) {                return $this->raiseError("could not create lock file" .                                         (isset($php_errormsg) ? ": " . $php_errormsg : ""));            }            if (!(int)flock($this->lock_fp, $mode)) {                switch ($mode) {                    case LOCK_SH: $str = 'shared';    break;                    case LOCK_EX: $str = 'exclusive'; break;                    case LOCK_UN: $str = 'unlock';    break;                    default:      $str = 'unknown';   break;                }                return $this->raiseError("could not acquire $str lock ($this->lockfile)",                                         PEAR_REGISTRY_ERROR_LOCK);            }        }        return true;    }    // }}}    // {{{ _unlock()    function _unlock()    {        $ret = $this->_lock(LOCK_UN);        if (is_resource($this->lock_fp)) {            fclose($this->lock_fp);        }        $this->lock_fp = null;        return $ret;    }    // }}}    // {{{ _packageExists()    function _packageExists($package, $channel = false)    {        return file_exists($this->_packageFileName($package, $channel));    }    // }}}    // {{{ _channelExists()    /**     * Determine whether a channel exists in the registry     * @param string Channel name     * @param bool if true, then aliases will be ignored     * @return boolean     */    function _channelExists($channel, $noaliases = false)    {        $a = file_exists($this->_channelFileName($channel, $noaliases));        if (!$a && $channel == 'pear.php.net') {            return true;        }        if (!$a && $channel == 'pecl.php.net') {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -