WfsDataServer.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <?php
  2. Lib::loadClass('Api_WfsServerBase');
  3. Lib::loadClass('Api_WfsException');
  4. Lib::loadClass('Api_WfsGeomTypeConverter');
  5. Lib::loadClass('Api_WfsNs');
  6. Lib::loadClass('Core_XmlWriter');
  7. Lib::loadClass('DBG');
  8. class Api_WfsDataServer extends Api_WfsServerBase {
  9. public function run($request) {
  10. $document = '';
  11. if ('WFS' != V::get('SERVICE', '', $request->query) && ('WFS' != V::get('service', '', $request->query))) {
  12. throw new Api_WfsException("Only WFS Service is allowed");
  13. }
  14. $req = V::get('REQUEST', '', $request->query);
  15. if (!empty($req)) {
  16. $methodName = "{$req}Action";
  17. if (!method_exists($this, $methodName)) {
  18. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  19. }
  20. $this->DBG("WfsServer->{$methodName}() ...", __LINE__);
  21. $document = $this->$methodName($urlQuery);
  22. }
  23. else {
  24. $this->DBG("WfsServer->parseXMLRequest() ...", __LINE__);
  25. $document = $this->parseXMLRequest();
  26. header('Content-type: application/xml');
  27. echo '<?xml version="1.0" encoding="UTF-8"?>';
  28. echo $document; exit;// TODO: return $document;
  29. }
  30. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$document (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($document);echo'</pre>';}
  31. if ('raw' == V::get('outputFormat', '', $request->query)) {
  32. header('Content-type: text/plain; charset=utf-8');
  33. echo $document;
  34. } else {
  35. header('Content-type: application/xml');
  36. echo $document;
  37. }
  38. }
  39. public function parseXMLRequest() {
  40. $data = array();
  41. $reqContent = Request::getRequestBody();
  42. if (empty($reqContent)) {
  43. throw new Exception("Empty request");
  44. }
  45. $parserXml = xml_parser_create();
  46. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  47. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  48. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  49. throw new Exception("Error parsing xml");
  50. }
  51. xml_parser_free($parserXml);
  52. if (empty($tags)) {
  53. throw new Exception("Empty structure from request");
  54. }
  55. $rootTagName = V::get('tag', '', $tags[0]);
  56. if ('Transaction' == $rootTagName) return $this->_parseTransactionXmlStruct($reqContent, $tags);
  57. throw new Api_WfsException("Not implemented '{$rootTagName}' #L." . __LINE__, 501);
  58. }
  59. public function getFeatureAction() {
  60. $args = $this->parseGetFeatureArgsFromRequest();
  61. if ('hits' == $args['resultType']) {
  62. return $this->getTotalFeatures($args, $simple = true);
  63. } else {
  64. return $this->getFeatures($args, $simple = true);
  65. }
  66. }
  67. public function getFeatureAdvancedAction() {
  68. $args = $this->parseGetFeatureArgsFromRequest();
  69. if ('hits' == $args['resultType']) {
  70. return $this->getTotalFeatures($args, $simple = false);
  71. } else {
  72. if ('/@instance' == strtolower(substr($args['typeName'], -1 * strlen('/@instance')))) {
  73. return $this->getInstanceFeatures(substr($args['typeName'], 0, -1 * strlen('/@instance')), $args);
  74. }
  75. return $this->getFeatures($args, $simple = false);
  76. }
  77. }
  78. public function testOgcFilterAction() {
  79. $type = V::get('TYPENAME', '', $_REQUEST);
  80. $typeEx = explode(':', $type);
  81. $maxFeatures = V::get('MAXFEATURES', '10000', $_REQUEST, 'int');// TODO: Set Deafult Limit
  82. $ogcFilter = V::get('Filter', '', $_REQUEST);
  83. $srsname = V::get('SRSNAME', '', $_REQUEST);// eg. EPSG:4326
  84. if (count($typeEx) == 2) {
  85. Lib::loadClass('ParseOgcFilter');
  86. $parser = new ParseOgcFilter();
  87. $parser->loadOgcFilter($ogcFilter);
  88. $queryWhereBuilder = $parser->convertToSqlQueryWhereBuilder();
  89. echo $queryWhereBuilder->getQueryWhere('t');
  90. } else {
  91. throw new HttpException("Wrong param TYPENAME", 400);
  92. }
  93. }
  94. public function getTotalFeatures($args, $simple = true) {
  95. DBG::log("typeName({$args['xsd:type']})");
  96. $acl = $this->getAclFromTypeName($args['xsd:type']);
  97. DBG::log([ 'msg'=>"typeName({$args['xsd:type']}) - acl(".get_class($acl).")", '$acl'=>$acl ]);
  98. $fldList = $this->_getFieldListFromAcl($acl);
  99. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  100. $rootWfsNs = 'p5';
  101. $rootWfsNsUri = "{$baseNsUri}";
  102. $wfsNs = $args['typePrefix'];
  103. $wfsNsUri = "{$baseNsUri}/" . ('p5_' == substr($args['typePrefix'], 0, 3)) ? substr($args['typePrefix'], 3) : $args['typePrefix'];
  104. $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$args['xsd:type']}&REQUEST=DescribeFeatureType";
  105. // get BBox from geom_field (only one geom fld is allowed)
  106. $geomFld = null;
  107. {
  108. foreach ($fldList as $fldName) {
  109. if ($acl->isGeomField($fldName)) {
  110. $geomFld = $fldName;
  111. }
  112. }
  113. }
  114. DBG::log("ogcFilter(" . strlen($args['ogc:filter']) . "): {$args['ogc:filter']}");
  115. $searchParams = array();
  116. $searchParams['limit'] = $args['limit'];
  117. $searchParams['limitstart'] = $args['offset'];
  118. if (!empty($args['sortBy'])) {
  119. $searchParams['sortBy'] = $args['sortBy'];
  120. } else {
  121. $searchParams['order_by'] = $acl->getPrimaryKeyField();
  122. $searchParams['order_dir'] = 'DESC';
  123. }
  124. if (strlen($args['ogc:filter']) > 0) $searchParams['ogc:Filter'] = $args['ogc:filter'];
  125. if (!empty($args['filterFields'])) $searchParams['cols'] = $args['filterFields'];// propertyName
  126. if (!empty($args['primaryKey'])) $searchParams['primaryKey'] = $args['primaryKey'];// featureID
  127. if (!empty($args['bbox'])) $searchParams['f_the_geom'] = "BBOX:{$args['bbox']}";
  128. $queryFeatures = $acl->buildQuery($searchParams);
  129. $totalItems = $queryFeatures->getTotal();
  130. $xmlWriter = new XMLWriter();
  131. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  132. $xmlWriter->openUri('php://output');
  133. $xmlWriter->setIndent(true);
  134. $xmlWriter->startDocument('1.0','UTF-8');
  135. $xmlWriter->startElement('wfs:FeatureCollection');
  136. $xmlWriter->writeAttribute('xmlns:wfs', 'http://www.opengis.net/wfs/2.0');
  137. $xmlWriter->writeAttribute('xmlns', 'http://www.opengis.net/wfs/2.0');
  138. $xmlWriter->writeAttribute('xmlns:gml', 'http://www.opengis.net/gml');
  139. $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  140. // $xmlWriter->writeAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}");
  141. $xmlWriter->writeAttribute('numberMatched', $totalItems);
  142. $xmlWriter->writeAttribute('numberReturned', 0);
  143. // $xmlWriter->writeAttribute('timeStamp', "TODO: timestamp like '2011-12-09T11:30:16'");
  144. $xmlWriter->endElement();// wfs:FeatureCollection
  145. $xmlWriter->endDocument();
  146. exit;
  147. }
  148. public function getFeatures($args, $simple = true) {
  149. $type = $args['typeName'];
  150. DBG::log("typeName({$args['xsd:type']})");
  151. $acl = $this->getAclFromTypeName($args['xsd:type']);
  152. DBG::log([ 'msg'=>"typeName({$args['xsd:type']}) - acl(".get_class($acl).")", '$acl'=>$acl ]);
  153. $fldList = $this->_getFieldListFromAcl($acl);
  154. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  155. $rootWfsNs = 'p5';
  156. $rootWfsNsUri = "{$baseNsUri}";
  157. $wfsNs = $args['typePrefix'];
  158. $wfsNsUri = "{$baseNsUri}/" . ('p5_' === substr($args['typePrefix'], 0, 3) ? substr($args['typePrefix'], 3) : $args['typePrefix']);
  159. $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$args['xsd:type']}&REQUEST=DescribeFeatureType";
  160. // get BBox from geom_field (only one geom fld is allowed)
  161. $geomFld = null;
  162. {
  163. foreach ($fldList as $fldName) {
  164. if ($acl->isGeomField($fldName)) {
  165. $geomFld = $fldName;
  166. }
  167. }
  168. }
  169. DBG::log("ogcFilter(" . strlen($args['ogc:filter']) . "): {$args['ogc:filter']}");
  170. $searchParams = array();
  171. $searchParams['limit'] = $args['limit'];
  172. $searchParams['limitstart'] = $args['offset'];
  173. if (!empty($args['sortBy'])) {
  174. $searchParams['sortBy'] = $args['sortBy'];
  175. } else {
  176. $searchParams['order_by'] = $acl->getPrimaryKeyField();
  177. $searchParams['order_dir'] = 'DESC';
  178. }
  179. if (strlen($args['ogc:filter']) > 0) $searchParams['ogc:Filter'] = $args['ogc:filter'];
  180. if (!empty($args['filterFields'])) $searchParams['cols'] = $args['filterFields'];// PropertyName
  181. if (!empty($args['primaryKey'])) $searchParams['primaryKey'] = $args['primaryKey'];// featureID
  182. if (!empty($args['bbox'])) $searchParams['f_the_geom'] = "BBOX:{$args['bbox']}";
  183. $contextFieldList = []; // convert $args['filterFields'] to field list
  184. $schemaCache = array();
  185. try {
  186. $acl__getAllFieldNames = function ($listFields) {
  187. return array_map(function ($field) {
  188. return $field['fieldNamespace'];
  189. }, $listFields);
  190. };
  191. $acl__getLocalFieldNames = function ($listFields) {
  192. return array_map(function ($field) {
  193. return $field['fieldNamespace'];
  194. }, array_filter($listFields, function ($field) {
  195. return $field['isLocal'];
  196. }));
  197. };
  198. DBG::log($acl->getFields(), 'array', "\$contextFieldList ACL fields");
  199. if (empty($args['filterFields'])) { // get all local fields
  200. // $contextFieldList = $acl__getLocalFieldNames($acl->getFields());
  201. $contextFieldList = $acl__getAllFieldNames($acl->getFields());
  202. } else {
  203. foreach ($args['filterFields'] as $fieldXPath) {
  204. if ('*' === $fieldXPath) {
  205. $contextFieldList = array_merge($contextFieldList, $acl__getLocalFieldNames($acl->getFields()));
  206. } else if (false === strpos($fieldXPath, '/') && false === strpos($fieldXPath, ':')) {
  207. $contextFieldList[] = $fieldXPath;
  208. } else if (false === strpos($fieldXPath, '/') && false !== strpos($fieldXPath, ':')) {
  209. $contextFieldList[] = $fieldXPath;
  210. $fieldNs = str_replace(['__x3A__', ':'], '/', $fieldXPath);
  211. $schemaCache[$fieldNs] = SchemaFactory::loadDefaultObject('SystemObject')->getItem($fieldNs, [ 'propertyName' => '*,field' ]);
  212. DBG::log($schemaCache[$fieldNs], 'array', "\$schemaCache[{$fieldNs}]");
  213. } else if ('/*' === substr($fieldXPath, -2) && false === strpos(substr($fieldXPath, 0, -2), '/')) {
  214. $fieldName = substr($fieldXPath, 0, -2);
  215. $contextFieldList[] = $fieldName;
  216. $xsdType = $acl->getXsdFieldType($fieldName);
  217. if ('ref:' !== substr($xsdType, 0, 4)) throw new Exception("Error Processing Request - field '{$fieldXPath}' type is not ref '/*' is not allowed");
  218. $fieldNs = str_replace(['__x3A__', ':'], '/', substr($xsdType, 4));
  219. if (!array_key_exists($fieldNs, $schemaCache)) {
  220. $schemaCache[$fieldNs] = SchemaFactory::loadDefaultObject('SystemObject')->getItem($fieldNs, [ 'propertyName' => '*,field' ]);
  221. DBG::log($schemaCache[$fieldNs], 'array', "\$schemaCache[{$fieldNs}]");
  222. }
  223. $fieldPrefix = "{$fieldName}";
  224. $contextFieldList = array_merge($contextFieldList, array_map(function ($fieldName) use ($fieldPrefix) {
  225. return "{$fieldPrefix}/{$fieldName}";
  226. }, $acl__getLocalFieldNames($schemaCache[$fieldNs]['field'])));
  227. } else {
  228. $fieldName = trim($fieldXPath, '*/');
  229. DBG::log(['$fieldXPath'=>$fieldXPath, '$fieldName'=>$fieldName], 'array', "\$contextFieldList TODO");
  230. }
  231. }
  232. }
  233. DBG::log($contextFieldList, 'array', "\$contextFieldList");
  234. $searchParams['cols'] = $contextFieldList;
  235. } catch (Exception $e) {
  236. DBG::log($e);
  237. throw $e;
  238. }
  239. DBG::log([ 'msg'=>'getItems - $searchParams', '$searchParams'=>$searchParams ]);
  240. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData->total);echo'</pre>';}
  241. $queryFeatures = $acl->buildQuery($searchParams);
  242. $items = $queryFeatures->getItems();
  243. DBG::log([ 'msg'=>'getItems - $items', '$items'=>$items ]);
  244. header('Content-type: application/xml; charset=utf-8');
  245. $xmlWriter = new Core_XmlWriter();
  246. $xmlWriter->openUri('php://output');
  247. // $xmlWriter->openMemory();// DBG
  248. $xmlWriter->setIndent(true);
  249. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  250. $xmlWriter->startDocument('1.0','UTF-8');
  251. //$xmlWriter->startElementNS('wfs', 'FeatureCollection', 'http://www.opengis.net/wfs');
  252. $xmlWriter->startElement('wfs:FeatureCollection');
  253. // $xmlWriter->writeAttributeNS('xmlns', 'wfs', 'http://www.w3.org/2000/xmlns/', 'http://www.opengis.net/wfs');
  254. $xmlWriter->writeAttribute('xmlns:wfs', 'http://www.opengis.net/wfs');
  255. $xmlWriter->writeAttribute('xmlns', 'http://www.opengis.net/wfs');
  256. $xmlWriter->writeAttribute('xmlns:gml', 'http://www.opengis.net/gml');
  257. $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  258. $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  259. $xmlWriter->writeAttribute("xmlns:{$wfsNs}", $wfsNsUri); // TODO: BUG $wfsNsUri
  260. if (!$simple) $xmlWriter->writeAttribute("xmlns:{$rootWfsNs}", $rootWfsNsUri);
  261. foreach ($schemaCache as $childSchema) {
  262. $xmlWriter->writeAttribute("xmlns:{$childSchema['nsPrefix']}", "{$rootWfsNsUri}/" . str_replace('__x3A__', '/', $childSchema['nsPrefix']));
  263. }
  264. $xmlWriter->writeAttribute('xsi:schemaLocation', "{$wfsNsUri} {$featureTypeUri}"); // TODO: BUG $wfsNsUri
  265. $xmlWriter->writeAttribute('numberMatched', 'unknown'); // TODO: return total items if simple query (without prefix, small total number, maxFeatures set, etc.)
  266. // NOTE: for client: if numberMatched == 'unknown' then request with resultType = 'hits'
  267. $xmlWriter->writeAttribute('numberReturned', count($items));
  268. $tblName = $acl->getName();
  269. $primaryKeyField = $acl->getPrimaryKeyField();
  270. foreach ($items as $item) {
  271. $itemKey = V::get($primaryKeyField, '', $item);
  272. if (!is_array($item)) $item = (array)$item;
  273. if (!empty($geomFld)) DBG::log(['msg'=>"item[{$itemKey}] ({$geomFld})isEmpty(".empty($item[$geomFld])."):", '$item['.$geomFld.']'=>$item[$geomFld]]);
  274. DBG::log([ 'msg'=>">>> loop({$itemKey})", '$item'=>$item ]);
  275. $xmlWriter->startElement('gml:featureMember');
  276. $xmlWriter->startElement("{$wfsNs}:{$type}");
  277. $xmlWriter->writeAttribute('fid', "{$type}.{$itemKey}");
  278. if (!$simple) $xmlWriter->writeAttribute("{$rootWfsNs}:web_link", Request::getPathUri() . "index.php?_route=ViewTableAjax&namespace=" . $acl->getNamespace() . "#EDIT/{$itemKey}");
  279. foreach ($fldList as $idZasob => $fldName) {
  280. if(V::get('DBG_LOOP','',$_GET))DBG::log([ 'msg'=>">>> loop({$itemKey}) item({$item['ID']}) fld({$fldName})", '$item'=>$item[$fldName] ]);
  281. $fldType = $acl->getXsdFieldType($fldName);
  282. if (!$acl->canReadObjectField($fldName, (object)$item)) continue;
  283. if ($geomFld != null && $fldName == $geomFld) {
  284. $xmlWriter->startElement("{$wfsNs}:{$fldName}");
  285. if (!$simple && !$acl->canReadObjectField($fldName, (object)$item)) {
  286. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_read", "false");
  287. }
  288. if (!$simple && $acl->canWriteObjectField($fldName, (object)$item)) {
  289. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_write", "true");
  290. }
  291. $this->_typeConverter->createGmlFromWkt_xmlWriter($item[$fldName], $xmlWriter);
  292. $xmlWriter->endElement();// {$wfsNs}:{$fldName}
  293. } else if (is_array($item[$fldName])) {// TODO: by struct - REF field
  294. DBG::log([ 'msg'=>">>> loop({$itemKey}) REF item[{$itemKey}][{$fldName}]", '$item'=>$item[$fldName] ]);
  295. if (empty($item[$fldName])) {
  296. $xmlWriter->h($fldName);
  297. // } else if (1 == count($item[$fldName]) && !empty($item[$fldName][0]['xlink'])) {
  298. // $xlink = $item[$fldName][0]['xlink'];
  299. // $xlinkParts = explode(':', $xlink);
  300. // if (2 != count($xlinkParts)) throw new Exception("Error Processing Request - wrong xlink format for ".$acl->getName().".{$itemKey}/{$fldName}");
  301. // $xlinkParts[0] = Api_WfsNs::getNsUri($xlinkParts[0]);
  302. // $xlink = implode('#', $xlinkParts);
  303. // $xmlWriter->startElement("{$wfsNs}:{$fldName}");
  304. // if (!$simple && !$acl->canReadObjectField($fldName, (object)$item)) {
  305. // $xmlWriter->writeAttribute("{$rootWfsNs}:allow_read", "false");
  306. // }
  307. // if (!$simple && $acl->canWriteObjectField($fldName, (object)$item)) {
  308. // $xmlWriter->writeAttribute("{$rootWfsNs}:allow_write", "true");
  309. // }
  310. // $xmlWriter->writeAttribute('xlink:href', $xlink);
  311. // $xmlWriter->endElement();// {$wfsNs}:{$fldName}
  312. } else {
  313. // $xmlWriter->writeComment("TODO: ".$acl->getName().".{$itemKey}/{$fldName} ...");
  314. $fieldNs = str_replace(['__x3A__', ':'], '/', $fldName); // substr($xsdType, 4));
  315. if (!array_key_exists($fieldNs, $schemaCache)) {
  316. $xmlWriter->writeComment("Error Processing Request - field is not ref ".$acl->getName().".{$itemKey}/{$fldName}");
  317. } else {
  318. foreach ($item[$fldName] as $refItem) {
  319. DBG::log($refItem, 'array', "\$refItem fld({$fldName})");
  320. if (1 == count($refItem) && !empty($refItem['xlink'])) {
  321. $xmlWriter->startElement($schemaCache[$fieldNs]['typeName']);
  322. $xmlWriter->writeAttribute("xlink:href", $refItem['xlink']);
  323. $xmlWriter->endElement();
  324. } else {
  325. $xmlWriter->startElement($schemaCache[$fieldNs]['typeName']);
  326. foreach ($schemaCache[$fieldNs]['field'] as $field) {
  327. // $xmlWriter->writeComment("REF field ({$field['fieldNamespace']}) value({$refItem[$field['fieldNamespace']]})");
  328. if (array_key_exists($field['fieldNamespace'], $refItem)) {
  329. $xmlWriter->startElement("{$schemaCache[$fieldNs]['nsPrefix']}:{$field['fieldNamespace']}");
  330. $xmlWriter->text($refItem[$field['fieldNamespace']]);
  331. $xmlWriter->endElement();
  332. }
  333. }
  334. $xmlWriter->endElement();
  335. }
  336. }
  337. }
  338. }
  339. } else if ('xsd:base64Binary' === $acl->getXsdFieldType($fldName)) {
  340. if (empty($item[$fldName]) && '0' !== $item[$fldName]) continue;
  341. $xmlWriter->startElement("{$wfsNs}:{$fldName}");
  342. if (!$simple && !$acl->canReadObjectField($fldName, (object)$item)) {
  343. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_read", "false");
  344. }
  345. if (!$simple && $acl->canWriteObjectField($fldName, (object)$item)) {
  346. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_write", "true");
  347. }
  348. $xmlWriter->text(base64_encode($item[$fldName]));
  349. $xmlWriter->endElement();// {$wfsNs}:{$fldName}
  350. } else {
  351. $value = str_replace('&', '&amp;', $item[$fldName]);
  352. if (empty($value) && '0' !== $value) {
  353. continue;
  354. } else {
  355. $xmlWriter->startElement("{$wfsNs}:{$fldName}");
  356. if (!$simple && !$acl->canReadObjectField($fldName, (object)$item)) {
  357. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_read", "false");
  358. }
  359. if (!$simple && $acl->canWriteObjectField($fldName, (object)$item)) {
  360. $xmlWriter->writeAttribute("{$rootWfsNs}:allow_write", "true");
  361. }
  362. $xmlWriter->text($value);
  363. $xmlWriter->endElement();// {$wfsNs}:{$fldName}
  364. }
  365. }
  366. }
  367. $xmlWriter->endElement();// {$wfsNs}:{$type}
  368. $xmlWriter->endElement();// gml:featureMember
  369. }
  370. $xmlWriter->endElement();// wfs:FeatureCollection
  371. $xmlWriter->endDocument();
  372. exit;
  373. }
  374. public function describeFeatureTypeAction() {
  375. $type = V::get('TYPENAME', '', $_REQUEST);
  376. if (empty($type)) {
  377. $reqContent = Request::getRequestBody();
  378. if (!empty($reqContent)) {
  379. return $this->_parseDescribeFeatureTypeRequest($reqContent);
  380. } else {
  381. return $this->_getDescribeFeatureAllTypes();
  382. }
  383. //throw new HttpException("Wrong param TYPENAME", 400);
  384. }
  385. $typeEx = explode(':', $type);
  386. if (count($typeEx) != 2) throw new HttpException("Wrong param TYPENAME", 400);
  387. return $this->_getDescribeFeatureType($typeEx[0], $typeEx[1]);
  388. }
  389. public function describeFeatureTypeAdvancedAction() {
  390. $typeName = V::geti('TYPENAME', '', $_REQUEST);
  391. if (empty($typeName)) {
  392. $reqContent = Request::getRequestBody();
  393. if (!empty($reqContent)) {
  394. return $this->_parseDescribeFeatureTypeRequest($reqContent, $simple = false);
  395. } else {
  396. return $this->_getDescribeFeatureAllTypes($simple = false);
  397. }
  398. //throw new HttpException("Wrong param TYPENAME", 400);
  399. }
  400. if (false === strpos($typeName, ':')) throw new HttpException("Wrong param TYPENAME", 400);
  401. list($nsPrefix, $name) = explode(':', $typeName);
  402. if ('/@instance' == strtolower(substr($name, -1 * strlen('/@instance')))) {
  403. return $this->_describeInstanceAttributeTable($nsPrefix, substr($name, 0, -1 * strlen('/@instance')));
  404. }
  405. return $this->_getDescribeFeatureType($nsPrefix, $name, $simple = false);
  406. }
  407. public function getCapabilitiesAction() {
  408. $wfsServerUrl = $this->getBaseUri();
  409. $serviceTitle = "Web Feature Service";
  410. $serviceDescription = "This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.";
  411. //header('Content-type: application/xml; charset="utf-8"');
  412. header('Content-type: application/xml');
  413. $this->_getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription);
  414. }
  415. }