1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Move some Miniflux features to abstract handler

This commit is contained in:
J. King 2020-12-20 22:30:59 -05:00
parent b7ce6f5c79
commit f33359f3e3
2 changed files with 10 additions and 10 deletions

View file

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\REST;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\ValueInfo;
use Psr\Http\Message\ServerRequestInterface;
@ -15,6 +16,15 @@ abstract class AbstractHandler implements Handler {
abstract public function __construct();
abstract public function dispatch(ServerRequestInterface $req): ResponseInterface;
/** @codeCoverageIgnore */
protected function now(): \DateTimeImmutable {
return Date::normalize("now");
}
protected function isAdmin(): bool {
return (bool) Arsse::$user->propertiesGet(Arsse::$user->id, false)['admin'];
}
protected function fieldMapNames(array $data, array $map): array {
$out = [];
foreach ($map as $to => $from) {

View file

@ -116,11 +116,6 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
public function __construct() {
}
/** @codeCoverageIgnore */
protected function now(): \DateTimeImmutable {
return Date::normalize("now");
}
protected function authenticate(ServerRequestInterface $req): bool {
// first check any tokens; this is what Miniflux does
if ($req->hasHeader("X-Auth-Token")) {
@ -143,11 +138,6 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
return false;
}
protected function isAdmin(): bool {
return (bool) Arsse::$user->propertiesGet(Arsse::$user->id, false)['admin'];
}
public function dispatch(ServerRequestInterface $req): ResponseInterface {
// try to authenticate
if (!$this->authenticate($req)) {