From 75e87f31a06d8ed01204d018e7125d2c52bc532c Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 3 Jul 2021 10:23:24 -0400 Subject: [PATCH] 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 --- lib/AbstractException.php | 1 + lib/Arsse.php | 14 ++++++++++++++ locale/en.php | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/lib/AbstractException.php b/lib/AbstractException.php index 501634d..cde92dc 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -14,6 +14,7 @@ abstract class AbstractException extends \Exception { "Exception.arrayEmpty" => 10002, "ExceptionType.strictFailure" => 10011, "ExceptionType.typeUnknown" => 10012, + "Exception.extMissing" => 10021, "Lang/Exception.defaultFileMissing" => 10101, "Lang/Exception.fileMissing" => 10102, "Lang/Exception.fileUnreadable" => 10103, diff --git a/lib/Arsse.php b/lib/Arsse.php index 331944a..ec04d24 100644 --- a/lib/Arsse.php +++ b/lib/Arsse.php @@ -28,4 +28,18 @@ class Arsse { static::$db = static::$db ?? new Database; 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]); + } + } } diff --git a/locale/en.php b/locale/en.php index 0189866..0f738f2 100644 --- a/locale/en.php +++ b/locale/en.php @@ -80,6 +80,11 @@ return [ }', // indicates programming error '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.fileMissing' => 'Language file "{0}" is not available', 'Exception.JKingWeb/Arsse/Lang/Exception.fileUnreadable' => 'Insufficient permissions to read language file "{0}"',