url = trim($url, '/ '); $urlParts = explode('?', $request->url); $request->path = $urlParts[0]; $request->query = []; $query = (count($urlParts) > 1)? $urlParts[1] : null; if (!empty($query)) { $queryArgs = []; parse_str($query, $queryArgs); $request->query = $queryArgs; } $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'
url (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'';}
if (empty($segments)) return null;
$request->segments = $segments;
IF(V::get('DBG','',$_GET)>1){echo'responseFormat (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request->format);echo'';}
if (!self::checkResponseFormat($request->format)) {
throw new HttpException("Response format not allowed", 400);
}
IF(V::get('DBG','',$_GET)>1){echo'u (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'';}
$request->apiRouterName = array_shift($request->segments);
IF(V::get('DBG','',$_GET)>1){echo'u (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request);echo'';}
$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);
// }
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))
);
}
}