diff --git a/lib/AbstractException.php b/lib/AbstractException.php index 501634d4..cde92dca 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 331944aa..ec04d249 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 01898667..0f738f2f 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}"',