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

📄 v1.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 4 页
字号:
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());                return $this->_isValid = 0;            }            $validator = $chan->getValidationObject();            $validator->setPackageFile($this);            $validator->validate($state);            $failures = $validator->getFailures();            foreach ($failures['errors'] as $error) {                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $error);            }            foreach ($failures['warnings'] as $warning) {                $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $warning);            }        }        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {            if ($this->_analyzePhpFiles()) {                $this->_isValid = true;            }        }        if ($this->_isValid) {            return $this->_isValid = $state;        }        return $this->_isValid = 0;    }    function _analyzePhpFiles()    {        if (!$this->_isValid) {            return false;        }        if (!isset($this->_packageFile)) {            return false;        }        $dir_prefix = dirname($this->_packageFile);        $common = new PEAR_Common;        $log = isset($this->_logger) ? array(&$this->_logger, 'log') :            array($common, 'log');        $info = $this->getFilelist();        foreach ($info as $file => $fa) {            if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {                $this->_validateError(PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND,                    array('file' => realpath($dir_prefix) . DIRECTORY_SEPARATOR . $file));                continue;            }            if ($fa['role'] == 'php' && $dir_prefix) {                call_user_func_array($log, array(1, "Analyzing $file"));                $srcinfo = $this->_analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);                if ($srcinfo) {                    $this->_buildProvidesArray($srcinfo);                }            }        }        $this->_packageName = $pn = $this->getPackage();        $pnl = strlen($pn);        if (isset($this->_packageInfo['provides'])) {            foreach ((array) $this->_packageInfo['provides'] as $key => $what) {                if (isset($what['explicit'])) {                    // skip conformance checks if the provides entry is                    // specified in the package.xml file                    continue;                }                extract($what);                if ($type == 'class') {                    if (!strncasecmp($name, $pn, $pnl)) {                        continue;                    }                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));                } elseif ($type == 'function') {                    if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {                        continue;                    }                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));                }            }        }        return $this->_isValid;    }    /**     * Get the default xml generator object     *     * @return PEAR_PackageFile_Generator_v1     */    function &getDefaultGenerator()    {        if (!class_exists('PEAR_PackageFile_Generator_v1')) {            require_once 'PEAR/PackageFile/Generator/v1.php';        }        $a = &new PEAR_PackageFile_Generator_v1($this);        return $a;    }    /**     * Get the contents of a file listed within the package.xml     * @param string     * @return string     */    function getFileContents($file)    {        if ($this->_archiveFile == $this->_packageFile) { // unpacked            $dir = dirname($this->_packageFile);            $file = $dir . DIRECTORY_SEPARATOR . $file;            $file = str_replace(array('/', '\\'),                array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);            if (file_exists($file) && is_readable($file)) {                return implode('', file($file));            }        } else { // tgz            if (!class_exists('Archive_Tar')) {                require_once 'Archive/Tar.php';            }            $tar = &new Archive_Tar($this->_archiveFile);            $tar->pushErrorHandling(PEAR_ERROR_RETURN);            if ($file != 'package.xml' && $file != 'package2.xml') {                $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;            }            $file = $tar->extractInString($file);            $tar->popErrorHandling();            if (PEAR::isError($file)) {                return PEAR::raiseError("Cannot locate file '$file' in archive");            }            return $file;        }    }    // {{{ analyzeSourceCode()    /**     * Analyze the source code of the given PHP file     *     * @param  string Filename of the PHP file     * @return mixed     * @access private     */    function _analyzeSourceCode($file)    {        if (!function_exists("token_get_all")) {            return false;        }        if (!defined('T_DOC_COMMENT')) {            define('T_DOC_COMMENT', T_COMMENT);        }        if (!defined('T_INTERFACE')) {            define('T_INTERFACE', -1);        }        if (!defined('T_IMPLEMENTS')) {            define('T_IMPLEMENTS', -1);        }        if (!$fp = @fopen($file, "r")) {            return false;        }        if (function_exists('file_get_contents')) {            fclose($fp);            $contents = file_get_contents($file);        } else {            $contents = @fread($fp, filesize($file));            fclose($fp);        }        $tokens = token_get_all($contents);/*        for ($i = 0; $i < sizeof($tokens); $i++) {            @list($token, $data) = $tokens[$i];            if (is_string($token)) {                var_dump($token);            } else {                print token_name($token) . ' ';                var_dump(rtrim($data));            }        }*/        $look_for = 0;        $paren_level = 0;        $bracket_level = 0;        $brace_level = 0;        $lastphpdoc = '';        $current_class = '';        $current_interface = '';        $current_class_level = -1;        $current_function = '';        $current_function_level = -1;        $declared_classes = array();        $declared_interfaces = array();        $declared_functions = array();        $declared_methods = array();        $used_classes = array();        $used_functions = array();        $extends = array();        $implements = array();        $nodeps = array();        $inquote = false;        $interface = false;        for ($i = 0; $i < sizeof($tokens); $i++) {            if (is_array($tokens[$i])) {                list($token, $data) = $tokens[$i];            } else {                $token = $tokens[$i];                $data = '';            }            if ($inquote) {                if ($token != '"' && $token != T_END_HEREDOC) {                    continue;                } else {                    $inquote = false;                    continue;                }            }            switch ($token) {                case T_WHITESPACE :                    continue;                case ';':                    if ($interface) {                        $current_function = '';                        $current_function_level = -1;                    }                    break;                case '"':                case T_START_HEREDOC:                    $inquote = true;                    break;                case T_CURLY_OPEN:                case T_DOLLAR_OPEN_CURLY_BRACES:                case '{': $brace_level++; continue 2;                case '}':                    $brace_level--;                    if ($current_class_level == $brace_level) {                        $current_class = '';                        $current_class_level = -1;                    }                    if ($current_function_level == $brace_level) {                        $current_function = '';                        $current_function_level = -1;                    }                    continue 2;                case '[': $bracket_level++; continue 2;                case ']': $bracket_level--; continue 2;                case '(': $paren_level++;   continue 2;                case ')': $paren_level--;   continue 2;                case T_INTERFACE:                    $interface = true;                case T_CLASS:                    if (($current_class_level != -1) || ($current_function_level != -1)) {                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,                            array('file' => $file));                        return false;                    }                case T_FUNCTION:                case T_NEW:                case T_EXTENDS:                case T_IMPLEMENTS:                    $look_for = $token;                    continue 2;                case T_STRING:                    if (version_compare(zend_version(), '2.0', '<')) {                        if (in_array(strtolower($data),                            array('public', 'private', 'protected', 'abstract',                                  'interface', 'implements', 'throw')                                  )) {                            $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_PHP5,                                array($file));                        }                    }                    if ($look_for == T_CLASS) {                        $current_class = $data;                        $current_class_level = $brace_level;                        $declared_classes[] = $current_class;                    } elseif ($look_for == T_INTERFACE) {                        $current_interface = $data;                        $current_class_level = $brace_level;                        $declared_interfaces[] = $current_interface;                    } elseif ($look_for == T_IMPLEMENTS) {                        $implements[$current_class] = $data;                    } elseif ($look_for == T_EXTENDS) {                        $extends[$current_class] = $data;                    } elseif ($look_for == T_FUNCTION) {                        if ($current_class) {                            $current_function = "$current_class::$data";                            $declared_methods[$current_class][] = $data;                        } elseif ($current_interface) {                            $current_function = "$current_interface::$data";                            $declared_methods[$current_interface][] = $data;                        } else {                            $current_function = $data;                            $declared_functions[] = $current_function;                        }                        $current_function_level = $brace_level;                        $m = array();                    } elseif ($look_for == T_NEW) {                        $used_classes[$data] = true;                    }                    $look_for = 0;                    continue 2;                case T_VARIABLE:                    $look_for = 0;                    continue 2;                case T_DOC_COMMENT:                case T_COMMENT:                    if (preg_match('!^/\*\*\s!', $data)) {                        $lastphpdoc = $data;                        if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {                            $nodeps = array_merge($nodeps, $m[1]);                        }                    }                    continue 2;                case T_DOUBLE_COLON:                    if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,                            array('file' => $file));                        return false;                    }                    $class = $tokens[$i - 1][1];                    if (strtolower($class) != 'parent') {                        $used_classes[$class] = true;                    }                    continue 2;            }        }        return array(            "source_file" => $file,            "declared_classes" => $declared_classes,            "declared_interfaces" => $declared_interfaces,            "declared_methods" => $declared_methods,            "declared_functions" => $declared_functions,            "used_classes" => array_diff(array_keys($used_classes), $nodeps),            "inheritance" => $extends,            "implements" => $implements,            );    }    /**     * Build a "provides" array from data returned by     * analyzeSourceCode().  The format of the built array is like     * this:     *     *  array(     *    'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),     *    ...     *  )     *     *     * @param array $srcinfo array with information about a source file     * as returned by the analyzeSourceCode() method.     *     * @return void     *     * @access private     *     */    function _buildProvidesArray($srcinfo)    {        if (!$this->_isValid) {            return false;        }        $file = basename($srcinfo['source_file']);        $pn = $this->getPackage();        $pnl = strlen($pn);        foreach ($srcinfo['declared_classes'] as $class) {            $key = "class;$class";            if (isset($this->_packageInfo['provides'][$key])) {                continue;            }            $this->_packageInfo['provides'][$key] =                array('file'=> $file, 'type' => 'class', 'name' => $class);            if (isset($srcinfo['inheritance'][$class])) {                $this->_packageInfo['provides'][$key]['extends'] =                    $srcinfo['inheritance'][$class];            }        }        foreach ($srcinfo['declared_methods'] as $class => $methods) {            foreach ($methods as $method) {                $function = "$class::$method";                $key = "function;$function";                if ($method{0} == '_' || !strcasecmp($method, $class) ||                    isset($this->_packageInfo['provides'][$key])) {                    continue;                }                $this->_packageInfo['provides'][$key] =                    array('file'=> $file, 'type' => 'function', 'name' => $function);            }        }        foreach ($srcinfo['declared_functions'] as $function) {            $key = "function;$function";            if ($function{0} == '_' || isset($this->_packageInfo['provides'][$key])) {                continue;            }            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";            }            $this->_packageInfo['provides'][$key] =                array('file'=> $file, 'type' => 'function', 'name' => $function);        }    }    // }}}}?>

⌨️ 快捷键说明

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