Kaynağa Gözat

added partial GetFeature for Ant Acl, added resolve simpleType in local prefix

Piotr Labudda 9 yıl önce
ebeveyn
işleme
e625c620ba
3 değiştirilmiş dosya ile 107 ekleme ve 2 silme
  1. 17 0
      SE/se-lib/AntAclBase.php
  2. 0 1
      SE/se-lib/Api/WfsDataServer.php
  3. 90 1
      SE/se-lib/XML.php

+ 17 - 0
SE/se-lib/AntAclBase.php

@@ -27,6 +27,15 @@ class AntAclBase extends Core_AclBase {
     }
     }
     return $cols;
     return $cols;
   }
   }
+  // public function getFieldType($fieldName) {
+  //   try {
+  //     throw new Exception("TODO: AntAclBase::getFieldType({$fieldName})");
+  //   } catch (Exception $e) {
+  //     DBG::log($e);
+  //   }
+  //   $field = $this->_getField($fieldName);
+  //   return $field['xsdType'];
+  // }
   public function getXsdFieldType($fieldName) {
   public function getXsdFieldType($fieldName) {
     $field = $this->_getField($fieldName);
     $field = $this->_getField($fieldName);
     return $field['xsdType'];
     return $field['xsdType'];
@@ -43,6 +52,9 @@ class AntAclBase extends Core_AclBase {
     return [];// TODO: ...
     return [];// TODO: ...
   }
   }
 
 
+  public function isGeomField($fieldName) {
+    return ('the_geom' === $fieldName); // TODO: ...
+  }
   public function isEnumerationField($fieldName) {
   public function isEnumerationField($fieldName) {
     return false; // TODO: ...
     return false; // TODO: ...
   }
   }
@@ -75,6 +87,11 @@ class AntAclBase extends Core_AclBase {
     throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
     throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
   }
   }
 
 
+  public function getItems($params = []) {
+    DBG::log($params, 'array', "AntAclBase::getItems params");
+    return [];
+  }
+
   public static function buildInstance($idZasob, $conf = []) {
   public static function buildInstance($idZasob, $conf = []) {
     static $_cache;
     static $_cache;
     if (!$_cache) $_cache = array();
     if (!$_cache) $_cache = array();

+ 0 - 1
SE/se-lib/Api/WfsDataServer.php

@@ -223,7 +223,6 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 		if (!$simple) $xmlWriter->writeAttribute("xmlns:{$rootWfsNs}", $rootWfsNsUri);
 		if (!$simple) $xmlWriter->writeAttribute("xmlns:{$rootWfsNs}", $rootWfsNsUri);
 		$xmlWriter->writeAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}");
 		$xmlWriter->writeAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}");
 
 
