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

Prototype code to check for missing extensions

This is useful in general, but will also provide clear error text if
trying to fork without the posix or pcntl extensions
This commit is contained in:
J. King 2021-07-03 10:23:24 -04:00
parent 3b51d4daea
commit 75e87f31a0
3 changed files with 20 additions and 0 deletions

View file

@ -14,6 +14,7 @@ abstract class AbstractException extends \Exception {
"Exception.arrayEmpty" => 10002, "Exception.arrayEmpty" => 10002,
"ExceptionType.strictFailure" => 10011, "ExceptionType.strictFailure" => 10011,
"ExceptionType.typeUnknown" => 10012, "ExceptionType.typeUnknown" => 10012,
"Exception.extMissing" => 10021,
"Lang/Exception.defaultFileMissing" => 10101, "Lang/Exception.defaultFileMissing" => 10101,
"Lang/Exception.fileMissing" => 10102, "Lang/Exception.fileMissing" => 10102,
"Lang/Exception.fileUnreadable" => 10103, "Lang/Exception.fileUnreadable" => 10103,

View file

@ -28,4 +28,18 @@ class Arsse {
static::$db = static::$db ?? new Database; static::$db = static::$db ?? new Database;
static::$user = static::$user ?? new User; static::$user = static::$user ?? new User;
} }
public static function checkExtensions(string ...$ext): void {
$missing = [];
foreach ($ext as $e) {
if (!extension_loaded($e)) {
$missing[] = $e;
}
}
if ($missing) {
$total = sizeof($missing);
$first = $missing[0];
throw new Exception("extMissing", ['first' => $first, 'total' => $total]);
}
}
} }

View file

@ -80,6 +80,11 @@ return [
}', }',
// indicates programming error // indicates programming error
'Exception.JKingWeb/Arsse/ExceptionType.typeUnknown' => 'Normalization type {0} is not implemented', 'Exception.JKingWeb/Arsse/ExceptionType.typeUnknown' => 'Normalization type {0} is not implemented',
'Exception.JKingWeb/Arsse/Exception.extMissing' => 'The "{first}" PHP extension {total, plural, offset:1
=0 {is}
=1 {and one other extension are}
other {and # other extensions are}
} not installed or not enabled.',
'Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing' => 'Default language file "{0}" missing', 'Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing' => 'Default language file "{0}" missing',
'Exception.JKingWeb/Arsse/Lang/Exception.fileMissing' => 'Language file "{0}" is not available', 'Exception.JKingWeb/Arsse/Lang/Exception.fileMissing' => 'Language file "{0}" is not available',
'Exception.JKingWeb/Arsse/Lang/Exception.fileUnreadable' => 'Insufficient permissions to read language file "{0}"', 'Exception.JKingWeb/Arsse/Lang/Exception.fileUnreadable' => 'Insufficient permissions to read language file "{0}"',