|
@@ -1,5 +1,7 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
|
|
+Lib::loadClass('Type_ApiRequest');
|
|
|
|
|
+
|
|
|
class Api {
|
|
class Api {
|
|
|
|
|
|
|
|
private $_apiUser;
|
|
private $_apiUser;
|
|
@@ -19,7 +21,8 @@ class Api {
|
|
|
header('Access-Control-Allow-Origin: https://dev.procesy5.pl');
|
|
header('Access-Control-Allow-Origin: https://dev.procesy5.pl');
|
|
|
// header('Access-Control-Allow-Origin: *');
|
|
// header('Access-Control-Allow-Origin: *');
|
|
|
// header('Access-Control-Max-Age: 86400'); // cache for 1 day
|
|
// header('Access-Control-Max-Age: 86400'); // cache for 1 day
|
|
|
- $request = $this->parseUrl($url);
|
|
|
|
|
|
|
+ $request = Type_ApiRequest::build($url);
|
|
|
|
|
+ $this->_request = $request;
|
|
|
|
|
|
|
|
$apiRouterName = $request->apiRouterName;
|
|
$apiRouterName = $request->apiRouterName;
|
|
|
IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">apiRouterName (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($apiRouterName);echo'</pre>';}
|
|
IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">apiRouterName (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($apiRouterName);echo'</pre>';}
|
|
@@ -28,7 +31,7 @@ class Api {
|
|
|
case 'wfsqgis': $apiRouterName = 'WfsQgis'; break;
|
|
case 'wfsqgis': $apiRouterName = 'WfsQgis'; break;
|
|
|
default: $apiRouterName = ucfirst(strtolower($apiRouterName)); break;
|
|
default: $apiRouterName = ucfirst(strtolower($apiRouterName)); break;
|
|
|
}
|
|
}
|
|
|
- $apiRouterClassName = "Api_{$apiRouterName}";
|
|
|
|
|
|
|
+ $apiRouterClassName = "Api_{$apiRouterName}"; // Api_WfsData, Api_WfsQgis, Api_Wps
|
|
|
if (!Lib::tryLoadClass($apiRouterClassName)) {
|
|
if (!Lib::tryLoadClass($apiRouterClassName)) {
|
|
|
throw new HttpException("Route not exists", 404);
|
|
throw new HttpException("Route not exists", 404);
|
|
|
}
|
|
}
|
|
@@ -42,53 +45,6 @@ class Api {
|
|
|
$this->response($responseDocument);
|
|
$this->response($responseDocument);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function parseUrl($url) {
|
|
|
|
|
- $request = new stdClass();
|
|
|
|
|
- $request->url = trim($url, '/ ');
|
|
|
|
|
- $urlParts = explode('?', $request->url);
|
|
|
|
|
- $request->path = $urlParts[0];
|
|
|
|
|
- $request->query = (count($urlParts) > 1)? $urlParts[1] : '';
|
|
|
|
|
- $request->args = $_REQUEST;
|
|
|
|
|
- $request->segments = array();
|
|
|
|
|
- $urlPathParts = explode('/', $request->path);
|
|
|
|
|
- foreach ($urlPathParts as $part) {
|
|
|
|
|
- if (!empty($part)) $request->segments[] = $part;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- 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>';}
|
|
|
|
|
- $request->format = array_shift($request->segments);
|
|
|
|
|
- if (empty($request->segments)) return null;
|
|
|
|
|
-
|
|
|
|
|
- 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 (!$this->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>';}
|
|
|
|
|
-
|
|
|
|
|
- if (!empty($request->query)) {
|
|
|
|
|
- $queryArgs = array();
|
|
|
|
|
- parse_str($request->query, $queryArgs);
|
|
|
|
|
- $request->query = $queryArgs;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $this->_request = $request;
|
|
|
|
|
- return $this->_request;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private function checkResponseFormat($format) {
|
|
|
|
|
- $allowedTypes = array();
|
|
|
|
|
- $allowedTypes[] = 'xml';
|
|
|
|
|
- $allowedTypes[] = 'json';
|
|
|
|
|
- $allowedTypes[] = 'csv';
|
|
|
|
|
- $allowedTypes[] = 'csv_file';
|
|
|
|
|
- $allowedTypes[] = 'raw';
|
|
|
|
|
- //$allowedTypes[] = 'xml-ns';// xml with namespace
|
|
|
|
|
- return in_array($format, $allowedTypes);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private function response($document) {
|
|
private function response($document) {
|
|
|
if ('xml' == $this->_request->format) {
|
|
if ('xml' == $this->_request->format) {
|
|
|
$this->responseXml($document);
|
|
$this->responseXml($document);
|