| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- // class Type_WpsProcess
- // class Type_WpsProcessInput
- class Type_WpsProcess {
- var $_data = [];
- // @see http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd
- // wps:ProcessDescriptions / ProcessDescription [ @minOccurs=1, @maxOccurs=unbounded ]
- // ProcessDescription / ows:Identifier [ @minOccurs=1, @maxOccurs=1 ]
- // ProcessDescription / ows:Title [ @minOccurs=1, @maxOccurs=1 ]
- // ProcessDescription / ows:Abstract [ @minOccurs=0, @maxOccurs=1 ]
- // ProcessDescription / ows:Metadata [ @xlink:title, @xlink:type, @xlink:href, @about ]
- // ProcessDescription / DataInputs / Input [ @minOccurs=1, @maxOccurs=unbounded ]
- // ProcessDescription / ProcessOutputs / Output [ @minOccurs=1, @maxOccurs=unbounded ]
- // Input / ows:Identifier [ @minOccurs=1, @maxOccurs=1 ]
- // Input / ows:Title [ @minOccurs=1, @maxOccurs=1 ]
- // Input / ows:Abstract [ @minOccurs=0, @maxOccurs=1 ]
- // Input / ( LiteralData | ComplexData | BoundingBoxData )
- // Input / ( LiteralData )
- // Input / ( LiteralData ) / ows:DataType [ @minOccurs=0, @maxOccurs=1, @ows:reference ]
- // Input / ( LiteralData ) / UOMs [ @minOccurs=0, @maxOccurs=1 ]
- // Input / ( LiteralData ) / ( ows:AllowedValues | ows:AnyValue | ValuesReference )
- // Input / ( LiteralData ) / ( ows:AllowedValues )
- // Input / ( LiteralData ) / ( ows:AllowedValues ) / ( ows:Value | ows:Range )
- // Input / ( LiteralData ) / ( ows:AllowedValues ) / ( ows:Value )
- // Input / ( LiteralData ) / ( ows:AllowedValues ) / ( ows:Range ) / [ @ows:MinimumValue, @ows:MaximumValue, @ows:Spacing ]
- // Input / ( LiteralData ) / ( ows:AnyValue )
- // Input / ( LiteralData ) / ( ValuesReference ) / [ @ows:reference, valuesForm anyURI ]
- // Input / ( LiteralData ) / DefaultValue [ @minOccurs=0, @maxOccurs=1 ]
- // Input / ( ComplexData )
- // Input / ( ComplexData ) / Default / Format [ @minOccurs=1, @maxOccurs=1 ]
- // Input / ( ComplexData ) / Supported / Format [ @minOccurs=1, @maxOccurs=unbounded ]
- // Input / ( ComplexData ) / @maximumMegabytes integer
- // Input / ( BoundingBoxData )
- // Input / ( BoundingBoxData ) / Default / CRS anyURI
- // Input / ( BoundingBoxData ) / Supported / CRS anyURI
- // Output / ows:Identifier
- // Output / ows:Title
- // Output / ( ComplexOutput | LiteralOutput | BoundingBoxOutput )
- // Output / ( ComplexOutput )
- // Output / ( ComplexOutput ) / Default / Format [ @minOccurs=1, @maxOccurs=1 ]
- // Output / ( ComplexOutput ) / Supported / Format [ @minOccurs=1, @maxOccurs=unbounded ]
- // Output / ( LiteralOutput )
- // Output / ( LiteralOutput ) / ows:DataType [ @minOccurs=0, @maxOccurs=1 ]
- // Output / ( LiteralOutput ) / UOMs [ @minOccurs=0, @maxOccurs=1 ]
- // Output / ( BoundingBoxOutput )
- // Output / ( BoundingBoxData ) / Default / CRS anyURI
- // Output / ( BoundingBoxData ) / Supported / CRS anyURI
- // Format / MimeType string [ @minOccurs=1, @maxOccurs=1 ]
- // Format / Encoding AnyURI [ @minOccurs=0, @maxOccurs=1 ]
- // Format / Schema AnyURI [ @minOccurs=0, @maxOccurs=1 ]
- // UOMs / ( Default / ows:UOM | Supported / ows:UOM [ @minOccurs=1, @maxOccurs=unbounded ] )
- // ows:UOM string [ @ows:reference ]
- // @ows:reference - URI (local or remote) or URN (like ogc:*, xs:*)
- // example: Output / LiteralOutput / <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#float">float</ows:DataType>
- // example: Input / LiteralData:
- // <ows:DataType ows:reference="xs:float">float</ows:DataType>
- // <ows:AnyValue/>
- // <DefaultValue>1.01</DefaultValue>
- // Type_WpsProcessOutput: [ 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd ]
- // supportedOutput: [ Type_WpsProcessOutput, ... ]
- // [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
- // [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
- // [ 'MimeType' => "application/json" ],
- // [ 'MimeType' => "application/wfs-collection-1.0" ],
- // [ 'MimeType' => "application/wfs-collection-1.1" ],
- // [ 'MimeType' => "application/zip" ],
- 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
- return self::buildProcess($conf);
- }
- static function buildProcess($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->processVersion = V::get('processVersion', '1.0.0', $conf);
- $wpsProcess->dataInputs = array_map([ self, 'buildInput' ], $conf['dataInputs']);
- // $wpsProcess->dataInputs = array_map(function ($input) {
- // return ($input instanceof Type_WpsProcessInput) ? $input : Type_WpsProcessInput::build($input);
- $wpsProcess->defaultOutput = $conf['defaultOutput'];
- $wpsProcess->supportedOutput = $conf['supportedOutput'];
- return $wpsProcess;
- }
- static function buildInput($input) { // @return Type_WpsProcessInput or throw Exception
- return ($input instanceof Type_WpsProcessInput) ? $input : Type_WpsProcessInput::build($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 [
- '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 = []; // $_data['dataType'] === $this->dataType
- // $_data['dataType']: ( 'literal' | 'complex' | 'boundingBox' )
- 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']}'");
- switch ($conf['dataType']) {
- case 'literal': break;
- case 'complex': break;
- case 'boundingBox': break;
- default: throw new Exception("WpsProcessInput parse error - missing input type for '{$conf['identifier']}'");
- }
- }
- static function build($conf) { // @return Type_WpsProcessInput or throw Exception
- return self::buildInput($conf);
- }
- static function buildInput($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->dataType = $conf['dataType']; // 'literal' | 'complex' | 'boundingBox'
- $input->xsdType = V::get('xsdType', '', $conf);
- 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 array_merge(
- [
- 'identifier' => $this->_data['identifier'],
- 'title' => $this->_data['title'],
- 'abstract' => $this->_data['description'],
- 'maxOccurs' => $this->_data['maxOccurs'],
- 'minOccurs' => $this->_data['minOccurs'],
- ],
- ('literal' === $this->dataType) ? [ 'literalData' => $this->_data['literalData'] ] : [],
- ('complex' === $this->dataType) ? [ 'complexData' => $this->_data['complexData'] ] : [],
- ('boundingBox' === $this->dataType) ? [ 'boundingBoxData' => $this->_data['boundingBoxData'] ] : []
- );
- }
- }
|