add seiralmanager #66
This commit is contained in:
@@ -4,7 +4,10 @@ namespace api;
|
|||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
include_once PATH_DATABASE . "/SQLManager.php";
|
include_once PATH_DATABASE . "/SQLManager.php";
|
||||||
|
include_once PATH_UTILITTY . "/XmlManager.php";
|
||||||
|
include_once PATH_UTILITTY . "/JsonManager.php";
|
||||||
require_once PATH_3PARTY . "/Slim/Slim.php";
|
require_once PATH_3PARTY . "/Slim/Slim.php";
|
||||||
|
|
||||||
\Slim\Slim::registerAutoloader();
|
\Slim\Slim::registerAutoloader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,15 +23,29 @@ abstract class Api extends \Slim\Slim {
|
|||||||
*/
|
*/
|
||||||
protected $sqlManager;
|
protected $sqlManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable for the serialazarion manager of the api
|
||||||
|
* @var <T>:SqlManager
|
||||||
|
*/
|
||||||
|
protected $serialManager;
|
||||||
|
protected static $contentypeXML = "application/xml;charset=utf-8";
|
||||||
|
protected static $contentypeJson = "application/json;charset=utf-8";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default-Constructor
|
* Default-Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct($headers = array()) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
// set content type td xml
|
// set content type td xml
|
||||||
$this->contentType("Content-type: application/xml;charset=utf-8");
|
if ($headers && preg_match('/json/', $headers["Accept"])) {
|
||||||
|
$this->serialManager = new \utiliy\JsonManager();
|
||||||
|
$this->contentType(self::$contentypeJson);
|
||||||
|
} else {
|
||||||
|
$this->serialManager = new \utiliy\XmlManager();
|
||||||
|
$this->contentType(self::$contentypeXML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,10 +53,10 @@ abstract class Api extends \Slim\Slim {
|
|||||||
*/
|
*/
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
|
|
||||||
// destroy the sqlManager
|
// destroy the sqlManager
|
||||||
$this->sqlManager->closeConnection();
|
$this->sqlManager->closeConnection();
|
||||||
unset($this->sqlManager);
|
unset($this->sqlManager);
|
||||||
$this->sqlManager = null;
|
unset($this->serialManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace api;
|
|||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
include_once PATH_DATABASE . "/PisSqlManager.php";
|
include_once PATH_DATABASE . "/PisSqlManager.php";
|
||||||
include_once PATH_UTILITTY . "/XmlManager.php";
|
|
||||||
include_once PATH_UTILITTY . "/ArrayManager.php";
|
include_once PATH_UTILITTY . "/ArrayManager.php";
|
||||||
require_once PATH_API . "/Api.php";
|
require_once PATH_API . "/Api.php";
|
||||||
|
|
||||||
@@ -30,9 +29,9 @@ class PisApi extends Api {
|
|||||||
/**
|
/**
|
||||||
* Default-Constructor
|
* Default-Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct($headers = array()) {
|
||||||
$this->sqlManager = new \database\PisSqlManager();
|
$this->sqlManager = new \database\PisSqlManager();
|
||||||
parent::__construct();
|
parent::__construct($headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +50,8 @@ class PisApi extends Api {
|
|||||||
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
|
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
|
||||||
if (count($pidList) < $this->maxPid) {
|
if (count($pidList) < $this->maxPid) {
|
||||||
$result = $this->sqlManager->sendPisQuery($pidList);
|
$result = $this->sqlManager->sendPisQuery($pidList);
|
||||||
return \utiliy\XmlManager::arrayToPisXml($result);
|
|
||||||
|
return $this->serialManager->arrayToPis($result);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ class PssApi extends Api {
|
|||||||
/**
|
/**
|
||||||
* Default-Constructor
|
* Default-Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct($headers = array()) {
|
||||||
$this->sqlManager = new \database\PssSqlManager();
|
$this->sqlManager = new \database\PssSqlManager();
|
||||||
parent::__construct();
|
parent::__construct($headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ class PssApi extends Api {
|
|||||||
|
|
||||||
if (count($pidList) < $this->maxPid) {
|
if (count($pidList) < $this->maxPid) {
|
||||||
$result = $this->sqlManager->sendPssQuery($pidList);
|
$result = $this->sqlManager->sendPssQuery($pidList);
|
||||||
return \utiliy\XmlManager::arrayToPssXml($result);
|
return $this->serialManager->arrayTopis($result);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace api;
|
|||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
include_once PATH_DATABASE . "/SpsSqlManager.php";
|
include_once PATH_DATABASE . "/SpsSqlManager.php";
|
||||||
include_once PATH_UTILITTY . "/XmlManager.php";
|
|
||||||
require_once PATH_API . "/Api.php";
|
require_once PATH_API . "/Api.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,9 +112,9 @@ class SpsApi extends Api {
|
|||||||
/**
|
/**
|
||||||
* Default-Constructor
|
* Default-Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct($headers = array()) {
|
||||||
$this->sqlManager = new \database\SpsSqlManager();
|
$this->sqlManager = new \database\SpsSqlManager();
|
||||||
parent::__construct();
|
parent::__construct($headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +131,7 @@ class SpsApi extends Api {
|
|||||||
*/
|
*/
|
||||||
public function sendSpsAliasQuery($queryArgs) {
|
public function sendSpsAliasQuery($queryArgs) {
|
||||||
$result = $this->sqlManager->sendSpsAliasQuery($queryArgs);
|
$result = $this->sqlManager->sendSpsAliasQuery($queryArgs);
|
||||||
return \utiliy\XmlManager::arrayToSpsXml($result);
|
return $this->serialManager->arrayToSps($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,7 +157,7 @@ class SpsApi extends Api {
|
|||||||
|
|
||||||
// send querry
|
// send querry
|
||||||
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
|
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
|
||||||
return \utiliy\XmlManager::arrayToSpsXml($result);
|
return $this->serialManager->arrayToSps($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
require_once PATH_API . "/PisApi.php";
|
require_once PATH_API . "/PisApi.php";
|
||||||
|
|
||||||
|
$headers = apache_request_headers();
|
||||||
// instance a new api
|
// instance a new api
|
||||||
$app = new \api\PisApi();
|
$app = new \api\PisApi($headers);
|
||||||
|
|
||||||
// HTTP-Get-Method
|
// HTTP-Get-Method
|
||||||
$app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) {
|
$app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
require_once PATH_API . "/PssApi.php";
|
require_once PATH_API . "/PssApi.php";
|
||||||
|
|
||||||
|
$headers = apache_request_headers();
|
||||||
// instance a new api
|
// instance a new api
|
||||||
$app = new \api\PssApi();
|
$app = new \api\PssApi($headers);
|
||||||
|
|
||||||
// HTTP-Get-Method
|
// HTTP-Get-Method
|
||||||
$app->get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) {
|
$app->get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) {
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
require_once PATH_API . "/SpsApi.php";
|
require_once PATH_API . "/SpsApi.php";
|
||||||
|
$headers = apache_request_headers();
|
||||||
|
|
||||||
// instance a new api
|
// instance a new api
|
||||||
$app = new \api\SpsApi();
|
$app = new \api\SpsApi($headers);
|
||||||
|
|
||||||
// HTTP-Get-Methods
|
// HTTP-Get-Methods
|
||||||
$app->get(\api\SpsApi::$routeParameterAlias, function ($alias) use ($app) {
|
$app->get(\api\SpsApi::$routeParameterAlias, function ($alias) use ($app) {
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
namespace utiliy;
|
namespace utiliy;
|
||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
|
require_once PATH_UTILITTY . "/SerialManager.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The XmlManager provides some xml-methods
|
* The XmlManager provides some xml-methods
|
||||||
* @author stubbfel
|
* @author stubbfel
|
||||||
* @since 25.06.2013
|
* @since 25.06.2013
|
||||||
*/
|
*/
|
||||||
class JsonManager {
|
class JsonManager implements SerialManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name for the sap item
|
* Name for the sap item
|
||||||
@@ -93,7 +94,7 @@ class JsonManager {
|
|||||||
|
|
||||||
// add placeinformation item
|
// add placeinformation item
|
||||||
$placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName],
|
$placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName],
|
||||||
JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
|
JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
|
||||||
array_push($place, $placeInfo);
|
array_push($place, $placeInfo);
|
||||||
}
|
}
|
||||||
return json_encode($infos);
|
return json_encode($infos);
|
||||||
@@ -130,6 +131,18 @@ class JsonManager {
|
|||||||
return json_encode($services);
|
return json_encode($services);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function arrayToSps($result) {
|
||||||
|
return JsonManager::arrayToSpsJson($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrayToPss($result) {
|
||||||
|
return JsonManager::arrayToPssJson($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrayToPis($result) {
|
||||||
|
return JsonManager::arrayToPisJson($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
15
geoapi/utility/SerialManager.php
Normal file
15
geoapi/utility/SerialManager.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
namespace utiliy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author stubbfel
|
||||||
|
*/
|
||||||
|
interface SerialManager {
|
||||||
|
|
||||||
|
public function arrayToSps($result);
|
||||||
|
public function arrayToPis($result);
|
||||||
|
public function arrayToPss($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -3,13 +3,14 @@
|
|||||||
namespace utiliy;
|
namespace utiliy;
|
||||||
|
|
||||||
include_once "../../global.inc.php";
|
include_once "../../global.inc.php";
|
||||||
|
require_once PATH_UTILITTY . "/SerialManager.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The XmlManager provides some xml-methods
|
* The XmlManager provides some xml-methods
|
||||||
* @author stubbfel
|
* @author stubbfel
|
||||||
* @since 25.06.2013
|
* @since 25.06.2013
|
||||||
*/
|
*/
|
||||||
class XmlManager {
|
class XmlManager implements SerialManager{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a default xml document
|
* a default xml document
|
||||||
@@ -158,6 +159,18 @@ class XmlManager {
|
|||||||
return $xml->asXML();
|
return $xml->asXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function arrayToSps($result) {
|
||||||
|
return XmlManager::arrayToSpsXml($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrayToPis($result){
|
||||||
|
return XmlManager::arrayToPisXml($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrayToPss($result) {
|
||||||
|
return XmlManager::arrayToPssXml($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user