WfsData.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. if (empty($request->segments)) {
  19. //$this->mainWpsAction($request);// show list of posible data source
  20. throw new HttpException("Bad Request", 400);
  21. } else {
  22. $this->_dataSourceName = array_shift($request->segments);
  23. $this->DBG("dataSourceAction({$this->_dataSourceName}) ...", __LINE__);
  24. try {
  25. $this->dataSourceAction($request);
  26. } catch (Api_WfsException $e) {
  27. $e->sendResponseXml();
  28. } catch (Exception $e) {
  29. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  30. $wfsException->sendResponseXml();
  31. }
  32. $this->DBG("dataSourceAction() END", __LINE__);
  33. }
  34. exit;
  35. // return document tree - array of arrays
  36. }
  37. public function wfsServerAction($request) {
  38. }
  39. public function dataSourceAction($request) {
  40. $document = '';
  41. //$userAcl = User::getAcl();
  42. 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>';}
  43. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  44. $userAcl->fetchGroups();
  45. $userAcl->fetchAllPerms(true);
  46. 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>';}
  47. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  48. $wfsServer = new Api_WfsDataServer($userAcl);
  49. $wfsServer->setBaseUri($this->_apiBaseUri);
  50. if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
  51. throw new Api_WfsException("Only WFS Service is allowed");
  52. }
  53. $req = V::get('REQUEST', '', $request->query);
  54. if (!empty($req)) {
  55. $methodName = "{$req}Action";
  56. if (!method_exists($wfsServer, $methodName)) {
  57. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  58. }
  59. $this->DBG("WfsServer->{$methodName}() ...", __LINE__);
  60. $document = $wfsServer->$methodName($urlQuery);
  61. }
  62. else {
  63. $this->DBG("WfsServer->parseXMLRequest() ...", __LINE__);
  64. $document = $wfsServer->parseXMLRequest();
  65. header('Content-type: application/xml');
  66. echo '<?xml version="1.0" encoding="UTF-8"?>';
  67. echo $document; exit;// TODO: return $document;
  68. }
  69. 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>';}
  70. if ('raw' == V::get('outputFormat', '', $request->query)) {
  71. header('Content-type: text/plain; charset=utf-8');
  72. echo $document;
  73. } else {
  74. header('Content-type: application/xml');
  75. echo $document;
  76. }
  77. exit;// TODO: return $document;
  78. }
  79. public function mainWpsAction($request) {
  80. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  81. }
  82. }