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 />\n\tKör <a href='api/stryktipset'>denna</a> för att hämta stryktipsmatcherna<br />\n\tHämta Liverpools matcher <a href='api/matches/Liverpool'>här</a><br />\n\tHämta matcher med Arsenal och Liverpool <a href='api/matches/Liverpool,Arsenal'>här</a>"); return $response; }); $app->run();
}); $app->group('/api/matches', function () { require 'app/api/cMatchesApi.php'; header("Content-Type: application/json"); $this->get('', function (Request $request, Response $response) { flush(); return MatchesApi::getMatches(); })->setName('matches'); $this->get('/{team}', function (Request $request, Response $response, $args) { $limit = null; $parm = $request->getQueryParams(); if (array_key_exists('limit', $parm)) { $limit = intval($parm['limit']); } flush(); return MatchesApi::getTeam($args['team'], $limit); })->setName('matches-team'); }); $app->get('/api/tables', function (Request $request, Response $response, $args) { $response = $response->withHeader('Content-type', 'application/json'); require 'app/api/cTablesApi.php'; $table = TablesApi::getPremierLeagueTable(); $response->getBody()->write($table); return $response; }); $app->get('/stryktipset', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents("webInterface/views/stryktipsView.html")); return $response; }); $app->get('/matches', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents("webInterface/views/matchesView.html"));