Example #1
0
 /**
  * Check if an xml code satisfy the schema.
  *
  * @param string $xml The xml code to verify
  * @param string $filename The name of the file from which the xml code has been read from
  *
  * @return string[]|null Return null of all is ok, a list of errors otherwise
  */
 public static function checkString($xml, $filename = '')
 {
     $doc = Utilities::stringToDOMDocument($xml, $filename);
     $errors = null;
     $preUseInternalErrors = libxml_use_internal_errors(true);
     try {
         if (!$doc->schemaValidateSource(static::getSchema())) {
             $errors = Utilities::explainLibXmlErrors($filename);
         }
     } catch (Exception $x) {
         libxml_use_internal_errors($preUseInternalErrors);
         libxml_clear_errors();
         throw $x;
     }
     libxml_use_internal_errors($preUseInternalErrors);
     return $errors;
 }
Example #2
0
 /**
  * @param string|SimpleXMLElement $xml
  * @param AbstractPlatform $platform
  * @param bool $checkXml
  * @param bool $normalizeXml
  * @param callable|null $tableFilter
  *
  * @throws Exception
  *
  * @return Schema
  */
 public static function fromDocument($xml, AbstractPlatform $platform, $checkXml = true, $normalizeXml = false, $tableFilter = null)
 {
     if ($checkXml || $normalizeXml) {
         if (is_a($xml, '\\SimpleXMLElement')) {
             $xml = $xml->asXML();
         }
         if ($normalizeXml) {
             $xml = Normalizer::normalizeString($xml);
         }
         if ($checkXml) {
             $errors = Checker::checkString($xml);
             if (isset($errors)) {
                 throw new Exception(implode("\n", $errors));
             }
         }
     }
     if (is_a($xml, '\\SimpleXMLElement')) {
         $xDoc = $xml;
     } else {
         $preUseInternalErrors = libxml_use_internal_errors(true);
         libxml_clear_errors();
         $xDoc = @simplexml_load_string($xml);
         if (!is_object($xDoc)) {
             $errors = Utilities::explainLibXmlErrors();
             libxml_clear_errors();
             libxml_use_internal_errors($preUseInternalErrors);
             throw new Exception(implode("\n", $errors));
         }
         libxml_use_internal_errors($preUseInternalErrors);
     }
     $schema = new Schema();
     foreach ($xDoc->table as $xTable) {
         if (isset($tableFilter) && $tableFilter((string) $xTable['name']) === false) {
             continue;
         }
         static::parseTable($schema, $xTable, $platform);
     }
     return $schema;
 }
Example #3
0
 /**
  * Return the XSLT document that fixes a source xml file.
  *
  * @throws Exception Throws an Exception if the xsd file couldn't be read.
  *
  * @return DOMDocument
  */
 protected static function getXsltDOMDocument()
 {
     static $cache = null;
     $xsltFile = __DIR__ . '/doctrine-xml-0.5.xsl';
     if (!isset($cache)) {
         $s = is_file($xsltFile) && is_readable($xsltFile) ? @file_get_contents($xsltFile) : false;
         if ($s === false) {
             throw new Exception('Failed to load the xslt file ' . $xsltFile);
         }
         $cache = $s;
     }
     return Utilities::stringToDOMDocument($cache, $xsltFile);
 }