WfsQgis.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_WfsQgisServer');
  6. Lib::loadClass('UserAcl');
  7. class Api_WfsQgis 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. DBG::_('DBG', '>2', 'userAcl', $userAcl, __CLASS__, __FUNCTION__, __LINE__);
  70. $this->DBG("WfsServer(" . $this->_apiUser->getID() . ") ...", __LINE__);
  71. $wfsServer = new Api_WfsQgisServer($userAcl);
  72. $wfsServer->setBaseUri($this->_apiBaseUri);
  73. DBG::_('DBG', true, 'getBaseNamespaceUri:', $wfsServer->getBaseNamespaceUri(), __CLASS__, __FUNCTION__, __LINE__);
  74. if ('WFS' != V::get('SERVICE', '', $request->query)) {
  75. throw new Api_WfsException("Only WFS Service is allowed");
  76. }
  77. $req = V::get('REQUEST', '', $request->query);
  78. if (!empty($req)) {
  79. $methodName = "{$req}Action";
  80. if (!method_exists($wfsServer, $methodName)) {
  81. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  82. }
  83. $this->DBG("WfsServer->{$methodName}() ...", __LINE__);
  84. $document = $wfsServer->$methodName($urlQuery);
  85. }
  86. else {
  87. $this->DBG("WfsServer->parseXMLRequest() ...", __LINE__);
  88. $document = $wfsServer->parseXMLRequest();
  89. header('Content-type: application/xml');
  90. echo '<?xml version="1.0" encoding="UTF-8"?>';
  91. echo $document; exit;// TODO: return $document;
  92. }
  93. 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>';}
  94. header('Content-type: application/xml');
  95. echo $document; exit;// TODO: return $document;
  96. exit;
  97. // TODO: return $document;
  98. }
  99. public function mainWpsAction($request) {
  100. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  101. }
  102. }