-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.php
More file actions
86 lines (68 loc) · 2.5 KB
/
index.php
File metadata and controls
86 lines (68 loc) · 2.5 KB
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
<?php
/**
* API Kamelott
* MVC API website using Klein.php as router.
*/
/**
* Load composer packages and require controllers files.
*/
require 'vendor/autoload.php';
// Controllers' files
require_once 'controller/controllerUtils.php';
require_once 'controller/controllerAPI.php';
/**
* Set environement.
*/
// Start PHP sessions
session_start();
// Set local datetime
date_default_timezone_set('Europe/Paris');
// Create router
$router = new \Klein\Klein();
// Define applications to be used from any controller
$router->respond(function ($request, $response, $service, $app) {
$app->register('db', function() {
// Config file
include('config.php');
return new \DataManagement\DataManagement('pgsql', $database['host'], $database['port'], $database['dbname'], $database['user'], $database['password']);
});
});
/**
* Declare routes
*/
// Redirect to about page in french
$router->respond('GET', '/', $controllerHome);
// API calls
// Random quotes
$router->respond('GET', '/api/random', $controllerRandom);
// By character
$router->respond('GET', '/api/random/personnage/[:character]', $controllerRandomCharacter);
// By author
$router->respond('GET', '/api/random/auteur/[:author]', $controllerRandomAuthor);
// By season
$router->respond('GET', '/api/random/livre/[i:season]', $controllerRandomSeason);
// By season and character
$router->respond('GET', '/api/random/livre/[i:season]/personnage/[:character]', $controllerRandomSeasonCharacter);
// All quotes
$router->respond('GET', '/api/all', $controllerAll);
// By character
$router->respond('GET', '/api/all/personnage/[:character]', $controllerAllCharacter);
// By author
$router->respond('GET', '/api/all/auteur/[:author]', $controllerAllAuthor);
// By season
$router->respond('GET', '/api/all/livre/[i:season]', $controllerAllSeason);
// By season and character
$router->respond('GET', '/api/all/livre/[i:season]/personnage/[:character]', $controllerAllSeasonCharacter);
// Others
// Get a character's picture
$router->respond('GET', '/api/personnage/[:character]/pic', $controllerCharacterPic);
// Get all characters
$router->respond('GET', '/api/personnage/all', $controllerCharactersAll);
// Get all authors
$router->respond('GET', '/api/auteur/all', $controllerAuthorsAll);
// Sounds
$router->respond('GET', '/api/sounds/[:filename]', $controllerSounds);
// Catch errors
$router->onHttpError($controllerErrors);
// End of routing
$router->dispatch();