WfsData.php 4.8 KB

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