-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.php
105 lines (93 loc) · 3.91 KB
/
rest.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Openbiz Cubi Application Platform
*
* LICENSE http://code.google.com/p/openbiz-cubi/wiki/CubiLicense
*
* @package \
* @copyright Copyright (c) 2005-2011, Openbiz Technology LLC
* @license http://code.google.com/p/openbiz-cubi/wiki/CubiLicense
* @link http://code.google.com/p/openbiz-cubi/
* @version $Id$
*/
/* cubi rest web service entry point
request example:
url
http://host/cubi/rest.php/system/users?start=10&limit=10
*/
include_once 'bin/app_init.php';
include_once OPENBIZ_HOME."/bin/ErrorHandler.php";
require 'bin/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
// GET with query
$app->get('/:module/:resource/q', function ($module,$resource) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->query($resource, $app->request(), $app->response());
});
$app->get('/:module/:resource/:id/:childresource/q', function ($module,$resource,$id,$childresource) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->queryChildren($resource, $id, $childresource, $app->request(), $app->response());
});
// GET request
$app->get('/:module/:resource/:id', function ($module,$resource,$id) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->get($resource, $id, $app->request(), $app->response());
});
// POST request
$app->post('/:module/:resource/', function ($module,$resource) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->post($resource, $app->request(), $app->response());
});
// by default angular use POST instead of PUT to update data
$app->post('/:module/:resource/:id/:childresource', function ($module,$resource,$id,$childresource) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->putChildren($resource, $id, $childresource, $app->request(), $app->response());
});
$app->post('/:module/:resource/:id', function ($module,$resource,$id) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->put($resource, $id, $app->request(), $app->response());
});
/*// PUT request
$app->put('/:module/:resource/:id', function ($module,$resource,$id) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->put($resource, $id, $app->request(), $app->response());
});*/
// DELETE request
$app->delete('/:module/:resource/:id/:childresource/:childid', function ($module,$resource,$id,$childresource,$childid) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->deleteChild($resource, $id, $childresource, $childid, $app->request(), $app->response());
});
$app->delete('/:module/:resource/:id', function ($module,$resource,$id) {
$app = \Slim\Slim::getInstance();
// forward to module rest service implementation
$restServiceName = $module.".websvc."."RestService";
$restSvc = BizSystem::getObject($restServiceName);
$restSvc->delete($resource, $id, $app->request(), $app->response());
});
$app->run();
?>