Jelajahi Sumber

handle AntAcl xsd extension without childrens in local namespace

Piotr Labudda 7 tahun lalu
induk
melakukan
1988e9c09f
1 mengubah file dengan 38 tambahan dan 0 penghapusan
  1. 38 0
      SE/se-lib/XML.php

+ 38 - 0
SE/se-lib/XML.php

@@ -90,6 +90,16 @@ class XML {
 		}
 	}
 
+	public static function findComplexTypeNode($docArray, $name) {
+		foreach ($docArray[2] as $child) {
+			if ('complexType' === self::getTagName($child[0])) {
+				if ($name === $child[1]['name']) {
+					return $child;
+				}
+			}
+		}
+	}
+
 	public static function findTargetNamespacePrefix($docArray) {
 		$tns = self::findTargetNamespace($docArray);
 		if (!$tns) throw new Exception("targetNamespace not defined");
@@ -390,6 +400,34 @@ class XML {
 	}
 	public static function findFieldsFromExtension($docArray, $nodeArray) {
 		$fields = [];
+
+		if (empty($nodeArray[2])) { // empty extension tag - no childrens
+			// [0] => xs:extension
+			// [1] => Array:
+			//     [base] => default_db__x3A__NEURO_MATRIX:Pain2
+			// [2] => Array: <-- empty!
+			if (empty($nodeArray[1]['base'])) throw new Exception("Error Parsing Schema - missing base attribute when empty extension");
+			list($prefix, $name) = explode(':', $nodeArray[1]['base']);
+			if ($prefix !== XML::findTargetNamespacePrefix($docArray)) throw new Exception("Error Parsing Schema - extension base not in local namespace");
+			$foundComplexTypeNode = XML::findComplexTypeNode($docArray, $name);
+			if (!$foundComplexTypeNode) throw new Exception("Error Parsing Schema - cannot find extension base in local namespace");
+			switch ($foundComplexTypeNode[2][0][0]) {
+				case 'xs:sequence':
+				case 'xsd:sequence': return XML::findFieldsFromSequence($docArray, $foundComplexTypeNode[2][0]); break;
+				case 'xs:complexContent':
+				case 'xsd:complexContent': return XML::findFieldsFromComplexContent($docArray, $foundComplexTypeNode[2][0]); break;
+				case 'xs:annotation':
+				case 'xsd:annotation': {
+					switch ($foundComplexTypeNode[2][1][0]) {
+						case 'xs:sequence':
+						case 'xsd:sequence': return XML::findFieldsFromSequence($docArray, $foundComplexTypeNode[2][1]); break;
+						case 'xs:complexContent':
+						case 'xsd:complexContent': return XML::findFieldsFromComplexContent($docArray, $foundComplexTypeNode[2][1]); break;
+					}
+				} break;
+			}
+		}
+
 		if (!self::isXsdTag($nodeArray[2][0][0], 'sequence')) throw new Exception("Error Parsing Schema - expected 'complexType/complexContent/extension/sequence'");
 		foreach ($nodeArray[2][0][2] as $f) {
 			if (!self::isXsdTag($f[0], 'element')) {