You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

136 lines
3.4 KiB

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