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

📄 validator.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php//// +----------------------------------------------------------------------+// | PHP Version 5                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2006 The PHP Group                                |// +----------------------------------------------------------------------+// | This source file is subject to version 3.01 of the PHP license,      |// | that is bundled with this package in the file LICENSE, and is        |// | available through the world-wide-web at the following url:           |// | 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 world-wide-web, please send a note to          |// | license@php.net so we can mail you a copy immediately.               |// +----------------------------------------------------------------------+// | Author: Greg Beaver <cellog@php.net>                                 |// |                                                                      |// +----------------------------------------------------------------------+//// $Id: Validator.php,v 1.1.2.5 2006/05/22 11:17:02 cellog Exp $/** * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller * @author Greg Beaver <cellog@php.net> * @access private */class PEAR_PackageFile_v2_Validator{    /**     * @var array     */    var $_packageInfo;    /**     * @var PEAR_PackageFile_v2     */    var $_pf;    /**     * @var PEAR_ErrorStack     */    var $_stack;    /**     * @var int     */    var $_isValid = 0;    /**     * @var int     */    var $_filesValid = 0;    /**     * @var int     */    var $_curState = 0;    /**     * @param PEAR_PackageFile_v2     * @param int     */    function validate(&$pf, $state = PEAR_VALIDATE_NORMAL)    {        $this->_pf = &$pf;        $this->_curState = $state;        $this->_packageInfo = $this->_pf->getArray();        $this->_isValid = $this->_pf->_isValid;        $this->_filesValid = $this->_pf->_filesValid;        $this->_stack = &$pf->_stack;        $this->_stack->getErrors(true);        if (($this->_isValid & $state) == $state) {            return true;        }        if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {            return false;        }        if (!isset($this->_packageInfo['attribs']['version']) ||              $this->_packageInfo['attribs']['version'] != '2.0') {            $this->_noPackageVersion();        }        $structure =        array(            'name',            'channel|uri',            '*extends', // can't be multiple, but this works fine            'summary',            'description',            '+lead', // these all need content checks            '*developer',            '*contributor',            '*helper',            'date',            '*time',            'version',            'stability',            'license->?uri->?filesource',            'notes',            'contents', //special validation needed            '*compatible',            'dependencies', //special validation needed            '*usesrole',            '*usestask', // reserve these for 1.4.0a1 to implement                         // this will allow a package.xml to gracefully say it                         // needs a certain package installed in order to implement a role or task            '*providesextension',            '*srcpackage|*srcuri',            '+phprelease|+extsrcrelease|+extbinrelease|bundle', //special validation needed            '*changelog',        );        $test = $this->_packageInfo;        if (isset($test['dependencies']) &&              isset($test['dependencies']['required']) &&              isset($test['dependencies']['required']['pearinstaller']) &&              isset($test['dependencies']['required']['pearinstaller']['min']) &&              version_compare('1.4.9',                $test['dependencies']['required']['pearinstaller']['min'], '<')) {            $this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);            return false;        }        // ignore post-installation array fields        if (array_key_exists('filelist', $test)) {            unset($test['filelist']);        }        if (array_key_exists('_lastmodified', $test)) {            unset($test['_lastmodified']);        }        if (array_key_exists('#binarypackage', $test)) {            unset($test['#binarypackage']);        }        if (array_key_exists('old', $test)) {            unset($test['old']);        }        if (array_key_exists('_lastversion', $test)) {            unset($test['_lastversion']);        }        if (!$this->_stupidSchemaValidate($structure,                                          $test, '<package>')) {            return false;        }        if (empty($this->_packageInfo['name'])) {            $this->_tagCannotBeEmpty('name');        }        if (isset($this->_packageInfo['uri'])) {            $test = 'uri';        } else {            $test = 'channel';        }        if (empty($this->_packageInfo[$test])) {            $this->_tagCannotBeEmpty($test);        }        if (is_array($this->_packageInfo['license']) &&              (!isset($this->_packageInfo['license']['_content']) ||              empty($this->_packageInfo['license']['_content']))) {            $this->_tagCannotBeEmpty('license');        } elseif (empty($this->_packageInfo['license'])) {            $this->_tagCannotBeEmpty('license');        }        if (empty($this->_packageInfo['summary'])) {            $this->_tagCannotBeEmpty('summary');        }        if (empty($this->_packageInfo['description'])) {            $this->_tagCannotBeEmpty('description');        }        if (empty($this->_packageInfo['date'])) {            $this->_tagCannotBeEmpty('date');        }        if (empty($this->_packageInfo['notes'])) {            $this->_tagCannotBeEmpty('notes');        }        if (isset($this->_packageInfo['time']) && empty($this->_packageInfo['time'])) {            $this->_tagCannotBeEmpty('time');        }        if (isset($this->_packageInfo['dependencies'])) {            $this->_validateDependencies();        }        if (isset($this->_packageInfo['compatible'])) {            $this->_validateCompatible();        }        if (!isset($this->_packageInfo['bundle'])) {            if (!isset($this->_packageInfo['contents']['dir'])) {                $this->_filelistMustContainDir('contents');                return false;            }            if (isset($this->_packageInfo['contents']['file'])) {                $this->_filelistCannotContainFile('contents');                return false;            }        }        $this->_validateMaintainers();        $this->_validateStabilityVersion();        $fail = false;        if (array_key_exists('usesrole', $this->_packageInfo)) {            $roles = $this->_packageInfo['usesrole'];            if (!is_array($roles) || !isset($roles[0])) {                $roles = array($roles);            }            foreach ($roles as $role) {                if (!isset($role['role'])) {                    $this->_usesroletaskMustHaveRoleTask('usesrole', 'role');                    $fail = true;                } else {                    if (!isset($role['channel'])) {                        if (!isset($role['uri'])) {                            $this->_usesroletaskMustHaveChannelOrUri($role['role'], 'usesrole');                            $fail = true;                        }                    } elseif (!isset($role['package'])) {                        $this->_usesroletaskMustHavePackage($role['role'], 'usesrole');                        $fail = true;                    }                }            }        }        if (array_key_exists('usestask', $this->_packageInfo)) {            $roles = $this->_packageInfo['usestask'];            if (!is_array($roles) || !isset($roles[0])) {                $roles = array($roles);            }            foreach ($roles as $role) {                if (!isset($role['task'])) {                    $this->_usesroletaskMustHaveRoleTask('usestask', 'task');                    $fail = true;                } else {                    if (!isset($role['channel'])) {                        if (!isset($role['uri'])) {                            $this->_usesroletaskMustHaveChannelOrUri($role['task'], 'usestask');                            $fail = true;                        }                    } elseif (!isset($role['package'])) {                        $this->_usesroletaskMustHavePackage($role['task'], 'usestask');                        $fail = true;                    }                }            }        }        if ($fail) {            return false;        }        $this->_validateFilelist();        $this->_validateRelease();        if (!$this->_stack->hasErrors()) {            $chan = $this->_pf->_registry->getChannel($this->_pf->getChannel(), true);            if (PEAR::isError($chan)) {                $this->_unknownChannel($this->_pf->getChannel());            } else {                $valpack = $chan->getValidationPackage();                // for channel validator packages, always use the default PEAR validator.                // otherwise, they can't be installed or packaged                $validator = $chan->getValidationObject($this->_pf->getPackage());                if (!$validator) {                    $this->_stack->push(__FUNCTION__, 'error',                        array_merge(                            array('channel' => $chan->getName(),                                  'package' => $this->_pf->getPackage()),                              $valpack                            ),                        'package "%channel%/%package%" cannot be properly validated without ' .                        'validation package "%channel%/%name%-%version%"');                    return $this->_isValid = 0;                }                $validator->setPackageFile($this->_pf);                $validator->validate($state);                $failures = $validator->getFailures();                foreach ($failures['errors'] as $error) {                    $this->_stack->push(__FUNCTION__, 'error', $error,                        'Channel validator error: field "%field%" - %reason%');                }                foreach ($failures['warnings'] as $warning) {                    $this->_stack->push(__FUNCTION__, 'warning', $warning,                        'Channel validator warning: field "%field%" - %reason%');                }            }        }        $this->_pf->_isValid = $this->_isValid = !$this->_stack->hasErrors('error');        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid) {            if ($this->_pf->getPackageType() == 'bundle') {                if ($this->_analyzeBundledPackages()) {                    $this->_filesValid = $this->_pf->_filesValid = true;                } else {                    $this->_pf->_isValid = $this->_isValid = 0;                }            } else {                if (!$this->_analyzePhpFiles()) {                    $this->_pf->_isValid = $this->_isValid = 0;                } else {                    $this->_filesValid = $this->_pf->_filesValid = true;                }            }        }        if ($this->_isValid) {            return $this->_pf->_isValid = $this->_isValid = $state;        }        return $this->_pf->_isValid = $this->_isValid = 0;    }    function _stupidSchemaValidate($structure, $xml, $root)    {        if (!is_array($xml)) {            $xml = array();        }        $keys = array_keys($xml);        reset($keys);        $key = current($keys);        while ($key == 'attribs' || $key == '_contents') {            $key = next($keys);        }        $unfoundtags = $optionaltags = array();        $ret = true;        $mismatch = false;        foreach ($structure as $struc) {            if ($key) {                $tag = $xml[$key];            }            $test = $this->_processStructure($struc);            if (isset($test['choices'])) {                $loose = true;                foreach ($test['choices'] as $choice) {                    if ($key == $choice['tag']) {                        $key = next($keys);                        while ($key == 'attribs' || $key == '_contents') {                            $key = next($keys);                        }                        $unfoundtags = $optionaltags = array();                        $mismatch = false;                        if ($key && $key != $choice['tag'] && isset($choice['multiple'])) {                            $unfoundtags[] = $choice['tag'];                            $optionaltags[] = $choice['tag'];                            if ($key) {                                $mismatch = true;                            }                        }                        $ret &= $this->_processAttribs($choice, $tag, $root);

⌨️ 快捷键说明

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