Browse Source

Move some Miniflux features to abstract handler

rpm
J. King 3 years ago
parent
commit
f33359f3e3
  1. 10
      lib/REST/AbstractHandler.php
  2. 10
      lib/REST/Miniflux/V1.php

10
lib/REST/AbstractHandler.php

@ -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) {

10
lib/REST/Miniflux/V1.php

@ -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)) {

Loading…
Cancel
Save