Wps.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. Lib::loadClass('ApiRouteBase');
  3. Lib::loadClass('Api_WfsException');
  4. Lib::loadClass('Api_WpsV1_Server');
  5. Lib::loadClass('UserAcl');
  6. Lib::loadClass('Api_WfsLogger');
  7. Lib::loadClass('Api_WsdlServer');
  8. Lib::loadClass('Type_ApiRequest');
  9. class Api_Wps extends ApiRouteBase {// TODO: extends Api_WfsBase which extends ApiBase
  10. public $_apiUser;
  11. public $_apiBaseUri;
  12. public function execute(Type_ApiRequest $request) {
  13. $wfsLogger = new Api_WfsLogger();
  14. $this->setLogger($wfsLogger);
  15. $this->reqDBG($request);
  16. // /wfs-data.php/default_db/?... : $request->segments = ['default_db']
  17. // /wfs-data.php/filtr_proces_5040/default_db/?... : $request->segments = ['filtr_proces_5040', 'default_db']
  18. // /wfs-data.php?... : $request->segments = []
  19. // /wfs-data.php/filtr_proces_5040/?... : $request->segments = ['filtr_proces_5040']
  20. // /wfs-data.php/wsdl : $request->segments = ['wsdl']
  21. $serverClass = '';
  22. $version = V::get('version', '1.0.0', $request);
  23. $version = (!$version) ? '1.0.0' : $version;
  24. switch ($version) {
  25. case '1.0.0': $serverClass = 'Api_WpsV1_Server'; break;
  26. default: throw new Exception("WPS API version {$request->version} not supported");
  27. }
  28. // if (!empty($request->segments) && 'wsdl' == $request->segments[0]) {
  29. // $serverClass = 'Api_WsdlServer';
  30. // }
  31. $idFiltrProces = null;
  32. // foreach ($request->segments as $pathPart) {
  33. // if ('filtr_proces_' == substr($pathPart, 0, 13)) {
  34. // $idFiltrProces = (int)substr($pathPart, 13);
  35. // if (!$idFiltrProces) throw new Api_WfsException("Wrong filtr process number");
  36. // $this->DBG("filtr procesu({$idProcesFiltr})", __LINE__, __FUNCTION__, __CLASS__);
  37. // }
  38. // // if ('default_db' == $pathPart) continue;// skip 'default_db'
  39. // // throw new Api_WfsException("Not implemented '{$pathPart}'", 501);// skip all - wsdl work on segments
  40. // }
  41. try {
  42. $this->DBG("Api_WfsData->execute() START", __LINE__);
  43. //$userAcl = User::getAcl();
  44. 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>';}
  45. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  46. $userAcl->fetchGroups();
  47. if ($idFiltrProces) {
  48. if (!$userAcl->canExecuteProcesInit($idFiltrProces)) {
  49. throw new Api_WfsException("Access Denied for given process");
  50. }
  51. $userAcl->fetchProcesPerms($idFiltrProces);
  52. } else {
  53. $userAcl->fetchAllPerms();
  54. }
  55. User::getAcl($userAcl);// force set acl
  56. 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>';}
  57. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  58. $wfsServer = new $serverClass($userAcl); // Api_WpsV1_Server, TODO: Api_WpsV2_Server
  59. $wfsServer->setLogger($this->_logger);
  60. $wfsServer->setBaseUri($this->_apiBaseUri);
  61. $wfsServer->run($request);
  62. exit;// TODO:? return $document;
  63. } catch (Api_OwsException $e) {
  64. DBG::logAuth($e);
  65. $e->sendResponseXml();
  66. } catch (Api_WfsException $e) {
  67. DBG::logAuth($e);
  68. $e->sendResponseXml();
  69. } catch (Exception $e) {
  70. DBG::logAuth($e);
  71. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  72. $wfsException->sendResponseXml();
  73. }
  74. $this->DBG("Api_WfsData->execute() END", __LINE__);
  75. exit;
  76. // return document tree - array of arrays
  77. }
  78. }