-		DBG::log([ 'msg'=>'$geomFld - getFieldType', 'getFieldType'=>$acl->getFieldType($geomFld) ]);
 		$tblName = $acl->getName();
 		$tblName = $acl->getName();
 		foreach ($items as $itemKey => $item) {
 		foreach ($items as $itemKey => $item) {
 			if (!is_array($item)) $item = (array)$item;
 			if (!is_array($item)) $item = (array)$item;

+ 90 - 1
SE/se-lib/XML.php

@@ -72,6 +72,30 @@ class XML {
     $xmlWriter->endDocument();
     $xmlWriter->endDocument();
   }
   }
 
 
+  public static function findTargetNamespace($docArray) {
+    return V::get('targetNamespace', '', $docArray[1]);
+  }
+
+  public static function findSimpleTypeNode($docArray, $name) {
+    foreach ($docArray[2] as $child) {
+      if ('simpleType' === 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");
+    foreach ($docArray[1] as $attr => $val) {
+      if ('xmlns:' !== substr($attr, 0, 6)) continue;
+      if ($tns === $val) return substr($attr, 6);
+    }
+    throw new Exception("Missing targetNamespace xmlns:...");
+  }
+
   public static function findElementName($docArray, $nodeArray) {
   public static function findElementName($docArray, $nodeArray) {
     if (!empty($nodeArray[1]['name'])) return $nodeArray[1]['name'];
     if (!empty($nodeArray[1]['name'])) return $nodeArray[1]['name'];
     if (!empty($nodeArray[1]['ref'])) return $nodeArray[1]['ref'];
     if (!empty($nodeArray[1]['ref'])) return $nodeArray[1]['ref'];
@@ -83,7 +107,72 @@ class XML {
     if (!empty($nodeArray[1]['type'])) {
     if (!empty($nodeArray[1]['type'])) {
       // TODO:TYPE_RECURCE: if local ns prefix then find correct typeName?
       // TODO:TYPE_RECURCE: if local ns prefix then find correct typeName?
       // TODO:TYPE_RECURCE:the same for restrictions
       // TODO:TYPE_RECURCE:the same for restrictions
-      return $nodeArray[1]['type'];
+      $type = $nodeArray[1]['type'];
+      if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
+      if ('xsd:' == substr($type, 0, 4)) return $type;
+      list($prefix, $name) = explode(':', $type);
+      if ($prefix === self::findTargetNamespacePrefix($docArray)) {
+        $simpleTypeNode = self::findSimpleTypeNode($docArray, $name);
+        DBG::log($simpleTypeNode, 'array', "\$simpleTypeNode \$fieldName='{$fieldName}' type='{$type}'");
+        if (!empty($simpleTypeNode[1]['type'])) {
+          throw new Exception("TODO: findElementType node/@type => 'xsd:simpleType/@type' = '{$simpleTypeNode[1]['type']}'");
+        }
+        if (!empty($simpleTypeNode[2][0]) && 'xsd:restriction' == $simpleTypeNode[2][0][0]) {
+          $restrictionNode = $simpleTypeNode[2][0];
+          if (empty($restrictionNode[1]['base'])) throw new Exception("Missing xsd:restriction/@base (node/@type => xsd:simpleType/[@type='{$simpleTypeNode[1]['type']}']/xsd:restriction')");
+          $type = $restrictionNode[1]['base'];
+          DBG::log($type, 'array', "findElementType \$fieldName='{$fieldName}' type='{$nodeArray[1]['type']}' => type='{$type}'");
+          // TODO: in findElementRestrictions or findSimpleTypeRestrictions - save current restrictions in $restrictionNode[2]
+          // TODO: check restrictions - if has enumeration then return 'p5:enum'
+          $isEnum = false;
+          foreach ($restrictionNode[2] as $restr) {
+            if ('enumeration' === self::getTagName($restr[0])) {
+              $isEnum = true;
+              break;
+            }
+          }
+          if ($isEnum) return 'p5:enum';
+
+          // TODO: recurse with limit
+          if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
+          if ('xsd:' == substr($type, 0, 4)) return $type;
+          list($prefix, $name) = explode(':', $type);
+          $simpleTypeNode = self::findSimpleTypeNode($docArray, $name);
+          DBG::log($simpleTypeNode, 'array', "\$simpleTypeNode \$fieldName='{$fieldName}' ... type='{$type}'");
+          if (!empty($simpleTypeNode[1]['type'])) {
+            throw new Exception("TODO: findElementType node/@type => 'xsd:simpleType/@type' = '{$simpleTypeNode[1]['type']}'");
+          }
+          if (!empty($simpleTypeNode[2][0]) && 'xsd:restriction' == $simpleTypeNode[2][0][0]) {
+            $restrictionNode = $simpleTypeNode[2][0];
+            if (empty($restrictionNode[1]['base'])) throw new Exception("Missing xsd:restriction/@base (node/@type => xsd:simpleType/[@type='{$simpleTypeNode[1]['type']}']/xsd:restriction')");
+            $type = $restrictionNode[1]['base'];
+            DBG::log($type, 'array', "findElementType \$fieldName='{$fieldName}' ... type='{$type}'");
+            if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
+            if ('xsd:' == substr($type, 0, 4)) return $type;
+          }
+          // TODO: throw...
+        }
+        // TODO: throw...
+        //   0 => 'xsd:simpleType',
+        //   1 => [
+        //     'name' => 'PROCES_INIT_Simple',
+        //   ],
+        //   2 => [
+        //     0 => [
+        //       0 => 'xsd:restriction',
+        //       1 => [
+        //         'base' => 'default_db__x3A__CRM_PROCES:TYPE_Simple',
+        //       ],
+        //       2 => [
+        //         0 => [
+        //           0 => 'xsd:enumeration',
+        //           1 => [
+        //             'value' => 'PROCES_INIT',
+        //           ],
+        //           2 => NULL,
+      } else {
+        return $nodeArray[1]['type'];
+      }
     }
     }
     if (!empty($nodeArray[1]['ref'])) return 'ref:' . $nodeArray[1]['ref'];
     if (!empty($nodeArray[1]['ref'])) return 'ref:' . $nodeArray[1]['ref'];
     if (empty($nodeArray[2])) throw new Exception("Missing xsd:element childrens - cannot find type");
     if (empty($nodeArray[2])) throw new Exception("Missing xsd:element childrens - cannot find type");