parser.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 566 行 · 第 1/2 页
PHP
566 行
<?php// +----------------------------------------------------------------------+// | PHP Version 4 |// +----------------------------------------------------------------------+// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |// | Stig. S. Bakken, Lukas Smith |// | All rights reserved. |// +----------------------------------------------------------------------+// | MDB is a merge of PEAR DB and Metabases that provides a unified DB |// | API as well as database abstraction for PHP applications. |// | This LICENSE is in the BSD license style. |// | |// | Redistribution and use in source and binary forms, with or without |// | modification, are permitted provided that the following conditions |// | are met: |// | |// | Redistributions of source code must retain the above copyright |// | notice, this list of conditions and the following disclaimer. |// | |// | Redistributions in binary form must reproduce the above copyright |// | notice, this list of conditions and the following disclaimer in the |// | documentation and/or other materials provided with the distribution. |// | |// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |// | Lukas Smith nor the names of his contributors may be used to endorse |// | or promote products derived from this software without specific prior|// | written permission. |// | |// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |// | POSSIBILITY OF SUCH DAMAGE. |// +----------------------------------------------------------------------+// | Author: Christian Dickmann <dickmann@php.net> |// +----------------------------------------------------------------------+//// $Id: Parser.php,v 1.30.4.1 2004/01/08 13:43:02 lsmith Exp $//require_once('XML/Parser.php');/** * Parses an XML schema file * * @package MDB * @category Database * @access private * @author Christian Dickmann <dickmann@php.net> */class MDB_Parser extends XML_Parser{ var $database_definition = array(); var $elements = array(); var $element = ''; var $count = 0; var $table = array(); var $table_name = ''; var $field = array(); var $field_name = ''; var $init = array(); var $init_name = ''; var $init_value = ''; var $index = array(); var $index_name = ''; var $var_mode = FALSE; var $variables = array(); var $seq = array(); var $seq_name = ''; var $error = NULL; var $invalid_names = array( 'user' => array(), 'is' => array(), 'file' => array( 'oci' => array(), 'oracle' => array() ), 'notify' => array( 'pgsql' => array() ), 'restrict' => array( 'mysql' => array() ), 'password' => array( 'ibase' => array() ) ); var $fail_on_invalid_names = 1; function MDB_Parser($variables, $fail_on_invalid_names = 1) { $this->XML_Parser(); $this->variables = $variables; $this->fail_on_invalid_names = $fail_on_invalid_names; } function startHandler($xp, $element, $attribs) { if (strtolower($element) == 'variable') { $this->var_mode = TRUE; return; }; $this->elements[$this->count++] = strtolower($element); $this->element = implode('-', $this->elements); switch($this->element) { case 'database-table-initialization-insert': $this->init = array('type' => 'insert'); break; case 'database-table-initialization-insert-field': $this->init_name = ''; $this->init_value = ''; break; case 'database-table': $this->table_name = ''; $this->table = array(); break; case 'database-table-declaration-field': $this->field_name = ''; $this->field = array(); break; case 'database-table-declaration-field-default': $this->field['default'] = ''; break; case 'database-table-declaration-index': $this->index_name = ''; $this->index = array(); break; case 'database-sequence': $this->seq_name = ''; $this->seq = array(); break; case 'database-table-declaration-index-field': $this->field_name = ''; $this->field = array(); break; }; } function endHandler($xp, $element) { if (strtolower($element) == 'variable') { $this->var_mode = FALSE; return; }; switch($this->element) { /* Initialization */ case 'database-table-initialization-insert-field': if (!$this->init_name) { $this->raiseError('field-name has to be specified', $xp); }; if (isset($this->init['FIELDS'][$this->init_name])) { $this->raiseError('field "'.$this->init_name.'" already filled', $xp); }; if (!isset($this->table['FIELDS'][$this->init_name])) { $this->raiseError('unkown field "'.$this->init_name.'"', $xp); }; if ($this->init_value !== '' && !$this->validateFieldValue($this->init_name, $this->init_value, $xp)) { $this->raiseError('field "'.$this->init_name.'" has wrong value', $xp); }; $this->init['FIELDS'][$this->init_name] = $this->init_value; break; case 'database-table-initialization-insert': $this->table['initialization'][] = $this->init; break; /* Table definition */ case 'database-table': if (!isset($this->table['was'])) { $this->table['was'] = $this->table_name; }; if (!$this->table_name) { $this->raiseError('tables need names', $xp); }; if (isset($this->database_definition['TABLES'][$this->table_name])) { $this->raiseError('table "'.$this->table_name.'" already exists', $xp); }; if (!isset($this->table['FIELDS'])) { $this->raiseError('tables need one or more fields', $xp); }; if (isset($this->table['INDEXES'])) { foreach($this->table['INDEXES'] as $index_name => $index) { foreach($index['FIELDS'] as $field_name => $field) { if (!isset($this->table['FIELDS'][$field_name])) { $this->raiseError('index field "'.$field_name.'" does not exist', $xp); } if (!(isset($this->table['FIELDS'][$field_name]['notnull']) && $this->table['FIELDS'][$field_name]['notnull'] == 1)) { $this->raiseError('index field "'.$field_name.'" has to be "notnull"', $xp); } } } }; $this->database_definition['TABLES'][$this->table_name] = $this->table; break; /* Field declaration */ case 'database-table-declaration-field': if (!$this->field_name || !isset($this->field['type'])) { $this->raiseError('field "'.$this->field_name.'" was not properly specified', $xp); }; if (isset($this->table['FIELDS'][$this->field_name])) { $this->raiseError('field "'.$this->field_name.'" already exists', $xp); }; /* Invalidname check */ if ($this->fail_on_invalid_names && isset($this->invalid_names[$this->field_name])) { $this->raiseError('fieldname "'.$this->field_name.'" not allowed', $xp); }; /* Type check */ switch($this->field['type']) { case 'integer': if (isset($this->field['unsigned']) && $this->field['unsigned'] !== '1' && $this->field['unsigned'] !== '0') { $this->raiseError('unsigned has to be 1 or 0', $xp); }; break; case 'text': case 'clob': case 'blob': if (isset($this->field['length']) && ((int)$this->field['length']) <= 0) { $this->raiseError('length has to be an integer greater 0', $xp); }; break; case 'boolean': case 'date': case 'timestamp': case 'time': case 'float': case 'decimal': break; default: $this->raiseError('no valid field type ("'.$this->field['type'].'") specified', $xp); }; if (!isset($this->field['was'])) { $this->field['was'] = $this->field_name; }; if (isset($this->field['notnull']) && !$this->is_boolean($this->field['notnull'])) { $this->raiseError('field "notnull" has to be 1 or 0', $xp); }; if (isset($this->field['notnull']) && !isset($this->field['default'])) { $this->raiseError('if field is "notnull", it needs a default value', $xp); }; if (isset($this->field['unsigned']) && !$this->is_boolean($this->field['unsigned'])) { $this->raiseError('field "notnull" has to be 1 or 0', $xp); }; $this->table['FIELDS'][$this->field_name] = $this->field; if (isset($this->field['default'])) { if ($this->field['type'] == 'clob' || $this->field['type'] == 'blob') { $this->raiseError('"'.$this->field['type'].'"-fields are not allowed to have a default value', $xp); }; if ($this->field['default'] !== '' && !$this->validateFieldValue($this->field_name, $this->field['default'], $xp)) { $this->raiseError('default value of "'.$this->field_name.'" is of wrong type', $xp); }; }; break; /* Index declaration */ case 'database-table-declaration-index': if (!$this->index_name) { $this->raiseError('an index needs a name', $xp); }; if (isset($this->table['INDEXES'][$this->index_name])) { $this->raiseError('index "'.$this->index_name.'" already exists', $xp); }; if (isset($this->index['unique']) && !$this->is_boolean($this->index['unique'])) { $this->raiseError('field "unique" has to be 1 or 0', $xp); };
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?