-
Notifications
You must be signed in to change notification settings - Fork 9
/
router.php
117 lines (98 loc) · 4.3 KB
/
router.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
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* This file is the router. It's where all calls come in. It will accept a request en refer it to the right Controller
*
* @package The-Datatank
* @copyright (C) 2011 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert
* @author Jan Vansteenlandt
*/
include_once('includes/glue.php');
include_once('includes/rb.php');
include_once('aspects/caching/Cache.class.php');
include_once('aspects/errors/usage/Exceptions.php');
include_once('aspects/errors/system/Exceptions.php');
include_once('aspects/logging/ErrorLogger.class.php');
include_once('controllers/AController.class.php');
include_once('controllers/RController.class.php');
include_once('controllers/SQLController.class.php');
include_once('controllers/SPECTQLController.class.php');
include_once('controllers/SPECTQLIndex.class.php');
include_once('controllers/CUDController.class.php');
include_once('controllers/RedirectController.class.php');
include_once('TDT.class.php'); //general purpose static class
include_once('Config.class.php'); //Configfile
include_once('RequestURI.class.php');
include_once('model/ResourcesModel.class.php');
include_once('model/semantics/OntologyProcessor.class.php');
include_once('model/semantics/RDFOutput.class.php');
define("RDFAPI_INCLUDE_DIR", "model/semantics/rdfapi-php/api/");
include_once(RDFAPI_INCLUDE_DIR . "RdfAPI.php");
include_once(RDFAPI_INCLUDE_DIR . "util/RdfUtil.php");
include_once(RDFAPI_INCLUDE_DIR . "vocabulary/VocabularyRes.php");
include_once(RDFAPI_INCLUDE_DIR . "vocabulary/VocabularyClass.php");
include_once(RDFAPI_INCLUDE_DIR . "resModel/ResModelP.php");
include_once(RDFAPI_INCLUDE_DIR . "model/DBase.php");
// The code for the wrapper_handler is in aspects/logging/ErrorLogger.class.php
set_error_handler('wrapper_handler');
// Time is always in UTC
date_default_timezone_set('UTC');
// Initialize the ORM with the right credentials
R::setup(Config::$DB,Config::$DB_USER,Config::$DB_PASSWORD);
if (!isset($_SERVER['REQUEST_URI'])){
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 );
if (isset($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING'];
}
}
//support for CGI/FastCGI
if (!function_exists('getallheaders' )){
function getallheaders(){
foreach ($_SERVER as $name => $value){
if (substr($name, 0, 5) == 'HTTP_' ) {
$headers[str_replace( ' ', '-', ucwords(strtolower(str_replace('_' , ' ' , substr($name, 5)))))] = $value;
} else if ($name == "CONTENT_TYPE") {
$headers["Content-Type"] = $value;
} else if ($name == "CONTENT_LENGTH") {
$headers["Content-Length"] = $value;
}
}
return $headers;
}
}
//map urls to a classname
$urls = array(
'/spectql/?' => 'SPECTQLIndex',
//When a call is done to the TDTQL end-point, forward it to the TDTQLController
'/spectql(?P<query>/.*)' => 'SPECTQLController',
'/sql\.(?P<format>[^?]+).*' => 'SQLController',
// Calling the Read- controller
// This is a request on the representation
// explanation of the last part of regex:
// continue the REST parameters as long as no . is encountered. Continue format as long as no ? or end of URI occurs
// /package/resource/rest/para/meters.json?para=meter&filt=er
'/(?P<packageresourcestring>.*)\.(?P<format>[^?]+).*' => 'RController',
// Calling the Create, Update, Delete- controllers
// Calling a READ but no format is passed, so we redirect the request towards content negotation
// GET /package/resource - should give a HTTP/1.1 303 See Other to the .about representation
// But also:
// GET /package/ - should give all resources in package in an exception
'/(?P<packageresourcestring>.*)' => 'RedirectController',
// This is a request on the real-world object
// examples of matches:
// PUT TDTAdmin/Admin/package/
// PATCH TDTAdmin/Admin /package/resource/property/
// PUT TDTAdmin/Admin/package/resource
// DELETE TDTAdmin/Admin/package/resource
//'/TDTAdmin/Resources/(?P<package>[^/.]*)/?(?P<resource>[^/.]*)?/?(?P<RESTparameters>[^?.]*)[^.]*' => 'CUDController'
'/TDTAdmin/Resources/(?P<packageresourcestring>.*)' => 'CUDController'
);
//This function will do the magic. See includes/glue.php
try {
glue::stick($urls);
}
catch(Exception $e){
ErrorHandler::logException($e);
}
?>