add seiralmanager #66

This commit is contained in:
stubbfel
2013-07-01 17:47:45 +02:00
parent 802b561187
commit aa03fdcd1b
10 changed files with 83 additions and 23 deletions

View File

@@ -4,7 +4,10 @@ namespace api;
include_once "../../global.inc.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";
\Slim\Slim::registerAutoloader();
/**
@@ -20,15 +23,29 @@ abstract class Api extends \Slim\Slim {
*/
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
*/
public function __construct() {
public function __construct($headers = array()) {
$this->connect();
parent::__construct();
// set content type td xml
$this->contentType("Content-type: application/xml;charset=utf-8");
// set content type td xml
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() {
// destroy the sqlManager
// destroy the sqlManager
$this->sqlManager->closeConnection();
unset($this->sqlManager);
$this->sqlManager = null;
unset($this->serialManager);
}
/**

View File

@@ -4,7 +4,6 @@ namespace api;
include_once "../../global.inc.php";
include_once PATH_DATABASE . "/PisSqlManager.php";
include_once PATH_UTILITTY . "/XmlManager.php";
include_once PATH_UTILITTY . "/ArrayManager.php";
require_once PATH_API . "/Api.php";
@@ -30,9 +29,9 @@ class PisApi extends Api {
/**
* Default-Constructor
*/
public function __construct() {
public function __construct($headers = array()) {
$this->sqlManager = new \database\PisSqlManager();
parent::__construct();
parent::__construct($headers);
}
/**
@@ -51,7 +50,8 @@ class PisApi extends Api {
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
if (count($pidList) < $this->maxPid) {
$result = $this->sqlManager->sendPisQuery($pidList);
return \utiliy\XmlManager::arrayToPisXml($result);
return $this->serialManager->arrayToPis($result);
}
return NULL;
}

View File

@@ -30,9 +30,9 @@ class PssApi extends Api {
/**
* Default-Constructor
*/
public function __construct() {
public function __construct($headers = array()) {
$this->sqlManager = new \database\PssSqlManager();
parent::__construct();
parent::__construct($headers);
}
/**
@@ -52,7 +52,7 @@ class PssApi extends Api {
if (count($pidList) < $this->maxPid) {
$result = $this->sqlManager->sendPssQuery($pidList);
return \utiliy\XmlManager::arrayToPssXml($result);
return $this->serialManager->arrayTopis($result);
}
return NULL;
}

View File

@@ -4,7 +4,6 @@ namespace api;
include_once "../../global.inc.php";
include_once PATH_DATABASE . "/SpsSqlManager.php";
include_once PATH_UTILITTY . "/XmlManager.php";
require_once PATH_API . "/Api.php";
/**
@@ -113,9 +112,9 @@ class SpsApi extends Api {
/**
* Default-Constructor
*/
public function __construct() {
public function __construct($headers = array()) {
$this->sqlManager = new \database\SpsSqlManager();
parent::__construct();
parent::__construct($headers);
}
/**
@@ -132,7 +131,7 @@ class SpsApi extends Api {
*/
public function 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
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
return \utiliy\XmlManager::arrayToSpsXml($result);
return $this->serialManager->arrayToSps($result);
}
/**