WpsProcess.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. // class Type_WpsProcess
  3. // class Type_WpsProcessInput
  4. class Type_WpsProcess {
  5. var $_data = [];
  6. // Type_WpsProcessOutput: [ 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd ]
  7. // supportedOutput: [ Type_WpsProcessOutput, ... ]
  8. // [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
  9. // [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
  10. // [ 'MimeType' => "application/json" ],
  11. // [ 'MimeType' => "application/wfs-collection-1.0" ],
  12. // [ 'MimeType' => "application/wfs-collection-1.1" ],
  13. // [ 'MimeType' => "application/zip" ],
  14. static function validate($conf) {
  15. if (empty($conf['identifier'])) throw new Exception("WpsProcess parse error - missing input identifier");
  16. if (empty($conf['title'])) throw new Exception("WpsProcess parse error - missing input title for '{$conf['identifier']}'");
  17. }
  18. static function build($conf) { // @return Type_WpsProcess or throw Exception
  19. self::validate($conf);
  20. $wpsProcess = new Type_WpsProcess();
  21. $wpsProcess->identifier = $conf['identifier'];
  22. $wpsProcess->title = $conf['title'];
  23. $wpsProcess->description = $conf['description'];
  24. $wpsProcess->processVersion = V::get('processVersion', '1.0.0', $conf);
  25. $wpsProcess->dataInputs = array_map(function ($input) {
  26. return ($input instanceof Type_WpsProcessInput) ? $input : Type_WpsProcessInput::build($input);
  27. }, $conf['dataInputs']);
  28. $wpsProcess->defaultOutput = $conf['defaultOutput'];
  29. $wpsProcess->supportedOutput = $conf['supportedOutput'];
  30. return $wpsProcess;
  31. }
  32. function __isset($name) {
  33. return (array_key_exists($name, $this->_data));
  34. }
  35. function __get($name) {
  36. if (array_key_exists($name, $this->_data)) {
  37. return $this->_data[$name];
  38. }
  39. return null;
  40. }
  41. function __set($name, $value) {
  42. $this->_data[$name] = $value;
  43. }
  44. function toArray() {
  45. return $this->_data;
  46. }
  47. function __toString() {
  48. return str_replace('"', '',
  49. str_replace([ '{', '}', '":', ',"' ], [ '{ ', ' }', ': ', ', ' ], json_encode($this->_data))
  50. );
  51. }
  52. function toWpsJson() {
  53. return [
  54. 'processVersion' => V::get('processVersion', '1.0.0', $this->_data),
  55. 'statusSupported' => false,
  56. 'storeSupported' => false,
  57. 'identifier' => $this->_data['identifier'],
  58. 'title' => $this->_data['title'],
  59. 'abstract' => V::get('description', '', $this->_data),
  60. 'dataInputs' => array_map(function ($input) {
  61. return $input->toWpsJson();
  62. }, $this->_data['dataInputs']),
  63. 'processOutputs' => [ // TODO: multiple outputs?
  64. [
  65. 'identifier' => "result",
  66. 'title' => "result",
  67. 'defaultOutput' => $this->_data['defaultOutput'],
  68. 'supportedOutput' => $this->_data['supportedOutput'],
  69. ],
  70. ]
  71. ];
  72. // { // expected json structure:
  73. // "processVersion": "",
  74. // "statusSupported": false,
  75. // "storeSupported": false,
  76. // "identifier": "p5:selectFeature",
  77. // "title": "Select feature",
  78. // "abstract": "",
  79. // "dataInputs": [{
  80. // "maxOccurs": 1,
  81. // "minOccurs": 1,
  82. // "title": "Feature typeName",
  83. // "abstract": "Feature typeName eg. default_db/PROBLEMS",
  84. // "literalData": {
  85. // "anyValue": true
  86. // }
  87. // }, {
  88. // "maxOccurs": null,
  89. // "minOccurs": 1,
  90. // "title": "Feature primaryKey",
  91. // "abstract": "Feature primaryKey",
  92. // "literalData": {
  93. // "anyValue": true
  94. // }
  95. // }],
  96. // "processOutputs": [{
  97. // "identifier": "result",
  98. // "title": "result",
  99. // "complexOutput": {
  100. // "default": {
  101. // "formats": {
  102. // "text/xml; subtype=wfs-collection/1.0": true
  103. // }
  104. // },
  105. // "supported": {
  106. // "formats": {
  107. // "text/xml; subtype=wfs-collection/1.0": true,
  108. // "text/xml; subtype=wfs-collection/1.1": true,
  109. // "application/json": true
  110. // }
  111. // }
  112. // }
  113. // }]
  114. // }
  115. }
  116. }
  117. class Type_WpsProcessInput {
  118. var $_data = [];
  119. static function validate($conf) {
  120. if (empty($conf['identifier'])) throw new Exception("WpsProcessInput parse error - missing input identifier");
  121. if (empty($conf['title'])) throw new Exception("WpsProcessInput parse error - missing input title for '{$conf['identifier']}'");
  122. }
  123. static function build($conf) { // @return Type_WpsProcessInput or throw Exception
  124. self::validate($conf);
  125. $input = new Type_WpsProcessInput();
  126. $input->identifier = $conf['identifier'];
  127. $input->title = $conf['title'];
  128. $input->description = V::get('description', "", $conf);
  129. $input->maxOccurs = V::get('maxOccurs', 1, $conf, 'maxOccurs');
  130. $input->minOccurs = V::get('minOccurs', 1, $conf, 'minOccurs');
  131. $input->literalData = [ 'anyValue' => true ]; // default string input for all functions
  132. $input->_xsdType = $conf['type']; // for validation
  133. return $input;
  134. }
  135. function __isset($name) {
  136. return (array_key_exists($name, $this->_data));
  137. }
  138. function __get($name) {
  139. if (array_key_exists($name, $this->_data)) {
  140. return $this->_data[$name];
  141. }
  142. return null;
  143. }
  144. function __set($name, $value) {
  145. $this->_data[$name] = $value;
  146. }
  147. function toArray() {
  148. return $this->_data;
  149. }
  150. function __toString() {
  151. return str_replace('"', '',
  152. str_replace([ '{', '}', '":', ',"' ], [ '{ ', ' }', ': ', ', ' ], json_encode($this->_data))
  153. );
  154. }
  155. function toWpsJson() {
  156. return [
  157. 'identifier' => $this->_data['identifier'],
  158. 'title' => $this->_data['title'],
  159. 'abstract' => $this->_data['description'],
  160. 'literalData' => $this->_data['literalData'],
  161. 'maxOccurs' => $this->_data['maxOccurs'],
  162. 'minOccurs' => $this->_data['minOccurs'],
  163. ];
  164. }
  165. }