mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Fail gracefully when extensions are missing
This still needs tests
This commit is contained in:
parent
c9a2393a4e
commit
c49cb72528
4 changed files with 25 additions and 3 deletions
|
@ -8,6 +8,15 @@ namespace JKingWeb\Arsse;
|
|||
|
||||
class Arsse {
|
||||
public const VERSION = "0.9.2";
|
||||
public const REQUIRED_EXTENSIONS = [
|
||||
"intl", // as this extension is required to prepare formatted messages, its absence will throw a distinct English-only exception
|
||||
"dom",
|
||||
"filter",
|
||||
"json", // part of the PHP core since version 8.0
|
||||
"hash", // part of the PHP core since version 7.4
|
||||
"simplexml", // required by PicoFeed only
|
||||
"iconv", // required by PicoFeed only
|
||||
];
|
||||
|
||||
/** @var Factory */
|
||||
public static $obj;
|
||||
|
@ -29,6 +38,7 @@ class Arsse {
|
|||
static::$user = static::$user ?? new User;
|
||||
}
|
||||
|
||||
/** Checks whether the specified extensions are loaded and throws an exception if any are not */
|
||||
public static function checkExtensions(string ...$ext): void {
|
||||
$missing = [];
|
||||
foreach ($ext as $e) {
|
||||
|
|
|
@ -80,11 +80,15 @@ USAGE_TEXT;
|
|||
'help' => false,
|
||||
]);
|
||||
try {
|
||||
// ensure the require extensions are loaded
|
||||
Arsse::checkExtensions(...Arsse::REQUIRED_EXTENSIONS);
|
||||
// reconstitute multi-token commands (e.g. user add) into a single string
|
||||
$cmd = $this->command($args);
|
||||
if ($cmd && !in_array($cmd, ["", "conf save-defaults", "daemon"])) {
|
||||
// only certain commands don't require configuration to be loaded; daemon loads configuration after forking (if applicable)
|
||||
$this->loadConf();
|
||||
}
|
||||
// run the requested command
|
||||
switch ($cmd) {
|
||||
case "":
|
||||
if ($args['--version']) {
|
||||
|
|
|
@ -80,10 +80,12 @@ class REST {
|
|||
}
|
||||
|
||||
public function dispatch(ServerRequestInterface $req = null): ResponseInterface {
|
||||
try {
|
||||
// ensure the require extensions are loaded
|
||||
Arsse::checkExtensions(...Arsse::REQUIRED_EXTENSIONS);
|
||||
// create a request object if not provided
|
||||
$req = $req ?? ServerRequestFactory::fromGlobals();
|
||||
// find the API to handle
|
||||
try {
|
||||
[$api, $target, $class] = $this->apiMatch($req->getRequestTarget(), $this->apis);
|
||||
// authenticate the request pre-emptively
|
||||
$req = $this->authenticateRequest($req);
|
||||
|
|
|
@ -7,9 +7,15 @@ declare(strict_types=1);
|
|||
namespace JKingWeb\Arsse\Service;
|
||||
|
||||
use JKingWeb\Arsse\AbstractException;
|
||||
use JKingWeb\Arsse\Arsse;
|
||||
|
||||
class Daemon {
|
||||
protected const PID_PATTERN = '/^([1-9]\d{0,77})?$/D'; // no more than 78 digits (256-bit unsigned integer), starting with a digit other than zero
|
||||
protected const REQUIRED_EXTENSIONS = ["posix", "pcntl"];
|
||||
|
||||
public function __construct() {
|
||||
Arsse::checkExtensions(...self::REQUIRED_EXTENSIONS);
|
||||
}
|
||||
|
||||
/** Daemonizes the process via the traditional sysvinit double-fork procedure
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue