forked from iRail/The-DataTank-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
101 lines (83 loc) · 3.11 KB
/
app.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
<?php
require 'Slim/Slim.php';
require 'TwigView.php';
require 'rb.php';
require 'models.php';
require 'serializer.php';
//require 'Config.class.php';
require 'TDT.class.php';
require 'caching/Cache.class.php';
//require 'SlimConfig.class.php';
require 'config.php';
$app = new Slim($appConfigDevelopment);
$app->setName('TheDataTank');
$app->configureMode('production', function() use ($app, $appConfigProduction) {
$app->config($appConfigProduction);
});
$app->configureMode('development', function() use ($app, $appConfigDevelopment) {
$app->config($appConfigDevelopment);
});
R::setup($app->config('database.dsn'),
$app->config('database.user'),
$app->config('database.password')
);
// This handler prints config values used by the javascript app.
$app->get('/ui-config.js', function() use ($app) {
print('var TDT_URL = "' . $app->config('tdt-url') . '";;');
$app->response()->header('Content-Type', 'application/javascript');
});
$app->get('/', function() use ($app) {
$app->render('index.html',
array('static' => $app->config('static'), 'subdir' => $app->config('subdir')));
});
$app->get('/docs', function() use ($app) {
$url = $app->config('hostname') . '/TDTInfo/Resources.json';
TDT::HttpRequest($url);
$docs = json_decode(TDT::HttpRequest($url)->data);
$modules = array();
if (is_object($docs)) {
$ms = get_object_vars($docs);
foreach($ms as $name => $rs) {
$resources = array();
$rsv = get_object_vars($rs);
foreach($rsv as $rname => $resource) {
$resources[$rname] = $resource->doc;
}
$modules[$name] = $resources;
}
}
$app->render('docs.html',
array('static' => $app->config('static'), 'subdir' => $app->config('subdir'),
'modules' => $modules));
});
$app->get('/docs/:module/:resource', function($module, $resource) use ($app) {
$url = $app->config('hostname') . "/TDTInfo/Resources/$module/$resource.json";
$r = json_decode(TDT::HttpRequest($url)->data);
//get a sequence of the parameters
$parameters = array();
foreach($r->parameters as $var => $doc) {
$parameters[$var] = $doc;
}
$args = '';
if ($r->requiredparameters > 0) {
foreach($r->requiredparameters as $var) {
$args .= "%$var%/";
}
}
// build the proper URL's to invoke when doing a call for a certain resource
$url = $app->config('hostname') . $app->config('subdir') . "/$module/$resource/$args";
$app->render('doc.html',
array('static' => $app->config('static'), 'subdir' => $app->config('subdir'),
'module' => $module, 'resource' => $resource, 'url' => $url,
'parameters' => $parameters, 'doc' => $r->doc));
});
$app->get('/stats', function() use ($app) {
$app->render('stats.html',
array('static' => $app->config('static'), 'subdir' => $app->config('subdir')));
});
$app->get('/admin', function() use ($app) {
$app->render('admin.html',
array('static' => $app->config('static'), 'subdir' => $app->config('subdir')));
});
require 'api.php';
$app->run();