forked from sin0light/api-kaamelott
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
81 lines (66 loc) · 2.67 KB
/
index.php
File metadata and controls
81 lines (66 loc) · 2.67 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
<?php
// Slims' Ressources
require 'vendor/autoload.php';
// Kaamelott's lib
require 'lib/lib-kaamelott/kaamelott.class.php';
$kaamelott = new kaamelott;
// Create Your container
$c = new \Slim\Container();
// Override the default Not Found Handler
$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
$return['status'] = 0;
$return['error'] = 'Chemin inconnu';
return $c['response']
->withStatus(404)
->withJson($return);
};
};
// Declaring the router
$app = new Slim\App($c);
// Home page
$app->get('/', function ($request, $response, $args) {
return $response->write(file_get_contents('./home.html'));
});
// One random quote without filter
$app->map(['GET', 'POST'], '/api/random', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->random());
});
// One random quote from one designated season
$app->map(['GET', 'POST'], '/api/random/livre/{livre}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->randomLivre($args['livre']));
});
// One random quote from one designated character
$app->map(['GET', 'POST'], '/api/random/personnage/{personnage}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->randomPersonnage($args['personnage']));
});
// One random quote from one designated season and character
$app->map(['GET', 'POST'], '/api/random/livre/{livre}/personnage/{personnage}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->randomLivrePersonnage($args['livre'], $args['personnage']));
});
// All the quotes without filter
$app->map(['GET', 'POST'], '/api/all', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->all());
});
// All the quotes from one designated season
$app->map(['GET', 'POST'], '/api/all/livre/{livre}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->allLivre($args['livre']));
});
// All the quotes from one designated character
$app->map(['GET', 'POST'], '/api/all/personnage/{personnage}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->allPersonnage($args['personnage']));
});
// All the quotes from one designated season and character
$app->map(['GET', 'POST'], '/api/all/livre/{livre}/personnage/{personnage}', function ($request, $response, $args) {
global $kaamelott;
return $response->withJson($kaamelott->allLivrePersonnage($args['livre'], $args['personnage']));
});
$app->run();
?>