-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.php
58 lines (44 loc) · 1.35 KB
/
api.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
<?php
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
require_once 'vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$handler_function = function($e) use ($app) {
echo $e;
};
ErrorHandler::register();
$exceptionHandler = ExceptionHandler::register();
$exceptionHandler->setHandler($handler_function);
//This hold all application controllers
$app['controllers']
->assert('playerId', '\d+')
->assert('matchId', '\d+')
->assert('seasonId', '\d+');
//Cause Angular send first an OPTIONS call, this should be used
$app->match("{url}", function($url) use ($app) {
return "OK";
})->assert('url', '.*')->method("OPTIONS");
require_once 'classes-methods/player-methods.php';
require_once 'classes-methods/season-methods.php';
require_once 'classes-methods/match-methods.php';
require_once 'classes-methods/match-player-methods.php';
$app->error(function (\Exception $e, $code) {
return new Response('ERROR: '.$e);
});
function getState($app, $result) {
$httpCode = 200;
if(!is_array($result)) {
$httpCode = 400;
}
// if(count($result) === 0) {
// $httpCode = 404;
// }
return $app->json($result, $httpCode);
}
//run the app to handle the incoming request
//404, 405 responses are handled automatically
$app->run();
?>