Wps.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. switch ($version) {
  24. case '1.0.0': $serverClass = 'Api_WpsV1_Server'; break;
  25. default: throw new Exception("WPS API version {$request->version} not supported");
  26. }
  27. // if (!empty($request->segments) && 'wsdl' == $request->segments[0]) {
  28. // $serverClass = 'Api_WsdlServer';
  29. // }
  30. $idFiltrProces = null;
  31. // foreach ($request->segments as $pathPart) {
  32. // if ('filtr_proces_' == substr($pathPart, 0, 13)) {
  33. // $idFiltrProces = (int)substr($pathPart, 13);
  34. // if (!$idFiltrProces) throw new Api_WfsException("Wrong filtr process number");
  35. // $this->DBG("filtr procesu({$idProcesFiltr})", __LINE__, __FUNCTION__, __CLASS__);
  36. // }
  37. // // if ('default_db' == $pathPart) continue;// skip 'default_db'
  38. // // throw new Api_WfsException("Not implemented '{$pathPart}'", 501);// skip all - wsdl work on segments
  39. // }
  40. try {
  41. $this->DBG("Api_WfsData->execute() START", __LINE__);
  42. //$userAcl = User::getAcl();
  43. 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>';}
  44. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  45. $userAcl->fetchGroups();
  46. if ($idFiltrProces) {
  47. if (!$userAcl->canExecuteProcesInit($idFiltrProces)) {
  48. throw new Api_WfsException("Access Denied for given process");
  49. }
  50. $userAcl->fetchProcesPerms($idFiltrProces);
  51. } else {
  52. $userAcl->fetchAllPerms();
  53. }
  54. User::getAcl($userAcl);// force set acl
  55. 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>';}
  56. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  57. $wfsServer = new $serverClass($userAcl); // Api_WpsV1_Server, TODO: Api_WpsV2_Server
  58. $wfsServer->setLogger($this->_logger);
  59. $wfsServer->setBaseUri($this->_apiBaseUri);
  60. $wfsServer->run($request);
  61. exit;// TODO:? return $document;
  62. } catch (Api_WfsException $e) {
  63. DBG::logAuth($e);
  64. $e->sendResponseXml();
  65. } catch (Exception $e) {
  66. DBG::logAuth($e);
  67. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  68. $wfsException->sendResponseXml();
  69. }
  70. $this->DBG("Api_WfsData->execute() END", __LINE__);
  71. exit;
  72. // return document tree - array of arrays
  73. }
  74. }