parser.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 566 行 · 第 1/2 页
PHP
566 行
if (!isset($this->index['was'])) { $this->index['was'] = $this->index_name; }; $this->table['INDEXES'][$this->index_name] = $this->index; break; case 'database-table-declaration-index-field': if (!$this->field_name) { $this->raiseError('the index-field-name is required', $xp); }; if (isset($this->field['sorting']) && $this->field['sorting'] !== 'ascending' && $this->field['sorting'] !== 'descending') { $this->raiseError('sorting type unknown', $xp); }; $this->index['FIELDS'][$this->field_name] = $this->field; break; /* Sequence declaration */ case 'database-sequence': if (!$this->seq_name) { $this->raiseError('a sequence has to have a name', $xp); }; if (isset($this->database_definition['SEQUENCES'][$this->seq_name])) { $this->raiseError('sequence "'.$this->seq_name.'" already exists', $xp); }; if (!isset($this->seq['was'])) { $this->seq['was'] = $this->seq_name; }; if (isset($this->seq['on'])) { if ((!isset($this->seq['on']['table']) || !$this->seq['on']['table']) || (!isset($this->seq['on']['field']) || !$this->seq['on']['field'])) { $this->raiseError('sequence "'.$this->seq_name.'" was not properly defined', $xp); }; }; $this->database_definition['SEQUENCES'][$this->seq_name] = $this->seq; break; /* End of File */ case 'database': if (isset($this->database_definition['create']) && !$this->is_boolean($this->database_definition['create'])) { $this->raiseError('field "create" has to be 1 or 0', $xp); }; if (isset($this->database_definition['overwrite']) && !$this->is_boolean($this->database_definition['overwrite'])) { $this->raiseError('field "overwrite" has to be 1 or 0', $xp); }; if (!isset($this->database_definition['name']) || !$this->database_definition['name']) { $this->raiseError('database needs a name', $xp); }; if (isset($this->database_definition['SEQUENCES'])) { foreach($this->database_definition['SEQUENCES'] as $seq_name => $seq) { if (isset($seq['on']) && !isset($this->database_definition['TABLES'][$seq['on']['table']]['FIELDS'][$seq['on']['field']])) { $this->raiseError('sequence "'.$seq_name.'" was assigned on unexisting field/table', $xp); }; }; }; if (MDB::isError($this->error)) { $this->database_definition = $this->error; }; break; } unset($this->elements[--$this->count]); $this->element = implode('-', $this->elements); } function validateFieldValue($field_name, &$field_value, &$xp) { if (!isset($this->table['FIELDS'][$field_name])) { return; }; $field_def = $this->table['FIELDS'][$field_name]; switch($field_def['type']) { case 'text': case 'clob': if (isset($field_def['length']) && strlen($field_value) > $field_def['length']) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); }; break; case 'blob': /* if (!preg_match('/^([0-9a-f]{2})*$/i', $field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); } */ $field_value = pack('H*', $field_value); if (isset($field_def['length']) && strlen($field_value) > $field_def['length']) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); }; break; case 'integer': if ($field_value != ((int)$field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); }; $field_value = (int) $field_value; if (isset($field_def['unsigned']) && $field_def['unsigned'] && $field_value < 0) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); }; break; case 'boolean': if (!$this->is_boolean($field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); } break; case 'date': if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); } break; case 'timestamp': if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); } break; case 'time': if (!preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2})/", $field_value)) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); } break; case 'float': case 'double': if ($field_value != (double) $field_value) { return($this->raiseError('"'.$field_value.'" is not of type "'.$field_def['type'].'"', $xp)); }; $field_value = (double) $field_value; break; } return(TRUE); } function raiseError($msg, $xp = NULL) { if ($this->error === NULL) { if(is_resource($msg)) { $error = "Parser error: "; $xp = $msg; } else { $error = "Parser error: \"".$msg."\"\n"; } if($xp != NULL) { $byte = @xml_get_current_byte_index($xp); $line = @xml_get_current_line_number($xp); $column = @xml_get_current_column_number($xp); $error .= "Byte: $byte; Line: $line; Col: $column\n"; } $this->error = PEAR::raiseError(NULL, MDB_ERROR_MANAGER_PARSE, NULL, NULL, $error, 'MDB_Error', TRUE); }; return(FALSE); } function is_boolean(&$value) { if (is_int($value) && ($value == 0 || $value == 1)) { return(TRUE); }; if ($value === '1' || $value === '0') { $value = (int) $value; return(TRUE); }; switch($value) { case 'N': case 'n': case 'no': case 'FALSE': $value = 0; break; case 'Y': case 'y': case 'yes': case 'TRUE': $value = 1; break; default: return(FALSE); }; return(TRUE); } function cdataHandler($xp, $data) { if ($this->var_mode == TRUE) { if (!isset($this->variables[$data])) { $this->raiseError('variable "'.$data.'" not found', $xp); return; }; $data = $this->variables[$data]; }; switch($this->element) { /* Initialization */ case 'database-table-initialization-insert-field-name': @$this->init_name .= $data; break; case 'database-table-initialization-insert-field-value': @$this->init_value .= $data; break; /* Database */ case 'database-name': @$this->database_definition['name'] .= $data; break; case 'database-create': @$this->database_definition['create'] .= $data; break; case 'database-overwrite': @$this->database_definition['overwrite'] .= $data; break; case 'database-table-name': @$this->table_name .= $data; break; case 'database-table-was': @$this->table['was'] .= $data; break; /* Field declaration */ case 'database-table-declaration-field-name': @$this->field_name .= $data; break; case 'database-table-declaration-field-type': @$this->field['type'] .= $data; break; case 'database-table-declaration-field-was': @$this->field['was'] .= $data; break; case 'database-table-declaration-field-notnull': @$this->field['notnull'] .= $data; break; case 'database-table-declaration-field-unsigned': @$this->field['unsigned'] .= $data; break; case 'database-table-declaration-field-default': @$this->field['default'] .= $data; break; case 'database-table-declaration-field-length': @$this->field['length'] .= $data; break; /* Index declaration */ case 'database-table-declaration-index-name': @$this->index_name .= $data; break; case 'database-table-declaration-index-unique': @$this->index['unique'] .= $data; break; case 'database-table-declaration-index-was': @$this->index['was'] .= $data; break; case 'database-table-declaration-index-field-name': @$this->field_name .= $data; break; case 'database-table-declaration-index-field-sorting': @$this->field['sorting'] .= $data; break; /* Sequence declaration */ case 'database-sequence-name': @$this->seq_name .= $data; break; case 'database-sequence-was': @$this->seq['was'] .= $data; break; case 'database-sequence-start': @$this->seq['start'] .= $data; break; case 'database-sequence-on-table': @$this->seq['on']['table'] .= $data; break; case 'database-sequence-on-field': @$this->seq['on']['field'] .= $data; break; }; }};?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?