|
@@ -140,6 +140,25 @@ final class Utils
|
|
|
return $json;
|
|
return $json;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function pcreLastErrorMessage(int $code): string
|
|
|
|
|
+ {
|
|
|
|
|
+ if (PHP_VERSION_ID >= 80000) {
|
|
|
|
|
+ return preg_last_error_msg();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $constants = (get_defined_constants(true))['pcre'];
|
|
|
|
|
+ $constants = array_filter($constants, function ($key) {
|
|
|
|
|
+ return substr($key, -6) == '_ERROR';
|
|
|
|
|
+ }, ARRAY_FILTER_USE_KEY);
|
|
|
|
|
+
|
|
|
|
|
+ $constants = array_flip($constants);
|
|
|
|
|
+
|
|
|
|
|
+ return $constants[$code] ?? 'UNDEFINED_ERROR';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Throws an exception according to a given code with a customized message
|
|
* Throws an exception according to a given code with a customized message
|
|
|
*
|
|
*
|
|
@@ -197,7 +216,8 @@ final class Utils
|
|
|
$data
|
|
$data
|
|
|
);
|
|
);
|
|
|
if (!is_string($data)) {
|
|
if (!is_string($data)) {
|
|
|
- throw new \RuntimeException('Failed to preg_replace_callback: '.preg_last_error().' / '.preg_last_error_msg());
|
|
|
|
|
|
|
+ $pcreErrorCode = preg_last_error();
|
|
|
|
|
+ throw new \RuntimeException('Failed to preg_replace_callback: ' . $pcreErrorCode . ' / ' . self::pcreLastErrorMessage($pcreErrorCode));
|
|
|
}
|
|
}
|
|
|
$data = str_replace(
|
|
$data = str_replace(
|
|
|
['¤', '¦', '¨', '´', '¸', '¼', '½', '¾'],
|
|
['¤', '¦', '¨', '´', '¸', '¼', '½', '¾'],
|