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

📄 v1.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * package.xml parsing class, package.xml version 1.0 * * 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     Greg Beaver <cellog@php.net> * @copyright  1997-2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    CVS: $Id: v1.php,v 1.1.2.1 2005/11/02 16:57:27 cellog Exp $ * @link       http://pear.php.net/package/PEAR * @since      File available since Release 1.4.0a1 *//** * package.xml abstraction class */require_once 'PEAR/PackageFile/v1.php';/** * Parser for package.xml version 1.0 * @category   pear * @package    PEAR * @author     Greg Beaver <cellog@php.net> * @copyright  1997-2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    Release: @PEAR-VER@ * @link       http://pear.php.net/package/PEAR * @since      Class available since Release 1.4.0a1 */class PEAR_PackageFile_Parser_v1{    var $_registry;    var $_config;    var $_logger;    /**     * BC hack to allow PEAR_Common::infoFromString() to sort of     * work with the version 2.0 format - there's no filelist though     * @param PEAR_PackageFile_v2     */    function fromV2($packagefile)    {        $info = $packagefile->getArray(true);        $ret = new PEAR_PackageFile_v1;        $ret->fromArray($info['old']);    }    function setConfig(&$c)    {        $this->_config = &$c;        $this->_registry = &$c->getRegistry();    }    function setLogger(&$l)    {        $this->_logger = &$l;    }    /**     * @param string contents of package.xml file, version 1.0     * @return bool success of parsing     */    function parse($data, $file, $archive = false)    {        if (!extension_loaded('xml')) {            return PEAR::raiseError('Cannot create xml parser for parsing package.xml, no xml extension');        }        $xp = @xml_parser_create();        if (!$xp) {            return PEAR::raiseError('Cannot create xml parser for parsing package.xml');        }        xml_set_object($xp, $this);        xml_set_element_handler($xp, '_element_start_1_0', '_element_end_1_0');        xml_set_character_data_handler($xp, '_pkginfo_cdata_1_0');        xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);        $this->element_stack = array();        $this->_packageInfo = array('provides' => array());        $this->current_element = false;        unset($this->dir_install);        $this->_packageInfo['filelist'] = array();        $this->filelist =& $this->_packageInfo['filelist'];        $this->dir_names = array();        $this->in_changelog = false;        $this->d_i = 0;        $this->cdata = '';        $this->_isValid = true;        if (!xml_parse($xp, $data, 1)) {            $code = xml_get_error_code($xp);            $line = xml_get_current_line_number($xp);            xml_parser_free($xp);            return PEAR::raiseError(sprintf("XML error: %s at line %d",                           $str = xml_error_string($code), $line), 2);        }        xml_parser_free($xp);        $pf = new PEAR_PackageFile_v1;        $pf->setConfig($this->_config);        if (isset($this->_logger)) {            $pf->setLogger($this->_logger);        }        $pf->setPackagefile($file, $archive);        $pf->fromArray($this->_packageInfo);        return $pf;    }    // {{{ _unIndent()    /**     * Unindent given string     *     * @param string $str The string that has to be unindented.     * @return string     * @access private     */    function _unIndent($str)    {        // remove leading newlines        $str = preg_replace('/^[\r\n]+/', '', $str);        // find whitespace at the beginning of the first line        $indent_len = strspn($str, " \t");        $indent = substr($str, 0, $indent_len);        $data = '';        // remove the same amount of whitespace from following lines        foreach (explode("\n", $str) as $line) {            if (substr($line, 0, $indent_len) == $indent) {                $data .= substr($line, $indent_len) . "\n";            }        }        return $data;    }    // Support for package DTD v1.0:    // {{{ _element_start_1_0()    /**     * XML parser callback for ending elements.  Used for version 1.0     * packages.     *     * @param resource  $xp    XML parser resource     * @param string    $name  name of ending element     *     * @return void     *     * @access private     */    function _element_start_1_0($xp, $name, $attribs)    {        array_push($this->element_stack, $name);        $this->current_element = $name;        $spos = sizeof($this->element_stack) - 2;        $this->prev_element = ($spos >= 0) ? $this->element_stack[$spos] : '';        $this->current_attributes = $attribs;        $this->cdata = '';        switch ($name) {            case 'dir':                if ($this->in_changelog) {                    break;                }                if (array_key_exists('name', $attribs) && $attribs['name'] != '/') {                    $attribs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),                        $attribs['name']);                    if (strrpos($attribs['name'], '/') == strlen($attribs['name']) - 1) {                        $attribs['name'] = substr($attribs['name'], 0,                            strlen($attribs['name']) - 1);                    }                    if (strpos($attribs['name'], '/') === 0) {                        $attribs['name'] = substr($attribs['name'], 1);                    }                    $this->dir_names[] = $attribs['name'];                }                if (isset($attribs['baseinstalldir'])) {                    $this->dir_install = $attribs['baseinstalldir'];                }                if (isset($attribs['role'])) {                    $this->dir_role = $attribs['role'];                }                break;            case 'file':                if ($this->in_changelog) {                    break;                }                if (isset($attribs['name'])) {                    $path = '';                    if (count($this->dir_names)) {                        foreach ($this->dir_names as $dir) {                            $path .= $dir . '/';                        }                    }                    $path .= preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),                        $attribs['name']);                    unset($attribs['name']);                    $this->current_path = $path;                    $this->filelist[$path] = $attribs;                    // Set the baseinstalldir only if the file don't have this attrib                    if (!isset($this->filelist[$path]['baseinstalldir']) &&                        isset($this->dir_install))                    {                        $this->filelist[$path]['baseinstalldir'] = $this->dir_install;                    }                    // Set the Role                    if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) {                        $this->filelist[$path]['role'] = $this->dir_role;                    }                }                break;            case 'replace':                if (!$this->in_changelog) {                    $this->filelist[$this->current_path]['replacements'][] = $attribs;                }                break;            case 'maintainers':                $this->_packageInfo['maintainers'] = array();                $this->m_i = 0; // maintainers array index                break;            case 'maintainer':                // compatibility check                if (!isset($this->_packageInfo['maintainers'])) {                    $this->_packageInfo['maintainers'] = array();                    $this->m_i = 0;                }                $this->_packageInfo['maintainers'][$this->m_i] = array();                $this->current_maintainer =& $this->_packageInfo['maintainers'][$this->m_i];                break;

⌨️ 快捷键说明

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