-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
75 lines (59 loc) · 2.17 KB
/
index.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
<?php
/**
* Accessibility Advisor API
*
* Jan Bobisud ([email protected])
*
* Department of Computer Graphics and Interaction
* Faculty of Electrical Engineering
* Czech Technical University in Prague
*/
use Nette\Application\Routers\Route,
Nette\Application\Responses\JsonResponse,
Nette\Diagnostics\Debugger,
Nette\Http\IResponse;
// Load Nette Framework
require __DIR__ . '/data/libs/nette.min.php';
// Configure application
$configurator = new Nette\Config\Configurator;
// Enable Nette Debugger for error visualisation & logging
$configurator->enableDebugger(__DIR__ . '/data/log', '[email protected]');
// Create Dependency Injection container
$configurator->setTempDirectory(__DIR__ . '/data/temp');
// Create Robot Loader for class loading
$configurator->createRobotLoader()
->addDirectory(__DIR__ . '/data/model')
->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/data/config/config.neon');
$configurator->addConfig(__DIR__ . '/data/config/config.local.neon');
$container = $configurator->createContainer();
// Setup router using mod_rewrite detection
$container->router[] = new Route('[index.php]', function() {
return 'Accessibility Advisor API';
});
$container->router[] = new Route('<model>[/<id>]', function($model, $id, $presenter) use ($configurator) {
try {
$store = $presenter->context->getService('store');
$query = $presenter->request->getParameters();
$data = NULL;
unset($query['callback']);
unset($query['model']);
unset($query['id']);
if ($id !== NULL) {
$data = $store->{$model}->find($id);
} elseif (isset($query['ids'])) {
$data[$model] = $store->{$model}->findMany($query['ids']);
} else {
$data[$model] = $store->{$model}->findAll($query);
}
return new JsonResponse($data);
} catch (Exception $e) {
if (!$configurator->isDebugMode()) {
Debugger::log($e);
}
return $presenter->error($e->getMessage(), IResponse::S500_INTERNAL_SERVER_ERROR);
}
});
// Run the application!
$container->application->run();