Example #1
0
 /**
  * Check if the XML respect the DTD.
  * Require the XML_DTD package
  *
  * @param string $xml   The XML text to check
  *
  * @return boolean      Return true if valid
  * @access public
  */
 function isValid(&$xml)
 {
     $validator = new XML_DTD_XmlValidator();
     $tree = new XML_Tree();
     $nodes = $tree->getTreeFromString($xml);
     if (PEAR::isError($nodes)) {
         return $nodes;
     }
     $parser =& new XML_DTD_Parser();
     $validator->dtd = $parser->parse($this->_dtd);
     $validator->_runTree($nodes);
     if ($validator->_errors) {
         $errors = $validator->getMessage();
         return PEAR::raiseError($errors, XML_FASTCREATE_ERROR_DTD);
     }
     return true;
 }
Example #2
0
 /**
  * Parse a database definition file by creating a schema format
  * parser object and passing the file contents as parser input data stream.
  *
  * @param string $input_file            the database schema file.
  * @param array  $variables             associative array that the defines the text string values
  *                                      that are meant to be used to replace the variables that are
  *                                      used in the schema description.
  * @param bool   $fail_on_invalid_names make function fail on invalid names
  * @param array  $structure             database structure definition
  *
  * @access public
  * @return array
  */
 function parseDatabaseDefinitionFile($input_file, $variables = array(), $fail_on_invalid_names = true, $structure = false)
 {
     $dtd_file = $this->options['dtd_file'];
     if ($dtd_file) {
         include_once 'XML/DTD/XmlValidator.php';
         $dtd = new XML_DTD_XmlValidator();
         if (!$dtd->isValid($dtd_file, $input_file)) {
             return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
         }
     }
     $class_name = $this->options['parser'];
     $result = MDB2::loadClass($class_name, $this->db->getOption('debug'));
     if (PEAR::isError($result)) {
         return $result;
     }
     $max_identifiers_length = null;
     if (isset($this->db->options['max_identifiers_length'])) {
         $max_identifiers_length = $this->db->options['max_identifiers_length'];
     }
     $parser = new $class_name($variables, $fail_on_invalid_names, $structure, $this->options['valid_types'], $this->options['force_defaults'], $max_identifiers_length);
     $result = $parser->setInputFile($input_file);
     if (PEAR::isError($result)) {
         return $result;
     }
     $result = $parser->parse();
     if (PEAR::isError($result)) {
         return $result;
     }
     if (PEAR::isError($parser->error)) {
         return $parser->error;
     }
     return $parser->database_definition;
 }
Example #3
0
 /**
  * Parse a changeset definition file by creating a schema
  * parser object and passing the file contents as parser input data stream.
  *
  * @param string the changeset schema file.
  * @param array associative array that the defines the text string values
  *              that are meant to be used to replace the variables that are
  *              used in the schema description.
  * @param bool make function fail on invalid names
  * @param array database structure definition
  * @access public
  */
 function parseDictionaryDefinitionFile($input_file, $variables = array(), $fail_on_invalid_names = true, $structure = false)
 {
     $dtd_file = $this->options['dtd_file'];
     if ($dtd_file) {
         require_once 'XML/DTD/XmlValidator.php';
         $dtd = new XML_DTD_XmlValidator();
         if (!$dtd->isValid($dtd_file, $input_file)) {
             return $this->customRaiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
         }
     }
     require_once "MDB2/Schema/ParserDictionary.php";
     $class_name = 'MDB2_Dictionary_Parser';
     $result = MDB2::loadClass($class_name, $this->db->getOption('debug'));
     if (PEAR::isError($result)) {
         return $result;
     }
     $parser = new $class_name($variables, $fail_on_invalid_names, $structure, $this->options['valid_types'], $this->options['force_defaults']);
     $class_name = 'MDB2_Schema_Validate';
     $parser->val = new $class_name($fail_on_invalid_names, $this->options['valid_types'], $this->options['force_defaults']);
     $result = $parser->setInputFile($input_file);
     if (PEAR::isError($result)) {
         return $result;
     }
     $result = $parser->parse();
     if (PEAR::isError($result)) {
         return $result;
     }
     if (PEAR::isError($parser->error)) {
         return $parser->error;
     }
     $dictionary = $parser->dictionary_definition;
     return $dictionary;
 }