Commit 856ff806638939e5092adc738c8cf7487d7919c6
1 parent
f62f30c2
PT: 865156 - Restructuring AtomPub client to more easily route to services and d…
…eal with HTTP Headers.
Showing
2 changed files
with
184 additions
and
3 deletions
ktatompub/index.php
| ... | ... | @@ -97,9 +97,6 @@ switch(strtolower(trim($query[0]))){ |
| 97 | 97 | case 'document': |
| 98 | 98 | include('services/document.inc.php'); |
| 99 | 99 | break; |
| 100 | - case 'cmis': | |
| 101 | - include('services/cmis/index.php'); | |
| 102 | - break; | |
| 103 | 100 | case 'servicedocument': |
| 104 | 101 | default: |
| 105 | 102 | include('services/servicedocument.inc.php'); | ... | ... |
ktatompub/tools/index.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | + | |
| 4 | +define('KT_APP_BASE_URI',"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/?/'); | |
| 5 | +define('KT_APP_SYSTEM_URI',"http://".$_SERVER['HTTP_HOST']); | |
| 6 | + | |
| 7 | +// Define whether to use in debug mode for viewing generated structures | |
| 8 | +define('KT_APP_WEB_OUTPUT',false); | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Includes | |
| 14 | + */ | |
| 15 | +include_once('../../ktapi/ktapi.inc.php'); | |
| 16 | +include_once('../lib/KTAPPHelper.inc.php'); //Containing helper bridge functions to KtAPI | |
| 17 | +include_once('../lib/KTAPDoc.inc.php'); //Containing the parent class allowing easy XML manipulation | |
| 18 | +include_once('../lib/KTAPPServiceDoc.inc.php'); //Containing the servicedoc class allowing easy ServiceDocument generation | |
| 19 | +include_once('../lib/KTAPPFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation | |
| 20 | +include_once('../auth.php'); //Containing the authentication protocols | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | +class KTAPP{ | |
| 27 | + private $services=array(); | |
| 28 | + private $errors=array(); | |
| 29 | + private $output=''; | |
| 30 | + private $header='200'; | |
| 31 | + | |
| 32 | + private $headerLibrary=array( | |
| 33 | + 200 =>'OK', | |
| 34 | + 201 =>'Created', | |
| 35 | + 204 =>'No Content' | |
| 36 | + ); | |
| 37 | + | |
| 38 | + public function __construct(){ | |
| 39 | + $this->registerService('servicedocument',array($this,'serviceDocument')); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public function switchBoard(){ | |
| 43 | + $reqMethod=trim(strtoupper($_SERVER['REQUEST_METHOD'])); | |
| 44 | + $queryArray=split('/',trim($_SERVER['QUERY_STRING'],'/')); | |
| 45 | + $service=strtolower(trim($queryArray[0])); | |
| 46 | + $requestParams=array_slice($queryArray,1); | |
| 47 | + $this->queryArray=$queryArray; | |
| 48 | + $this->serviceName=$service; | |
| 49 | + $service=$this->getRegisteredService($service); | |
| 50 | + if(is_array($service)){ | |
| 51 | + if($service['fileName'])require_once($service['fileName']); | |
| 52 | + if(is_array($service['serviceFunc'])){ | |
| 53 | + $service['serviceFunc'][0]->$service['serviceFunc'][1]($reqMethod,$requestParams); | |
| 54 | + }else{ | |
| 55 | + $this->output=$service['serviceFunc']($reqMethod,$requestParams); | |
| 56 | + } | |
| 57 | + }else{ | |
| 58 | + echo 'service not found' ; | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + public function registerService($workspace=NULL,$serviceName=NULL,$serviceFunctionName=NULL,$fileName=NULL){ | |
| 63 | + $serviceRecord=array( | |
| 64 | + 'fileName' =>$fileName, | |
| 65 | + 'serviceFunc' =>$serviceFunctionName | |
| 66 | + ); | |
| 67 | + $this->services[$workspace][$serviceName]=$serviceRecord; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public function getRegisteredService($serviceName=NULL){ | |
| 71 | + $serviceName=strtolower(trim($serviceName)); | |
| 72 | + if(isset($this->services[$serviceName]))return $this->services[$serviceName]; | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public function serviceDocument(){ | |
| 77 | + $service=new KTAPPServiceDoc(KT_APP_BASE_URI); | |
| 78 | + | |
| 79 | + //Creating the Default Workspace for use with standard atomPub Clients | |
| 80 | + $ws=$service->newWorkspace('DMS'); | |
| 81 | + | |
| 82 | + foreach($this->services as $serviceName=>$serviceInstance){ | |
| 83 | + $col=$service->newCollection(KT_APP_BASE_URI.$serviceName.'/','',$ws); | |
| 84 | + } | |
| 85 | + | |
| 86 | +/* | |
| 87 | + $col=$service->newCollection(KT_APP_BASE_URI.'fulltree/','Full Document Tree',$ws); | |
| 88 | + $col=$service->newCollection(KT_APP_BASE_URI.'folder/','Folder Detail',$ws); | |
| 89 | + $col=$service->newCollection(KT_APP_BASE_URI.'document/','Document Detail',$ws); | |
| 90 | + $col=$service->newCollection(KT_APP_BASE_URI.'mimetypes/','Supported Mime Types',$ws); | |
| 91 | +*/ | |
| 92 | + | |
| 93 | + $this->output=$service->getAPPdoc(); | |
| 94 | + } | |
| 95 | + | |
| 96 | + public function render(){ | |
| 97 | + //ob_end_clean(); | |
| 98 | + header('Content-type: text/xml'); | |
| 99 | + echo $this->output; | |
| 100 | + } | |
| 101 | +} | |
| 102 | + | |
| 103 | + | |
| 104 | +function KTAPP_service_folder($reqMethod,$reqParams){ | |
| 105 | + //Create a new response feed | |
| 106 | + $feed=new KTAPPFeed(KT_APP_BASE_URI); | |
| 107 | + | |
| 108 | + //Invoke the KtAPI to get detail about the referenced document | |
| 109 | + $folderDetail=KTAPPHelper::getFolderDetail($reqParams[0]?$reqParams[0]:1); | |
| 110 | + | |
| 111 | + //Create the atom response feed | |
| 112 | + $entry=$feed->newEntry(); | |
| 113 | + foreach($folderDetail as $property=>$value){ | |
| 114 | + $feed->newField($property,$value,$entry); | |
| 115 | + } | |
| 116 | + | |
| 117 | + //Generate and set the output | |
| 118 | + return $feed->getAPPdoc(); | |
| 119 | +} | |
| 120 | + | |
| 121 | + | |
| 122 | +function KTAPP_service_fullTree($reqMethod,$reqParams){ | |
| 123 | + //Create a new response feed | |
| 124 | + $feed=new KTAPPFeed(KT_APP_BASE_URI); | |
| 125 | + | |
| 126 | + //Invoke the KtAPI to get detail about the referenced document | |
| 127 | + $tree=KTAPPHelper::getFullTree(); | |
| 128 | + | |
| 129 | + //Create the atom response feed | |
| 130 | + foreach($tree as $item){ | |
| 131 | + $id=$item['id']; | |
| 132 | + $entry=$feed->newEntry(); | |
| 133 | + $feed->newField('id',$id,$entry); | |
| 134 | + foreach($item as $property=>$value){ | |
| 135 | + $feed->newField($property,$value,$entry); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | + | |
| 140 | + //Generate and set the output | |
| 141 | + return $feed->getAPPdoc(); | |
| 142 | +} | |
| 143 | + | |
| 144 | +function KTAPP_service_document($reqMethod,$reqParams){ | |
| 145 | + | |
| 146 | + switch ($reqMethod){ | |
| 147 | + case 'GET': | |
| 148 | + break; | |
| 149 | + case 'PUT': | |
| 150 | + break; | |
| 151 | + case 'POST': | |
| 152 | + break; | |
| 153 | + case 'DELETE': | |
| 154 | + break; | |
| 155 | + } | |
| 156 | + //Create a new response feed | |
| 157 | + $feed=new KTAPPFeed(KT_APP_BASE_URI); | |
| 158 | + | |
| 159 | + //Invoke the KtAPI to get detail about the referenced document | |
| 160 | + $docDetail=KTAPPHelper::getDocumentDetail($reqParams[0]); | |
| 161 | + | |
| 162 | + //Create the atom response feed | |
| 163 | + $entry=$feed->newEntry(); | |
| 164 | + foreach($docDetail['results'] as $property=>$value){ | |
| 165 | + $feed->newField($property,$value,$entry); | |
| 166 | + } | |
| 167 | + //Add a downloaduri field manually | |
| 168 | + $feed->newField('downloaduri',urlencode(KT_APP_SYSTEM_URI.'/action.php?kt_path_info=ktcore.actions.document.view&fDocumentId='.$docDetail['results']['document_id']),$entry); | |
| 169 | + | |
| 170 | + //Generate and set the output | |
| 171 | + return $feed->getAPPdoc(); | |
| 172 | +} | |
| 173 | + | |
| 174 | + | |
| 175 | +$APP=new KTAPP(); | |
| 176 | +$APP->registerService('fulltree','KTAPP_service_fullTree','fasdfasdfasdfasdfa'); | |
| 177 | +$APP->registerService('fulltree',array($obj,'KTAPP_service_fullTree')); | |
| 178 | +$APP->registerService('folder','KTAPP_service_folder'); | |
| 179 | +$APP->registerService('document','KTAPP_service_document'); | |
| 180 | +$APP->switchBoard(); | |
| 181 | +$APP->render(); | |
| 182 | +//echo '<pre>'.print_r($APP,true).'</pre>'; | |
| 183 | + | |
| 184 | +?> | |
| 0 | 185 | \ No newline at end of file | ... | ... |