WfsData.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. Lib::loadClass('ApiRouteBase');
  3. Lib::loadClass('ApiDataSourceTodo');// TODO: @see Entity/Source/Mysql from feature-schema-install
  4. Lib::loadClass('Api_WfsException');
  5. Lib::loadClass('Api_WfsDataServer');
  6. Lib::loadClass('UserAcl');
  7. class Api_WfsData extends ApiRouteBase {// TODO: extends Api_WfsBase which extends ApiBase
  8. public $_apiUser;
  9. public $_apiBaseUri;
  10. public $_dataSourceName;
  11. public $_tblName;
  12. public $_tblSchema;
  13. public function execute($request) {
  14. $this->reqDBG($request, __LINE__);
  15. /* TODO: return response xml document
  16. $responseDocument = null;
  17. try {
  18. $responseDocument = $this->wfsServerAction($request);
  19. } catch (Api_WfsException $e) {// TODO: create WfsException - http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd
  20. //} catch (Exception $e) {// TODO: create WfsException - http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd
  21. $responseDocument = $this->wfsExceptionAction($request, $e);
  22. }
  23. return $responseDocument;
  24. */
  25. if (empty($request->segments)) {
  26. //$this->mainWpsAction($request);// show list of posible data source
  27. throw new HttpException("Bad Request", 400);
  28. } else {
  29. $this->_dataSourceName = array_shift($request->segments);
  30. $this->DBG("dataSourceAction({$this->_dataSourceName}) ...", __LINE__);
  31. try {
  32. $this->dataSourceAction($request);
  33. } catch (Api_WfsException $e) {
  34. $responseDocument = $this->wfsExceptionAction($e);
  35. header('Content-type: application/xml');
  36. echo $responseDocument;
  37. } catch (Exception $e) {
  38. $responseDocument = $this->wfsExceptionAction($e);
  39. header('Content-type: application/xml');
  40. echo $responseDocument;
  41. }
  42. $this->DBG("dataSourceAction() END", __LINE__);
  43. }
  44. exit;
  45. // return document tree - array of arrays
  46. }
  47. public function wfsServerAction($request) {
  48. }
  49. public function wfsExceptionAction($e) {
  50. $dom = new DOMDocument('1.0', 'utf-8');
  51. $dom->formatOutput = true;
  52. $dom->preserveWhiteSpace = false;
  53. $rootNode = $dom->createElementNS('http://www.opengis.net/ogc', 'ServiceExceptionReport');
  54. $dom->appendChild($rootNode);
  55. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  56. $rootNode->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation', 'http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd');
  57. $rootNode->setAttribute('version', '1.2.0');
  58. $srvExNode = $dom->createElement('ServiceException', $e->getMessage());
  59. $rootNode->appendChild($srvExNode);
  60. return $dom->saveXML();
  61. }
  62. public function dataSourceAction($request) {
  63. $document = '';
  64. //$userAcl = User::getAcl();
  65. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">user (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_apiUser);echo'</pre>';}
  66. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  67. $userAcl->fetchGroups();
  68. $userAcl->fetchAllPerms(true);
  69. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$userAcl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($userAcl);echo'</pre>';}
  70. $this->DBG("WfsServer(" . $this->_apiUser->getID() . ") ...", __LINE__);
  71. $wfsServer = new Api_WfsDataServer($userAcl);
  72. $wfsServer->setBaseUri($this->_apiBaseUri);
  73. if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
  74. throw new Api_WfsException("Only WFS Service is allowed");
  75. }
  76. $req = V::get('REQUEST', '', $request->query);
  77. if (!empty($req)) {
  78. $methodName = "{$req}Action";
  79. if (!method_exists($wfsServer, $methodName)) {
  80. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  81. }
  82. $this->DBG("WfsServer->{$methodName}() ...", __LINE__);
  83. $document = $wfsServer->$methodName($urlQuery);
  84. }
  85. else {
  86. $this->DBG("WfsServer->parseXMLRequest() ...", __LINE__);
  87. $document = $wfsServer->parseXMLRequest();
  88. header('Content-type: application/xml');
  89. echo '<?xml version="1.0" encoding="UTF-8"?>';
  90. echo $document; exit;// TODO: return $document;
  91. }
  92. 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>';}
  93. if ('raw' == V::get('outputFormat', '', $request->query)) {
  94. header('Content-type: text/plain; charset=utf-8');
  95. echo $document;
  96. } else {
  97. header('Content-type: application/xml');
  98. echo $document;
  99. }
  100. exit;// TODO: return $document;
  101. }
  102. public function mainWpsAction($request) {
  103. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  104. }
  105. }