KT_atom_server.inc.php
2.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
class KT_atom_server{
private $services=array();
private $errors=array();
private $output='';
private $queryArray=array();
private $serviceName='';
private $method='';
private $workspace='';
public function __construct(){
}
public function execute(){
$reqMethod=trim(strtoupper($_SERVER['REQUEST_METHOD']));
$queryArray=split('/',trim($_SERVER['QUERY_STRING'],'/'));
$rawRequest=@file_get_contents('php://input');
$workspace=strtolower(trim($queryArray[0]));
$serviceName=strtolower(trim($queryArray[1]));
$requestParams=array_slice($queryArray,2);
$this->queryArray=$queryArray;
$this->serviceName=$service;
$this->method=$reqMethod;
$this->workspace=$workspace;
if($workspace=='servicedocument'){
$this->serviceDocument();
return;
}
$service=$this->getRegisteredService($workspace,$serviceName);
if(is_array($service)){
$serviceClass=$service['serviceClass'];
echo 'made it';
$serviceObject=new $serviceClass($reqMethod,$requestParams,$rawRequest);
$this->output=$serviceObject->render();
}else{
$serviceObject=new KT_atom_service($requestParams,$rawRequest);
$serviceObject->setStatus(KT_atom_service::STATUS_NOT_FOUND);
$this->output=$serviceObject->render();
}
}
public function registerService($workspace=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){
$workspace=strtolower(trim($workspace));
$serviceName=strtolower(trim($serviceName));
$serviceRecord=array(
'fileName' =>$fileName,
'serviceClass' =>$serviceClass,
'title' =>$title
);
$this->services[$workspace][$serviceName]=$serviceRecord;
}
public function getRegisteredService($workspace,$serviceName=NULL){
$serviceName=strtolower(trim($serviceName));
if(isset($this->services[$workspace][$serviceName]))return $this->services[$workspace][$serviceName];
return false;
}
public function serviceDocument(){
$service=new KT_atom_serviceDoc(KT_APP_BASE_URI);
foreach($this->services as $workspace=>$collection){
//Creating the Default Workspace for use with standard atomPub Clients
$ws=$service->newWorkspace($workspace);
foreach($collection as $serviceName=>$serviceInstance){
$col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws);
}
}
$this->output=$service->getAPPdoc();
}
public function render(){
ob_end_clean();
header('Content-type: text/xml');
echo $this->output;
}
}
?>