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

📄 validate.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * PEAR_Validate * * 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: Validate.php,v 1.1.2.2 2006/05/22 10:19:33 cellog Exp $ * @link       http://pear.php.net/package/PEAR * @since      File available since Release 1.4.0a1 *//**#@+ * Constants for install stage */define('PEAR_VALIDATE_INSTALLING', 1);define('PEAR_VALIDATE_UNINSTALLING', 2); // this is not bit-mapped like the othersdefine('PEAR_VALIDATE_NORMAL', 3);define('PEAR_VALIDATE_DOWNLOADING', 4); // this is not bit-mapped like the othersdefine('PEAR_VALIDATE_PACKAGING', 7);/**#@-*/require_once 'PEAR/Common.php';require_once 'PEAR/Validator/PECL.php';/** * Validation class for package.xml - channel-level advanced validation * @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: @package_version@ * @link       http://pear.php.net/package/PEAR * @since      Class available since Release 1.4.0a1 */class PEAR_Validate{    var $packageregex = _PEAR_COMMON_PACKAGE_NAME_PREG;    /**     * @var PEAR_PackageFile_v1|PEAR_PackageFile_v2     */    var $_packagexml;    /**     * @var int one of the PEAR_VALIDATE_* constants     */    var $_state = PEAR_VALIDATE_NORMAL;    /**     * Format: ('error' => array('field' => name, 'reason' => reason), 'warning' => same)     * @var array     * @access private     */    var $_failures = array('error' => array(), 'warning' => array());    /**     * Override this method to handle validation of normal package names     * @param string     * @return bool     * @access protected     */    function _validPackageName($name)    {        return (bool) preg_match('/^' . $this->packageregex . '$/', $name);    }    /**     * @param string package name to validate     * @param string name of channel-specific validation package     * @final     */    function validPackageName($name, $validatepackagename = false)    {        if ($validatepackagename) {            if (strtolower($name) == strtolower($validatepackagename)) {                return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*$/', $name);            }        }        return $this->_validPackageName($name);    }    /**     * This validates a bundle name, and bundle names must conform     * to the PEAR naming convention, so the method is final and static.     * @param string     * @final     * @static     */    function validGroupName($name)    {        return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name);    }    /**     * Determine whether $state represents a valid stability level     * @param string     * @return bool     * @static     * @final     */    function validState($state)    {        return in_array($state, array('snapshot', 'devel', 'alpha', 'beta', 'stable'));    }    /**     * Get a list of valid stability levels     * @return array     * @static     * @final     */    function getValidStates()    {        return array('snapshot', 'devel', 'alpha', 'beta', 'stable');    }    /**     * Determine whether a version is a properly formatted version number that can be used     * by version_compare     * @param string     * @return bool     * @static     * @final     */    function validVersion($ver)    {        return (bool) preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);    }    /**     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2     */    function setPackageFile(&$pf)    {        $this->_packagexml = &$pf;    }    /**     * @access private     */    function _addFailure($field, $reason)    {        $this->_failures['errors'][] = array('field' => $field, 'reason' => $reason);    }    /**     * @access private     */    function _addWarning($field, $reason)    {        $this->_failures['warnings'][] = array('field' => $field, 'reason' => $reason);    }    function getFailures()    {        $failures = $this->_failures;        $this->_failures = array('warnings' => array(), 'errors' => array());        return $failures;    }    /**     * @param int one of the PEAR_VALIDATE_* constants     */    function validate($state = null)    {        if (!isset($this->_packagexml)) {            return false;        }        if ($state !== null) {            $this->_state = $state;        }        $this->_failures = array('warnings' => array(), 'errors' => array());        $this->validatePackageName();        $this->validateVersion();        $this->validateMaintainers();        $this->validateDate();        $this->validateSummary();        $this->validateDescription();        $this->validateLicense();        $this->validateNotes();        if ($this->_packagexml->getPackagexmlVersion() == '1.0') {            $this->validateState();            $this->validateFilelist();        } elseif ($this->_packagexml->getPackagexmlVersion() == '2.0') {            $this->validateTime();            $this->validateStability();            $this->validateDeps();            $this->validateMainFilelist();            $this->validateReleaseFilelist();            //$this->validateGlobalTasks();            $this->validateChangelog();        }        return !((bool) count($this->_failures['errors']));    }    /**     * @access protected     */    function validatePackageName()    {        if ($this->_state == PEAR_VALIDATE_PACKAGING ||              $this->_state == PEAR_VALIDATE_NORMAL) {            if ($this->_packagexml->getPackagexmlVersion() == '2.0' &&                  $this->_packagexml->getExtends()) {                $version = $this->_packagexml->getVersion() . '';                $name = $this->_packagexml->getPackage();                $test = array_shift($a = explode('.', $version));                if ($test == '0') {                    return true;                }                $vlen = strlen($test);                $majver = substr($name, strlen($name) - $vlen);                while ($majver && !is_numeric($majver{0})) {                    $majver = substr($majver, 1);                }                if ($majver != $test) {                    $this->_addWarning('package', "package $name extends package " .                        $this->_packagexml->getExtends() . ' and so the name should ' .                        'have a postfix equal to the major version like "' .                        $this->_packagexml->getExtends() . $test . '"');                    return true;                } elseif (substr($name, 0, strlen($name) - $vlen) !=                            $this->_packagexml->getExtends()) {                    $this->_addWarning('package', "package $name extends package " .                        $this->_packagexml->getExtends() . ' and so the name must ' .                        'be an extension like "' . $this->_packagexml->getExtends() .                        $test . '"');                    return true;                }            }        }        if (!$this->validPackageName($this->_packagexml->getPackage())) {            $this->_addFailure('name', 'package name "' .                $this->_packagexml->getPackage() . '" is invalid');            return false;        }    }    /**     * @access protected     */    function validateVersion()    {        if ($this->_state != PEAR_VALIDATE_PACKAGING) {            if (!$this->validVersion($this->_packagexml->getVersion())) {                $this->_addFailure('version',                    'Invalid version number "' . $this->_packagexml->getVersion() . '"');            }            return false;        }        $version = $this->_packagexml->getVersion();        $versioncomponents = explode('.', $version);        if (count($versioncomponents) != 3) {            $this->_addWarning('version',                'A version number should have 3 decimals (x.y.z)');            return true;        }        $name = $this->_packagexml->getPackage();        // version must be based upon state        switch ($this->_packagexml->getState()) {            case 'snapshot' :                return true;            case 'devel' :                if ($versioncomponents[0] . 'a' == '0a') {                    return true;                }                if ($versioncomponents[0] == 0) {                    $versioncomponents[0] = '0';                    $this->_addWarning('version',                        'version "' . $version . '" should be "' .                        implode('.' ,$versioncomponents) . '"');                } else {                    $this->_addWarning('version',                        'packages with devel stability must be < version 1.0.0');                }                return true;            break;            case 'alpha' :            case 'beta' :                // check for a package that extends a package,                // like Foo and Foo2                if ($this->_state == PEAR_VALIDATE_PACKAGING) {                    if (substr($versioncomponents[2], 1, 2) == 'rc') {                        $this->_addFailure('version', 'Release Candidate versions ' .                            'must have capital RC, not lower-case rc');                        return false;                    }                }                if (!$this->_packagexml->getExtends()) {                    if ($versioncomponents[0] == '1') {                        if ($versioncomponents[2]{0} == '0') {                            if ($versioncomponents[2] == '0') {                                // version 1.*.0000                                $this->_addWarning('version',                                    'version 1.' . $versioncomponents[1] .                                        '.0 probably should not be alpha or beta');                                return true;                            } elseif (strlen($versioncomponents[2]) > 1) {                                // version 1.*.0RC1 or 1.*.0beta24 etc.                                return true;                            } else {                                // version 1.*.0                                $this->_addWarning('version',                                    'version 1.' . $versioncomponents[1] .                                        '.0 probably should not be alpha or beta');                                return true;                            }                        } else {                            $this->_addWarning('version',

⌨️ 快捷键说明

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