1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/lib/REST/NextcloudNews/Versions.php

41 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\REST\NextcloudNews;
2017-08-29 14:50:31 +00:00
use JKingWeb\Arsse\Misc\HTTP;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Laminas\Diactoros\Response\JsonResponse as Response;
class Versions implements \JKingWeb\Arsse\REST\Handler {
2017-08-29 14:50:31 +00:00
public function __construct() {
}
public function dispatch(ServerRequestInterface $req): ResponseInterface {
if (!preg_match("<^/?$>D", $req->getRequestTarget())) {
// if the request path is more than an empty string or a slash, the client is probably trying a version we don't support
return HTTP::respEmpty(404);
}
switch ($req->getMethod()) {
case "OPTIONS":
// if the request method is OPTIONS, respond accordingly
return HTTP::respEmpty(204, ['Allow' => "HEAD,GET"]);
case "GET":
// otherwise return the supported versions
$out = [
'apiLevels' => [
'v1-2',
2020-03-01 20:16:50 +00:00
],
];
return new Response($out);
default:
// if any other method was used, this is an error
return HTTP::respEmpty(405, ['Allow' => "HEAD,GET"]);
}
}
2017-08-29 14:50:31 +00:00
}