Browse Source

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
rpm
J. King 3 years ago
parent
commit
75e87f31a0
  1. 1
      lib/AbstractException.php
  2. 14
      lib/Arsse.php
  3. 5
      locale/en.php

1
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,

14
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]);
}
}
}

5
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}"',

Loading…
Cancel
Save