|
|
@@ -1,5 +1,8 @@
|
|
|
<?php
|
|
|
|
|
|
+// class Type_WpsProcess
|
|
|
+// class Type_WpsProcessInput
|
|
|
+
|
|
|
class Type_WpsProcess {
|
|
|
|
|
|
var $_data = [];
|
|
|
@@ -13,19 +16,19 @@ class Type_WpsProcess {
|
|
|
// [ 'MimeType' => "application/wfs-collection-1.1" ],
|
|
|
// [ 'MimeType' => "application/zip" ],
|
|
|
|
|
|
- static function build($conf) { // @return Type_WpsProcess
|
|
|
+ static function validate($conf) {
|
|
|
+ if (empty($conf['identifier'])) throw new Exception("WpsProcess parse error - missing input identifier");
|
|
|
+ if (empty($conf['title'])) throw new Exception("WpsProcess parse error - missing input title for '{$conf['identifier']}'");
|
|
|
+ }
|
|
|
+ static function build($conf) { // @return Type_WpsProcess or throw Exception
|
|
|
+ self::validate($conf);
|
|
|
$wpsProcess = new Type_WpsProcess();
|
|
|
$wpsProcess->identifier = $conf['identifier'];
|
|
|
$wpsProcess->title = $conf['title'];
|
|
|
$wpsProcess->description = $conf['description'];
|
|
|
- $wpsProcess->maxOccurs = $conf['maxOccurs'];
|
|
|
- $wpsProcess->minOccurs = $conf['minOccurs'];
|
|
|
+ $wpsProcess->processVersion = V::get('processVersion', '1.0.0', $conf);
|
|
|
$wpsProcess->dataInputs = array_map(function ($input) {
|
|
|
- // 'identifier' => $identifier,
|
|
|
- // 'title' => $title,
|
|
|
- // 'description' => $description,
|
|
|
- // 'type' => 'literal',
|
|
|
- return (object)$input;
|
|
|
+ return ($input instanceof Type_WpsProcessInput) ? $input : Type_WpsProcessInput::build($input);
|
|
|
}, $conf['dataInputs']);
|
|
|
$wpsProcess->defaultOutput = $conf['defaultOutput'];
|
|
|
$wpsProcess->supportedOutput = $conf['supportedOutput'];
|
|
|
@@ -57,4 +60,129 @@ class Type_WpsProcess {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ function toWpsJson() {
|
|
|
+ return [
|
|
|
+ 'processVersion' => V::get('processVersion', '1.0.0', $this->_data),
|
|
|
+ 'statusSupported' => false,
|
|
|
+ 'storeSupported' => false,
|
|
|
+ 'identifier' => $this->_data['identifier'],
|
|
|
+ 'title' => $this->_data['title'],
|
|
|
+ 'abstract' => V::get('description', '', $this->_data),
|
|
|
+ 'dataInputs' => array_map(function ($input) {
|
|
|
+ return $input->toWpsJson();
|
|
|
+ }, $this->_data['dataInputs']),
|
|
|
+ 'processOutputs' => [ // TODO: multiple outputs?
|
|
|
+ [
|
|
|
+ 'identifier' => "result",
|
|
|
+ 'title' => "result",
|
|
|
+ 'defaultOutput' => $this->_data['defaultOutput'],
|
|
|
+ 'supportedOutput' => $this->_data['supportedOutput'],
|
|
|
+ ],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ // { // expected json structure:
|
|
|
+ // "processVersion": "",
|
|
|
+ // "statusSupported": false,
|
|
|
+ // "storeSupported": false,
|
|
|
+ // "identifier": "p5:selectFeature",
|
|
|
+ // "title": "Select feature",
|
|
|
+ // "abstract": "",
|
|
|
+ // "dataInputs": [{
|
|
|
+ // "maxOccurs": 1,
|
|
|
+ // "minOccurs": 1,
|
|
|
+ // "title": "Feature typeName",
|
|
|
+ // "abstract": "Feature typeName eg. default_db/PROBLEMS",
|
|
|
+ // "literalData": {
|
|
|
+ // "anyValue": true
|
|
|
+ // }
|
|
|
+ // }, {
|
|
|
+ // "maxOccurs": null,
|
|
|
+ // "minOccurs": 1,
|
|
|
+ // "title": "Feature primaryKey",
|
|
|
+ // "abstract": "Feature primaryKey",
|
|
|
+ // "literalData": {
|
|
|
+ // "anyValue": true
|
|
|
+ // }
|
|
|
+ // }],
|
|
|
+ // "processOutputs": [{
|
|
|
+ // "identifier": "result",
|
|
|
+ // "title": "result",
|
|
|
+ // "complexOutput": {
|
|
|
+ // "default": {
|
|
|
+ // "formats": {
|
|
|
+ // "text/xml; subtype=wfs-collection/1.0": true
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // "supported": {
|
|
|
+ // "formats": {
|
|
|
+ // "text/xml; subtype=wfs-collection/1.0": true,
|
|
|
+ // "text/xml; subtype=wfs-collection/1.1": true,
|
|
|
+ // "application/json": true
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }]
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+class Type_WpsProcessInput {
|
|
|
+
|
|
|
+ var $_data = [];
|
|
|
+
|
|
|
+ static function validate($conf) {
|
|
|
+ if (empty($conf['identifier'])) throw new Exception("WpsProcessInput parse error - missing input identifier");
|
|
|
+ if (empty($conf['title'])) throw new Exception("WpsProcessInput parse error - missing input title for '{$conf['identifier']}'");
|
|
|
+ }
|
|
|
+ static function build($conf) { // @return Type_WpsProcessInput or throw Exception
|
|
|
+ self::validate($conf);
|
|
|
+ $input = new Type_WpsProcessInput();
|
|
|
+ $input->identifier = $conf['identifier'];
|
|
|
+ $input->title = $conf['title'];
|
|
|
+ $input->description = V::get('description', "", $conf);
|
|
|
+ $input->maxOccurs = V::get('maxOccurs', 1, $conf, 'maxOccurs');
|
|
|
+ $input->minOccurs = V::get('minOccurs', 1, $conf, 'minOccurs');
|
|
|
+ $input->literalData = [ 'anyValue' => true ]; // default string input for all functions
|
|
|
+ $input->_xsdType = $conf['type']; // for validation
|
|
|
+ return $input;
|
|
|
+ }
|
|
|
+
|
|
|
+ function __isset($name) {
|
|
|
+ return (array_key_exists($name, $this->_data));
|
|
|
+ }
|
|
|
+
|
|
|
+ function __get($name) {
|
|
|
+ if (array_key_exists($name, $this->_data)) {
|
|
|
+ return $this->_data[$name];
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function __set($name, $value) {
|
|
|
+ $this->_data[$name] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ function toArray() {
|
|
|
+ return $this->_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ function __toString() {
|
|
|
+ return str_replace('"', '',
|
|
|
+ str_replace([ '{', '}', '":', ',"' ], [ '{ ', ' }', ': ', ', ' ], json_encode($this->_data))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ function toWpsJson() {
|
|
|
+ return [
|
|
|
+ 'identifier' => $this->_data['identifier'],
|
|
|
+ 'title' => $this->_data['title'],
|
|
|
+ 'abstract' => $this->_data['description'],
|
|
|
+ 'literalData' => $this->_data['literalData'],
|
|
|
+ 'maxOccurs' => $this->_data['maxOccurs'],
|
|
|
+ 'minOccurs' => $this->_data['minOccurs'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
}
|