Polyfill ctype #1250

This commit is contained in:
the-djmaze 2024-03-04 19:46:12 +01:00
parent 34106c937e
commit 382ccdb499
3 changed files with 22 additions and 2 deletions

View file

@ -0,0 +1,17 @@
<?php
if (!function_exists('ctype_digit')) {
function ctype_digit(string $text): bool
{
$l = \strlen($text);
return $l && $l === \strspn($text, '0123456789');
}
}
if (!function_exists('ctype_alpha')) {
function ctype_alpha(string $text): bool
{
$l = \strlen($text);
return $l && $l === \strspn($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
}
}

View file

@ -101,7 +101,6 @@ abstract class Integrity
'mbstring' => extension_loaded('mbstring'),
'Zlib' => extension_loaded('zlib'),
// enabled by default:
'ctype' => extension_loaded('ctype'),
'json' => function_exists('json_decode'),
'libxml' => function_exists('libxml_use_internal_errors'),
'dom' => class_exists('DOMDocument'),

View file

@ -4,10 +4,14 @@ if (defined('APP_VERSION_ROOT_PATH')) {
}
// PHP 8
if (\PHP_VERSION_ID < 80000) {
if (PHP_VERSION_ID < 80000) {
require __DIR__ . '/app/libraries/polyfill/php8.php';
}
if (!extension_loaded('ctype')) {
require __DIR__ . '/app/libraries/polyfill/ctype.php';
}
if (!defined('APP_VERSION')) {
define('APP_VERSION', basename(__DIR__));
}