WfsQgis.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. Lib::loadClass('Api_WfsLogger');
  8. class Api_WfsQgis extends ApiRouteBase {// TODO: extends Api_WfsBase which extends ApiBase
  9. public $_apiUser;
  10. public $_apiBaseUri;
  11. public $_idFiltrProces;
  12. public $_dataSourceName;
  13. public $_tblName;
  14. public $_tblSchema;
  15. public function execute($request) {
  16. $wfsLogger = new Api_WfsLogger();
  17. $this->setLogger($wfsLogger);
  18. $this->reqDBG($request);
  19. if (empty($request->segments)) {
  20. //$this->mainWpsAction($request);// show list of posible data source
  21. throw new HttpException("Bad Request", 400);
  22. } else {
  23. $pathPart = array_shift($request->segments);
  24. if ('filtr_proces_' == substr($pathPart, 0, 13)) {
  25. $this->_idFiltrProces = (int)substr($pathPart, 13);
  26. if (!$this->_idFiltrProces) throw new Api_WfsException("Wrong filtr process number");
  27. $this->DBG("filtr procesu({$idProcesFiltr})", __LINE__, __FUNCTION__, __CLASS__);
  28. $pathPart = array_shift($request->segments);
  29. }
  30. $this->_dataSourceName = $pathPart;
  31. $this->DBG("_dataSourceName:$this->_dataSourceName", __LINE__, __FUNCTION__, __CLASS__);
  32. try {
  33. $this->dataSourceAction($request);
  34. } catch (Api_WfsException $e) {
  35. $e->sendResponseXml();
  36. } catch (Exception $e) {
  37. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  38. $wfsException->sendResponseXml();
  39. }
  40. $this->DBG("END", __LINE__, __FUNCTION__, __CLASS__);
  41. }
  42. exit;
  43. // return document tree - array of arrays
  44. }
  45. public function wfsServerAction($request) {
  46. }
  47. public function dataSourceAction($request) {
  48. $document = '';
  49. //$userAcl = User::getAcl();
  50. 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>';}
  51. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  52. $userAcl->fetchGroups();
  53. if ($this->_idFiltrProces) {
  54. if (!$userAcl->canExecuteProcesInit($this->_idFiltrProces)) {
  55. throw new Api_WfsException("Access Denied for given process");
  56. }
  57. $userAcl->fetchProcesPerms($this->_idFiltrProces, true);
  58. } else {
  59. $userAcl->fetchAllPerms(true);
  60. }
  61. DBG::_('DBG', '>2', 'userAcl', $userAcl, __CLASS__, __FUNCTION__, __LINE__);
  62. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  63. $wfsServer = new Api_WfsQgisServer($userAcl);
  64. $wfsServer->setLogger($this->_logger);
  65. $wfsServer->setBaseUri($this->_apiBaseUri);
  66. DBG::_('DBG', true, 'getBaseNamespaceUri:', $wfsServer->getBaseNamespaceUri(), __CLASS__, __FUNCTION__, __LINE__);
  67. if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
  68. throw new Api_WfsException("Only WFS Service is allowed");
  69. }
  70. $req = V::get('REQUEST', '', $request->query);
  71. if (!empty($req)) {
  72. $methodName = "{$req}Action";
  73. if (!method_exists($wfsServer, $methodName)) {
  74. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  75. }
  76. $this->DBG("execute: WfsServer->{$methodName}(\$urlQuery)", __LINE__);
  77. $document = $wfsServer->$methodName($urlQuery);
  78. }
  79. else {
  80. $this->DBG("execute: WfsServer->parseXMLRequest()", __LINE__);
  81. $document = $wfsServer->parseXMLRequest();
  82. header('Content-type: application/xml');
  83. echo '<?xml version="1.0" encoding="UTF-8"?>';
  84. echo $document; exit;// TODO: return $document;
  85. }
  86. 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>';}
  87. header('Content-type: application/xml');
  88. echo $document; exit;// TODO: return $document;
  89. }
  90. public function mainWpsAction($request) {
  91. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  92. }
  93. }