|
|
@@ -0,0 +1,105 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+class Type_ApiRequest {
|
|
|
+
|
|
|
+ var $_data = [];
|
|
|
+
|
|
|
+ static function build($url) { // @return Type_ApiRequest
|
|
|
+ // GET https://biuro.biall-net.pl/dev-pl/se-master/wps.php?Request=GetCapabilities&identifier=&Service=WPS&Version=1.0.0
|
|
|
+ // $url: /xml/wps?Request=GetCapabilities&identifier=&Service=WPS&Version=1.0.0
|
|
|
+
|
|
|
+ $request = new Type_ApiRequest();
|
|
|
+ $request->url = trim($url, '/ ');
|
|
|
+ $urlParts = explode('?', $request->url);
|
|
|
+ $request->path = $urlParts[0];
|
|
|
+ $request->query = (count($urlParts) > 1)? $urlParts[1] : '';
|
|
|
+ $request->args = $_REQUEST;
|
|
|
+ $segments = array_filter(explode('/', $request->path), function ($part) {
|
|
|
+ return (!empty($part));
|
|
|
+ });
|
|
|
+ $request->format = array_shift($segments);
|
|
|
+ IF(V::get('DBG','',$_GET)>1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">url (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'</pre>';}
|
|
|
+ if (empty($segments)) return null;
|
|
|
+ $request->segments = $segments;
|
|
|
+
|
|
|
+ IF(V::get('DBG','',$_GET)>1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">responseFormat (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request->format);echo'</pre>';}
|
|
|
+ if (!self::checkResponseFormat($request->format)) {
|
|
|
+ throw new HttpException("Response format not allowed", 400);
|
|
|
+ }
|
|
|
+ IF(V::get('DBG','',$_GET)>1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">u (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'</pre>';}
|
|
|
+
|
|
|
+ $request->apiRouterName = array_shift($request->segments);
|
|
|
+ IF(V::get('DBG','',$_GET)>1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">u (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'</pre>';}
|
|
|
+ $request->version = V::geti('version', '', $_REQUEST);
|
|
|
+ // if (!self::checkVersion($request->version, $request->apiRouterName)) { // version may be set in POST body
|
|
|
+ // throw new Exception("{$request->apiRouterName} API Version not supported ({$request->version})", 400);
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (!empty($request->query)) {
|
|
|
+ $queryArgs = array();
|
|
|
+ parse_str($request->query, $queryArgs);
|
|
|
+ $request->query = $queryArgs;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $request;
|
|
|
+ }
|
|
|
+
|
|
|
+ static function checkResponseFormat($format) {
|
|
|
+ $allowedTypes = array();
|
|
|
+ $allowedTypes[] = 'xml';
|
|
|
+ $allowedTypes[] = 'json';
|
|
|
+ $allowedTypes[] = 'csv';
|
|
|
+ $allowedTypes[] = 'csv_file';
|
|
|
+ $allowedTypes[] = 'raw';
|
|
|
+ return in_array($format, $allowedTypes);
|
|
|
+ }
|
|
|
+
|
|
|
+ static function checkVersion($version, $apiName) {
|
|
|
+ switch ($apiName) {
|
|
|
+ case 'wps': return self::checkWPSVersion($version);
|
|
|
+ case 'wfsQgis': return self::checkWFSQgisVersion($version);
|
|
|
+ case 'wfsData': return self::checkWFSDataVersion($version);
|
|
|
+ default: return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ static function checkWPSVersion($version) {
|
|
|
+ switch ($version) {
|
|
|
+ case '1.0.0': return true; // QGIS client
|
|
|
+ case '2.0.0': return false; // TODO: implement WPS 2.0.0 - need working client to test
|
|
|
+ case '2.0.2': return false; // TODO: implement WPS 2.0.0 - need working client to test
|
|
|
+ default: return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ static function checkWFSQgisVersion($version) {
|
|
|
+ return true; // TODO: restrict by version ?
|
|
|
+ }
|
|
|
+ static function checkWFSDataVersion($version) {
|
|
|
+ return true; // TODO: restrict by version ?
|
|
|
+ }
|
|
|
+
|
|
|
+ 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))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+}
|