forked from tiera2/Strykt
/
index.php
51 lines (42 loc) · 1.85 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
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->add(function (Request $request, Response $response, callable $next) {
$uri = $request->getUri();
$path = $uri->getPath();
if ($path != '/' && substr($path, -1) == '/') {
// permanently redirect paths with a trailing slash
// to their non-trailing counterpart
$uri = $uri->withPath(substr($path, 0, -1));
return $response->withRedirect((string)$uri, 301);
}
return $next($request, $response);
});
$app->get('/api/stryktipset', function (Request $request, Response $response) {
$response = $response->withHeader('Content-type', 'application/json');
require 'api/cStryktipsetApi.php';
$response->getBody()->write(StryktipsetApi::getRow());
return $response;
});
$app->get('/api/matches', function (Request $request, Response $response) {
$response = $response->withHeader('Content-type', 'application/json');
require 'api/cMatchesApi.php';
$response->getBody()->write(MatchesApi::getMatches());
return $response;
});
$app->get('/api/matches/{team}', function (Request $request, Response $response, $args) {
$response = $response->withHeader('Content-type', 'application/json');
require 'api/cMatchesApi.php';
$response->getBody()->write(MatchesApi::getTeam($args['team']));
return $response;
});
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("kör denna för att hämta matcher <a href='api/matches'>länk</a><br />
Kör <a href='api/stryktipset'>denna</a> för att hämta stryktipsmatcherna<br />
Hämta Liverpools matcher <a href='api/matches/Liverpool'>här</a><br />
Hämta matcher med Arsenal och Liverpool <a href='api/matches/Liverpool,Arsenal'>här</a>");
return $response;
});
$app->run();