-
-
Notifications
You must be signed in to change notification settings - Fork 839
/
compatibility.php
121 lines (112 loc) · 3.05 KB
/
compatibility.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* compatibility functions
*
* This file contains a few functions that might be missing from the PHP build
*/
if (!function_exists('ctype_space')) {
/**
* Check for whitespace character(s)
*
* @param string $text
* @return bool
* @see ctype_space
*/
function ctype_space($text)
{
if (!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
if (trim($text) === '') return true;
return false;
}
}
if (!function_exists('ctype_digit')) {
/**
* Check for numeric character(s)
*
* @param string $text
* @return bool
* @see ctype_digit
*/
function ctype_digit($text)
{
if (!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
if (preg_match('/^\d+$/', $text)) return true;
return false;
}
}
if (!function_exists('gzopen') && function_exists('gzopen64')) {
/**
* work around for PHP compiled against certain zlib versions #865
*
* @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
*
* @param string $filename
* @param string $mode
* @param int $use_include_path
* @return mixed
*/
function gzopen($filename, $mode, $use_include_path = 0)
{
return gzopen64($filename, $mode, $use_include_path);
}
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
/**
* work around for PHP compiled against certain zlib versions #865
*
* @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
*
* @param resource $zp
* @param int $offset
* @param int $whence
* @return int
*/
function gzseek($zp, $offset, $whence = SEEK_SET)
{
return gzseek64($zp, $offset, $whence);
}
}
if (!function_exists('gztell') && function_exists('gztell64')) {
/**
* work around for PHP compiled against certain zlib versions #865
*
* @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
*
* @param resource $zp
* @return int
*/
function gztell($zp)
{
return gztell64($zp);
}
}
/**
* polyfill for PHP < 8
* @see https://www.php.net/manual/en/function.str-starts-with
*/
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle)
{
return empty($needle) || strpos($haystack, $needle) === 0;
}
}
/**
* polyfill for PHP < 8
* @see https://www.php.net/manual/en/function.str-contains
*/
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle)
{
return empty($needle) || strpos($haystack, $needle) !== false;
}
}
/**
* polyfill for PHP < 8
* @see https://www.php.net/manual/en/function.str-ends-with
*/
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle)
{
return empty($needle) || substr($haystack, -strlen($needle)) === $needle;
}
}