|
|
@@ -290,7 +290,7 @@ class XML {
|
|
|
foreach ($c[2] as $cc) {
|
|
|
if ('appinfo' == XML::getTagName($cc[0])) {
|
|
|
foreach ($cc[2] as $appTag) {
|
|
|
- $appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($docArray, $appTag);
|
|
|
+ $appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($appTag);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -325,14 +325,16 @@ class XML {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+ static function isXsdNodeAnnotation($xsdNode) { return self::isXsdTag($xsdNode[0], 'annotation'); }
|
|
|
+ static function isXsdNodeAppInfo($xsdNode) { return self::isXsdTag($xsdNode[0], 'appinfo'); }
|
|
|
|
|
|
- public static function readAppInfoRecurse($docArray, $nodeArray) {
|
|
|
+ public static function readAppInfoRecurse($nodeArray) {
|
|
|
$appInfo = [];
|
|
|
if (!empty($nodeArray[1])) foreach ($nodeArray[1] as $attrName => $attrVal) {
|
|
|
$appInfo['@' . XML::getTagName($attrName)] = $attrVal;
|
|
|
}
|
|
|
if (!empty($nodeArray[2])) foreach ($nodeArray[2] as $appTag) {
|
|
|
- $appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($docArray, $appTag);
|
|
|
+ $appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($appTag);
|
|
|
}
|
|
|
// TODO: text nodes
|
|
|
return $appInfo;
|
|
|
@@ -448,32 +450,45 @@ class XML {
|
|
|
if (!$xsdType['nsUri']) throw new Exception("Missing schema root element namespace declaration = '{$name}'");
|
|
|
if ($xsdType['nsUri'] != $xsdType['targetNsUri']) throw new Exception("TODO: type ns is not the same as targetNamespace '{$name}'");// TODO
|
|
|
|
|
|
- foreach ($schema[2] as $n) {
|
|
|
- if (!XML::isXsdTag($n[0], 'complexType')) continue;
|
|
|
- if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
|
|
|
- DBG::log($n, 'array', "find system_cache__appinfo:primaryKey from complexType");
|
|
|
- if (array_key_exists('system_cache__appinfo:primaryKey', $n[1])) {
|
|
|
- $xsdType['primaryKey'] = V::get('system_cache__appinfo:primaryKey', '', $n[1]);
|
|
|
- }
|
|
|
- // complexType/sequence/element
|
|
|
- // complexType/complexContent/extension[base=...]/sequence/element
|
|
|
- switch ($n[2][0][0]) {
|
|
|
- case 'xs:sequence':
|
|
|
- case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][0]); break;
|
|
|
- case 'xs:complexContent':
|
|
|
- case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][0]); break;
|
|
|
- case 'xs:annotation':
|
|
|
- case 'xsd:annotation': {
|
|
|
- switch ($n[2][1][0]) {
|
|
|
- case 'xs:sequence':
|
|
|
- case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][1]); break;
|
|
|
- case 'xs:complexContent':
|
|
|
- case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][1]); break;
|
|
|
- }
|
|
|
- } break;
|
|
|
+ $foundComplexTypes = array_filter($schema[2], function ($n) use ($xsdType) {
|
|
|
+ return (XML::isXsdTag($n[0], 'complexType') && $xsdType['name'] === V::get('name', '', $n[1]));
|
|
|
+ });
|
|
|
+ if (empty($foundComplexTypes)) throw new Exception("Missing complexType node with name='{$xsdType['name']}'");
|
|
|
+ $nodeComplexType = reset($foundComplexTypes);
|
|
|
+
|
|
|
+ DBG::log($nodeComplexType, 'array', "found main complexType node");
|
|
|
+ if (array_key_exists('system_cache__appinfo:primaryKey', $nodeComplexType[1])) {
|
|
|
+ $xsdType['primaryKey'] = V::get('system_cache__appinfo:primaryKey', '', $nodeComplexType[1]);
|
|
|
+ }
|
|
|
+ $listAnnotations = array_filter($nodeComplexType[2], [ self, 'isXsdNodeAnnotation' ]);
|
|
|
+ if (!empty($listAnnotations)) {
|
|
|
+ // DBG::nicePrint($listAnnotations, "\$listAnnotations");
|
|
|
+ $nodeAnnotation = reset($listAnnotations);
|
|
|
+ $listAppInfo = array_filter($nodeAnnotation[2], [ self, 'isXsdNodeAppInfo' ]);
|
|
|
+ if (!empty($listAppInfo)) {
|
|
|
+ // DBG::nicePrint($listAppInfo, "\$listAppInfo");
|
|
|
+ $nodeAppInfo = reset($listAppInfo);
|
|
|
+ $xsdType['appInfo'] = XML::readAppInfoRecurse($nodeAppInfo);
|
|
|
}
|
|
|
- // if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
|
|
|
}
|
|
|
+ // complexType/sequence/element
|
|
|
+ // complexType/complexContent/extension[base=...]/sequence/element
|
|
|
+ switch ($nodeComplexType[2][0][0]) { // TODO: convert to loop
|
|
|
+ case 'xs:sequence':
|
|
|
+ case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $nodeComplexType[2][0]); break;
|
|
|
+ case 'xs:complexContent':
|
|
|
+ case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $nodeComplexType[2][0]); break;
|
|
|
+ case 'xs:annotation':
|
|
|
+ case 'xsd:annotation': {
|
|
|
+ switch ($nodeComplexType[2][1][0]) {
|
|
|
+ case 'xs:sequence':
|
|
|
+ case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $nodeComplexType[2][1]); break;
|
|
|
+ case 'xs:complexContent':
|
|
|
+ case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $nodeComplexType[2][1]); break;
|
|
|
+ }
|
|
|
+ } break;
|
|
|
+ }
|
|
|
+ // if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
|
|
|
if (empty($xsdType['primaryKey'])) {
|
|
|
foreach ($xsdType['struct'] as $fieldName => $field) {
|
|
|
if ('ID' === strtoupper($fieldName)) {
|