KtAPP_Service.inc.php
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
class ktAPP_Service{
const STATUS_OK ='200 OK';
const STATUS_NOT_FOUND ='204 No Content';
const STATUS_NOT_ALLOWED ='204 Not Allowed';
const STATUS_NOT_AUTHENTICATED ='204 Not Authenticated';
const STATUS_CREATED ='201 Created';
const STATUS_UPDATED ='200 Updated';
public $responseFeed=NULL;
public $responseHeader=NULL;
public $method='';
public $params='';
public $rawContent='';
public $parsedXMLContent='';
public function __construct($method,$params,$content){
$this->method=$method;
$this->params=$params;
$this->rawContent=$content;
$this->parsedXMLContent=json_decode(json_encode(@simplexml_load_string($this->rawContent)),true);
$this->setStatus(self::STATUS_OK);
$this->responseFeed=new KTAPPFeed(KT_APP_BASE_URI);
switch(strtoupper($this->method)){
case 'GET': $this->GET_action();break;
case 'PUT': $this->PUT_action();break;
case 'POST': $this->POST_action();break;
case 'DELETE': $this->DELETE_action();break;
}
}
public function GET_action(){
$this->setStatus(ktAPP_Service::STATUS_OK);
}
public function PUT_action(){
$this->setStatus(ktAPP_Service::STATUS_NOT_FOUND );
}
public function POST_action(){
$this->setStatus(ktAPP_Service::STATUS_NOT_FOUND );
}
public function DELETE_action(){
$this->setStatus(ktAPP_Service::STATUS_NOT_FOUND );
}
public function render(){
return $this->responseFeed->render();
}
private function setStatus($status=NULL){
header("HTTP/1.1 ".$status);
}
}
?>