-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.SlimOData.php
76 lines (68 loc) · 2.26 KB
/
class.SlimOData.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
<?php
require_once('/var/www/html/Slim/Slim.php');
require 'class.ODataServiceDoc.php';
require 'class.CSDLSchema.php';
require 'class.ODataCollection.php';
\Slim\Slim::registerAutoloader();
class SlimOData extends \Slim\Slim
{
private $serviceDoc;
private $metadataDoc;
function __construct($namespace)
{
parent::__construct();
$this->config('debug', true);
$error_handler = array($this, 'error_handler');
$this->error($error_handler);
$this->get('(/)', array($this, 'displayServiceDoc'));
$this->get('/\$metadata', array($this, 'displayMetadata'));
$this->serviceDoc = new ODataServiceDoc();
$this->metadataDoc = new CSDLSchema($namespace);
}
function error_handler($e)
{
$error = array(
'code' => $e->getCode(),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
);
$this->response->headers->set('Content-Type', 'application/json');
echo json_encode($error);
}
function displayServiceDoc()
{
$fmt = $this->request->headers->get('Accept');
if(strstr($fmt, 'odata.streaming=true'))
{
$this->response->setStatus(406);
return;
}
echo $this->serviceDoc->serialize($fmt, $this);
}
function displayMetadata()
{
$fmt = $this->request->headers->get('Accept');
if(strstr($fmt, 'odata.streaming=true'))
{
$this->response->setStatus(406);
return;
}
echo $this->metadataDoc->serialize($this);
}
public function registerCollection($collection)
{
$this->serviceDoc->registerCollection($collection);
$this->metadataDoc->registerCollection($collection);
$this->get('/'.$collection->getUrl().'(/(:params+))', array($collection, 'get'));
$this->patch('/'.$collection->getUrl().'(/(:params+))', array($collection, 'patch'));
$this->post('/'.$collection->getUrl().'(/(:params+))', array($collection, 'post'));
$collection->registerApp($this);
}
public function overrideServiceDoc($serviceDoc)
{
$this->serviceDoc = $serviceDoc;
}
}
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
?>