From 7c8190baa56d338975b044a3bd7fb71629aad225 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 26 Dec 2020 12:39:55 +0100 Subject: [PATCH] Verify the signature of polyfills on PHP >= 8 --- composer.json | 3 +- src/Apcu/bootstrap.php | 16 ++-- src/Apcu/bootstrap80.php | 75 +++++++++++++++ src/Ctype/bootstrap.php | 26 ++--- src/Ctype/bootstrap80.php | 46 +++++++++ src/Iconv/bootstrap.php | 6 +- src/Iconv/bootstrap80.php | 80 ++++++++++++++++ src/Intl/Grapheme/bootstrap.php | 12 ++- src/Intl/Grapheme/bootstrap80.php | 50 ++++++++++ src/Intl/Icu/bootstrap.php | 12 ++- src/Intl/Icu/bootstrap80.php | 25 +++++ src/Intl/Idn/bootstrap.php | 12 ++- src/Intl/Idn/bootstrap80.php | 128 +++++++++++++++++++++++++ src/Intl/Normalizer/bootstrap.php | 8 +- src/Intl/Normalizer/bootstrap80.php | 19 ++++ src/Mbstring/bootstrap.php | 14 +-- src/Mbstring/bootstrap80.php | 143 ++++++++++++++++++++++++++++ src/Php80/bootstrap.php | 2 +- src/Util/TestListenerTrait.php | 17 +++- src/Uuid/bootstrap.php | 6 +- src/Uuid/bootstrap80.php | 89 +++++++++++++++++ 21 files changed, 748 insertions(+), 41 deletions(-) create mode 100644 src/Apcu/bootstrap80.php create mode 100644 src/Ctype/bootstrap80.php create mode 100644 src/Iconv/bootstrap80.php create mode 100644 src/Intl/Grapheme/bootstrap80.php create mode 100644 src/Intl/Icu/bootstrap80.php create mode 100644 src/Intl/Idn/bootstrap80.php create mode 100644 src/Intl/Normalizer/bootstrap80.php create mode 100644 src/Mbstring/bootstrap80.php create mode 100644 src/Uuid/bootstrap80.php diff --git a/composer.json b/composer.json index 95e92f44..253ab344 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ }, "require-dev": { "symfony/intl": "^4.4|^5.0", - "symfony/phpunit-bridge": "^5.3" + "symfony/phpunit-bridge": "^5.3", + "symfony/var-dumper": "^4.4|^5.1" }, "replace": { "symfony/polyfill-apcu": "self.version", diff --git a/src/Apcu/bootstrap.php b/src/Apcu/bootstrap.php index 90141a64..f99aa2f0 100644 --- a/src/Apcu/bootstrap.php +++ b/src/Apcu/bootstrap.php @@ -15,37 +15,41 @@ return; } +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (extension_loaded('Zend Data Cache')) { if (!function_exists('apcu_add')) { - function apcu_add($key, $var = null, $ttl = 0) { return p\Apcu::apcu_add($key, $var, $ttl); } + function apcu_add($key, $value = null, $ttl = 0) { return p\Apcu::apcu_add($key, $value, $ttl); } } if (!function_exists('apcu_delete')) { function apcu_delete($key) { return p\Apcu::apcu_delete($key); } } if (!function_exists('apcu_exists')) { - function apcu_exists($keys) { return p\Apcu::apcu_exists($keys); } + function apcu_exists($key) { return p\Apcu::apcu_exists($key); } } if (!function_exists('apcu_fetch')) { function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); } } if (!function_exists('apcu_store')) { - function apcu_store($key, $var = null, $ttl = 0) { return p\Apcu::apcu_store($key, $var, $ttl); } + function apcu_store($key, $value = null, $ttl = 0) { return p\Apcu::apcu_store($key, $value, $ttl); } } } else { if (!function_exists('apcu_add')) { - function apcu_add($key, $var = null, $ttl = 0) { return apc_add($key, $var, $ttl); } + function apcu_add($key, $value = null, $ttl = 0) { return apc_add($key, $value, $ttl); } } if (!function_exists('apcu_delete')) { function apcu_delete($key) { return apc_delete($key); } } if (!function_exists('apcu_exists')) { - function apcu_exists($keys) { return apc_exists($keys); } + function apcu_exists($key) { return apc_exists($key); } } if (!function_exists('apcu_fetch')) { function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } } if (!function_exists('apcu_store')) { - function apcu_store($key, $var = null, $ttl = 0) { return apc_store($key, $var, $ttl); } + function apcu_store($key, $value = null, $ttl = 0) { return apc_store($key, $value, $ttl); } } } diff --git a/src/Apcu/bootstrap80.php b/src/Apcu/bootstrap80.php new file mode 100644 index 00000000..48ca19c9 --- /dev/null +++ b/src/Apcu/bootstrap80.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Apcu as p; + +if (extension_loaded('Zend Data Cache')) { + if (!function_exists('apcu_add')) { + function apcu_add($key, mixed $value, int $ttl = 0): array|bool { return p\Apcu::apcu_add($key, $value, $ttl); } + } + if (!function_exists('apcu_delete')) { + function apcu_delete($key): array|bool { return p\Apcu::apcu_delete($key); } + } + if (!function_exists('apcu_exists')) { + function apcu_exists($key): array|bool { return p\Apcu::apcu_exists($key); } + } + if (!function_exists('apcu_fetch')) { + function apcu_fetch($key, &$success = null): mixed { return p\Apcu::apcu_fetch($key, $success); } + } + if (!function_exists('apcu_store')) { + function apcu_store($key, mixed $value, int $ttl = 0): array|bool { return p\Apcu::apcu_store($key, $value, $ttl); } + } +} else { + if (!function_exists('apcu_add')) { + function apcu_add($key, mixed $value, int $ttl = 0): array|bool { return apc_add($key, $value, $ttl); } + } + if (!function_exists('apcu_delete')) { + function apcu_delete($key): array|bool { return apc_delete($key); } + } + if (!function_exists('apcu_exists')) { + function apcu_exists($key): array|bool { return apc_exists($key); } + } + if (!function_exists('apcu_fetch')) { + function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } + } + if (!function_exists('apcu_store')) { + function apcu_store($key, mixed $value, int $ttl = 0): array|bool { return apc_store($key, $value, $ttl); } + } +} + +if (!function_exists('apcu_cache_info')) { + function apcu_cache_info($limited = false) { return apc_cache_info('user', $limited); } +} +if (!function_exists('apcu_cas')) { + function apcu_cas($key, $old, $new) { return apc_cas($key, $old, $new); } +} +if (!function_exists('apcu_clear_cache')) { + function apcu_clear_cache() { return apc_clear_cache('user'); } +} +if (!function_exists('apcu_dec')) { + function apcu_dec($key, $step = 1, &$success = false) { return apc_dec($key, $step, $success); } +} +if (!function_exists('apcu_inc')) { + function apcu_inc($key, $step = 1, &$success = false) { return apc_inc($key, $step, $success); } +} +if (!function_exists('apcu_sma_info')) { + function apcu_sma_info($limited = false) { return apc_sma_info($limited); } +} + +if (!class_exists('APCuIterator', false) && class_exists('APCIterator', false)) { + class APCuIterator extends APCIterator + { + public function __construct($search = null, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) + { + parent::__construct('user', $search, $format, $chunk_size, $list); + } + } +} diff --git a/src/Ctype/bootstrap.php b/src/Ctype/bootstrap.php index 0bc45cfd..ad138540 100644 --- a/src/Ctype/bootstrap.php +++ b/src/Ctype/bootstrap.php @@ -11,36 +11,40 @@ use Symfony\Polyfill\Ctype as p; +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!function_exists('ctype_alnum')) { - function ctype_alnum($input) { return p\Ctype::ctype_alnum($input); } + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } } if (!function_exists('ctype_alpha')) { - function ctype_alpha($input) { return p\Ctype::ctype_alpha($input); } + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } } if (!function_exists('ctype_cntrl')) { - function ctype_cntrl($input) { return p\Ctype::ctype_cntrl($input); } + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } } if (!function_exists('ctype_digit')) { - function ctype_digit($input) { return p\Ctype::ctype_digit($input); } + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } } if (!function_exists('ctype_graph')) { - function ctype_graph($input) { return p\Ctype::ctype_graph($input); } + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } } if (!function_exists('ctype_lower')) { - function ctype_lower($input) { return p\Ctype::ctype_lower($input); } + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } } if (!function_exists('ctype_print')) { - function ctype_print($input) { return p\Ctype::ctype_print($input); } + function ctype_print($text) { return p\Ctype::ctype_print($text); } } if (!function_exists('ctype_punct')) { - function ctype_punct($input) { return p\Ctype::ctype_punct($input); } + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } } if (!function_exists('ctype_space')) { - function ctype_space($input) { return p\Ctype::ctype_space($input); } + function ctype_space($text) { return p\Ctype::ctype_space($text); } } if (!function_exists('ctype_upper')) { - function ctype_upper($input) { return p\Ctype::ctype_upper($input); } + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } } if (!function_exists('ctype_xdigit')) { - function ctype_xdigit($input) { return p\Ctype::ctype_xdigit($input); } + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } } diff --git a/src/Ctype/bootstrap80.php b/src/Ctype/bootstrap80.php new file mode 100644 index 00000000..ab2f8611 --- /dev/null +++ b/src/Ctype/bootstrap80.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } +} +if (!function_exists('ctype_alpha')) { + function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } +} +if (!function_exists('ctype_cntrl')) { + function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } +} +if (!function_exists('ctype_digit')) { + function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } +} +if (!function_exists('ctype_graph')) { + function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } +} +if (!function_exists('ctype_lower')) { + function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } +} +if (!function_exists('ctype_print')) { + function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } +} +if (!function_exists('ctype_punct')) { + function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } +} +if (!function_exists('ctype_space')) { + function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } +} +if (!function_exists('ctype_upper')) { + function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } +} +if (!function_exists('ctype_xdigit')) { + function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } +} diff --git a/src/Iconv/bootstrap.php b/src/Iconv/bootstrap.php index 6eb76fc5..df6328cd 100644 --- a/src/Iconv/bootstrap.php +++ b/src/Iconv/bootstrap.php @@ -15,6 +15,10 @@ return; } +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!defined('ICONV_IMPL')) { define('ICONV_IMPL', 'Symfony'); } @@ -38,7 +42,7 @@ function iconv_get_encoding($type = 'all') { return p\Iconv::iconv_get_encoding( function iconv_set_encoding($type, $encoding) { return p\Iconv::iconv_set_encoding($type, $encoding); } } if (!function_exists('iconv_mime_encode')) { - function iconv_mime_encode($field_name, $field_value, $options = null) { return p\Iconv::iconv_mime_encode($field_name, $field_value, $options); } + function iconv_mime_encode($field_name, $field_value, $options = []) { return p\Iconv::iconv_mime_encode($field_name, $field_value, $options); } } if (!function_exists('iconv_mime_decode_headers')) { function iconv_mime_decode_headers($headers, $mode = 0, $encoding = null) { return p\Iconv::iconv_mime_decode_headers($headers, $mode, $encoding); } diff --git a/src/Iconv/bootstrap80.php b/src/Iconv/bootstrap80.php new file mode 100644 index 00000000..2dd8bf76 --- /dev/null +++ b/src/Iconv/bootstrap80.php @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Iconv as p; + +if (!defined('ICONV_IMPL')) { + define('ICONV_IMPL', 'Symfony'); +} +if (!defined('ICONV_VERSION')) { + define('ICONV_VERSION', '1.0'); +} +if (!defined('ICONV_MIME_DECODE_STRICT')) { + define('ICONV_MIME_DECODE_STRICT', 1); +} +if (!defined('ICONV_MIME_DECODE_CONTINUE_ON_ERROR')) { + define('ICONV_MIME_DECODE_CONTINUE_ON_ERROR', 2); +} + +if (!function_exists('iconv')) { + function iconv(string $from_encoding, string $to_encoding, string $string): string|false { return p\Iconv::iconv($from_encoding, $to_encoding, $string); } +} +if (!function_exists('iconv_get_encoding')) { + function iconv_get_encoding(string $type = 'all'): array|string|false { return p\Iconv::iconv_get_encoding($type); } +} +if (!function_exists('iconv_set_encoding')) { + function iconv_set_encoding(string $type, string $encoding): bool { return p\Iconv::iconv_set_encoding($type, $encoding); } +} +if (!function_exists('iconv_mime_encode')) { + function iconv_mime_encode(string $field_name, string $field_value, array $options = []): string|false { return p\Iconv::iconv_mime_encode($field_name, $field_value, $options); } +} +if (!function_exists('iconv_mime_decode_headers')) { + function iconv_mime_decode_headers(string $headers, int $mode = 0, string $encoding = null): array|false { return p\Iconv::iconv_mime_decode_headers($headers, $mode, $encoding); } +} + +if (extension_loaded('mbstring')) { + if (!function_exists('iconv_strlen')) { + function iconv_strlen(string $string, string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen($string, $encoding); } + } + if (!function_exists('iconv_strpos')) { + function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos($haystack, $needle, $offset, $encoding); } + } + if (!function_exists('iconv_strrpos')) { + function iconv_strrpos(string $haystack, string $needle, string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos($haystack, $needle, 0, $encoding); } + } + if (!function_exists('iconv_substr')) { + function iconv_substr(string $string, int $offset, int $length = null, string $encoding = null): string|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr($string, $offset, $length, $encoding); } + } + if (!function_exists('iconv_mime_decode')) { + function iconv_mime_decode($string, $mode = 0, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_decode_mimeheader($string, $mode, $encoding); } + } +} else { + if (!function_exists('iconv_strlen')) { + if (extension_loaded('xml')) { + function iconv_strlen(string $string, string $encoding = null): int|false { return p\Iconv::strlen1($string, $encoding); } + } else { + function iconv_strlen(string $string, string $encoding = null): int|false { return p\Iconv::strlen2($string, $encoding); } + } + } + + if (!function_exists('iconv_strpos')) { + function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { return p\Iconv::iconv_strpos($haystack, $needle, $offset, $encoding); } + } + if (!function_exists('iconv_strrpos')) { + function iconv_strrpos(string $haystack, string $needle, string $encoding = null): int|false { return p\Iconv::iconv_strrpos($haystack, $needle, $encoding); } + } + if (!function_exists('iconv_substr')) { + function iconv_substr(string $string, int $offset, int $length = null, string $encoding = null): string|false { return p\Iconv::iconv_substr($string, $offset, $length, $encoding); } + } + if (!function_exists('iconv_mime_decode')) { + function iconv_mime_decode(string $string, int $mode = 0, string $encoding = null): string|false { return p\Iconv::iconv_mime_decode($string, $mode, $encoding); } + } +} diff --git a/src/Intl/Grapheme/bootstrap.php b/src/Intl/Grapheme/bootstrap.php index 1a44b21e..0ca763f1 100644 --- a/src/Intl/Grapheme/bootstrap.php +++ b/src/Intl/Grapheme/bootstrap.php @@ -15,6 +15,10 @@ return; } +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!defined('GRAPHEME_EXTR_COUNT')) { define('GRAPHEME_EXTR_COUNT', 0); } @@ -26,13 +30,13 @@ } if (!function_exists('grapheme_extract')) { - function grapheme_extract($haystack, $size, $extract_type = 0, $start = 0, &$next = 0) { return p\Grapheme::grapheme_extract($haystack, $size, $extract_type, $start, $next); } + function grapheme_extract($haystack, $size, $type = 0, $start = 0, &$next = 0) { return p\Grapheme::grapheme_extract($haystack, $size, $type, $start, $next); } } if (!function_exists('grapheme_stripos')) { function grapheme_stripos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_stripos($haystack, $needle, $offset); } } if (!function_exists('grapheme_stristr')) { - function grapheme_stristr($haystack, $needle, $before_needle = false) { return p\Grapheme::grapheme_stristr($haystack, $needle, $before_needle); } + function grapheme_stristr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_stristr($haystack, $needle, $beforeNeedle); } } if (!function_exists('grapheme_strlen')) { function grapheme_strlen($input) { return p\Grapheme::grapheme_strlen($input); } @@ -47,8 +51,8 @@ function grapheme_strripos($haystack, $needle, $offset = 0) { return p\Grapheme: function grapheme_strrpos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strrpos($haystack, $needle, $offset); } } if (!function_exists('grapheme_strstr')) { - function grapheme_strstr($haystack, $needle, $before_needle = false) { return p\Grapheme::grapheme_strstr($haystack, $needle, $before_needle); } + function grapheme_strstr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_strstr($haystack, $needle, $beforeNeedle); } } if (!function_exists('grapheme_substr')) { - function grapheme_substr($string, $start, $length = null) { return p\Grapheme::grapheme_substr($string, $start, $length); } + function grapheme_substr($string, $offset, $length = null) { return p\Grapheme::grapheme_substr($string, $offset, $length); } } diff --git a/src/Intl/Grapheme/bootstrap80.php b/src/Intl/Grapheme/bootstrap80.php new file mode 100644 index 00000000..e144d5b0 --- /dev/null +++ b/src/Intl/Grapheme/bootstrap80.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Intl\Grapheme as p; + +if (!defined('GRAPHEME_EXTR_COUNT')) { + define('GRAPHEME_EXTR_COUNT', 0); +} +if (!defined('GRAPHEME_EXTR_MAXBYTES')) { + define('GRAPHEME_EXTR_MAXBYTES', 1); +} +if (!defined('GRAPHEME_EXTR_MAXCHARS')) { + define('GRAPHEME_EXTR_MAXCHARS', 2); +} + +if (!function_exists('grapheme_extract')) { + function grapheme_extract(string $haystack, int $size, int $type = GRAPHEME_EXTR_COUNT, int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract($haystack, $size, $type, $offset, $next); } +} +if (!function_exists('grapheme_stripos')) { + function grapheme_stripos(string $haystack, string $needle, int $offset = 0): int|false { return p\Grapheme::grapheme_stripos($haystack, $needle, $offset); } +} +if (!function_exists('grapheme_stristr')) { + function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr($haystack, $needle, $beforeNeedle); } +} +if (!function_exists('grapheme_strlen')) { + function grapheme_strlen(string $string): int|false|null { return p\Grapheme::grapheme_strlen($string); } +} +if (!function_exists('grapheme_strpos')) { + function grapheme_strpos(string $haystack, string $needle, int $offset = 0): int|false { return p\Grapheme::grapheme_strpos($haystack, $needle, $offset); } +} +if (!function_exists('grapheme_strripos')) { + function grapheme_strripos(string $haystack, string $needle, int $offset = 0): int|false { return p\Grapheme::grapheme_strripos($haystack, $needle, $offset); } +} +if (!function_exists('grapheme_strrpos')) { + function grapheme_strrpos(string $haystack, string $needle, int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos($haystack, $needle, $offset); } +} +if (!function_exists('grapheme_strstr')) { + function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr($haystack, $needle, $beforeNeedle); } +} +if (!function_exists('grapheme_substr')) { + function grapheme_substr(string $string, int $offset, int $length = null): string|false { return p\Grapheme::grapheme_substr($string, $offset, $length); } +} diff --git a/src/Intl/Icu/bootstrap.php b/src/Intl/Icu/bootstrap.php index 6dac46a2..6e58e186 100644 --- a/src/Intl/Icu/bootstrap.php +++ b/src/Intl/Icu/bootstrap.php @@ -11,8 +11,16 @@ use Symfony\Polyfill\Intl\Icu as p; +if (extension_loaded('intl')) { + return; +} + +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!function_exists('intl_is_failure')) { - function intl_is_failure($error_code) { return p\Icu::isFailure($error_code); } + function intl_is_failure($errorCode) { return p\Icu::isFailure($errorCode); } } if (!function_exists('intl_get_error_code')) { function intl_get_error_code() { return p\Icu::getErrorCode(); } @@ -21,5 +29,5 @@ function intl_get_error_code() { return p\Icu::getErrorCode(); } function intl_get_error_message() { return p\Icu::getErrorMessage(); } } if (!function_exists('intl_error_name')) { - function intl_error_name($error_code) { return p\Icu::getErrorName($error_code); } + function intl_error_name($errorCode) { return p\Icu::getErrorName($errorCode); } } diff --git a/src/Intl/Icu/bootstrap80.php b/src/Intl/Icu/bootstrap80.php new file mode 100644 index 00000000..b1cfdf85 --- /dev/null +++ b/src/Intl/Icu/bootstrap80.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Intl\Icu as p; + +if (!function_exists('intl_is_failure')) { + function intl_is_failure(int $errorCode): bool { return p\Icu::isFailure($errorCode); } +} +if (!function_exists('intl_get_error_code')) { + function intl_get_error_code(): int { return p\Icu::getErrorCode(); } +} +if (!function_exists('intl_get_error_message')) { + function intl_get_error_message(): string { return p\Icu::getErrorMessage(); } +} +if (!function_exists('intl_error_name')) { + function intl_error_name(int $errorCode): string { return p\Icu::getErrorName($errorCode); } +} diff --git a/src/Intl/Idn/bootstrap.php b/src/Intl/Idn/bootstrap.php index f02d5de7..8e6b9939 100644 --- a/src/Intl/Idn/bootstrap.php +++ b/src/Intl/Idn/bootstrap.php @@ -15,6 +15,10 @@ return; } +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!defined('U_IDNA_PROHIBITED_ERROR')) { define('U_IDNA_PROHIBITED_ERROR', 66560); } @@ -126,16 +130,16 @@ if (PHP_VERSION_ID < 70400) { if (!function_exists('idn_to_ascii')) { - function idn_to_ascii($domain, $options = IDNA_DEFAULT, $variant = INTL_IDNA_VARIANT_2003, &$idna_info = array()) { return p\Idn::idn_to_ascii($domain, $options, $variant, $idna_info); } + function idn_to_ascii($domain, $flags = 0, $variant = INTL_IDNA_VARIANT_2003, &$idna_info = null) { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); } } if (!function_exists('idn_to_utf8')) { - function idn_to_utf8($domain, $options = IDNA_DEFAULT, $variant = INTL_IDNA_VARIANT_2003, &$idna_info = array()) { return p\Idn::idn_to_utf8($domain, $options, $variant, $idna_info); } + function idn_to_utf8($domain, $flags = 0, $variant = INTL_IDNA_VARIANT_2003, &$idna_info = null) { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); } } } else { if (!function_exists('idn_to_ascii')) { - function idn_to_ascii($domain, $options = IDNA_DEFAULT, $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = array()) { return p\Idn::idn_to_ascii($domain, $options, $variant, $idna_info); } + function idn_to_ascii($domain, $flags = 0, $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null) { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); } } if (!function_exists('idn_to_utf8')) { - function idn_to_utf8($domain, $options = IDNA_DEFAULT, $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = array()) { return p\Idn::idn_to_utf8($domain, $options, $variant, $idna_info); } + function idn_to_utf8($domain, $flags = 0, $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null) { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); } } } diff --git a/src/Intl/Idn/bootstrap80.php b/src/Intl/Idn/bootstrap80.php new file mode 100644 index 00000000..6c2b7292 --- /dev/null +++ b/src/Intl/Idn/bootstrap80.php @@ -0,0 +1,128 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Intl\Idn as p; + +if (!defined('U_IDNA_PROHIBITED_ERROR')) { + define('U_IDNA_PROHIBITED_ERROR', 66560); +} +if (!defined('U_IDNA_ERROR_START')) { + define('U_IDNA_ERROR_START', 66560); +} +if (!defined('U_IDNA_UNASSIGNED_ERROR')) { + define('U_IDNA_UNASSIGNED_ERROR', 66561); +} +if (!defined('U_IDNA_CHECK_BIDI_ERROR')) { + define('U_IDNA_CHECK_BIDI_ERROR', 66562); +} +if (!defined('U_IDNA_STD3_ASCII_RULES_ERROR')) { + define('U_IDNA_STD3_ASCII_RULES_ERROR', 66563); +} +if (!defined('U_IDNA_ACE_PREFIX_ERROR')) { + define('U_IDNA_ACE_PREFIX_ERROR', 66564); +} +if (!defined('U_IDNA_VERIFICATION_ERROR')) { + define('U_IDNA_VERIFICATION_ERROR', 66565); +} +if (!defined('U_IDNA_LABEL_TOO_LONG_ERROR')) { + define('U_IDNA_LABEL_TOO_LONG_ERROR', 66566); +} +if (!defined('U_IDNA_ZERO_LENGTH_LABEL_ERROR')) { + define('U_IDNA_ZERO_LENGTH_LABEL_ERROR', 66567); +} +if (!defined('U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR')) { + define('U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR', 66568); +} +if (!defined('U_IDNA_ERROR_LIMIT')) { + define('U_IDNA_ERROR_LIMIT', 66569); +} +if (!defined('U_STRINGPREP_PROHIBITED_ERROR')) { + define('U_STRINGPREP_PROHIBITED_ERROR', 66560); +} +if (!defined('U_STRINGPREP_UNASSIGNED_ERROR')) { + define('U_STRINGPREP_UNASSIGNED_ERROR', 66561); +} +if (!defined('U_STRINGPREP_CHECK_BIDI_ERROR')) { + define('U_STRINGPREP_CHECK_BIDI_ERROR', 66562); +} +if (!defined('IDNA_DEFAULT')) { + define('IDNA_DEFAULT', 0); +} +if (!defined('IDNA_ALLOW_UNASSIGNED')) { + define('IDNA_ALLOW_UNASSIGNED', 1); +} +if (!defined('IDNA_USE_STD3_RULES')) { + define('IDNA_USE_STD3_RULES', 2); +} +if (!defined('IDNA_CHECK_BIDI')) { + define('IDNA_CHECK_BIDI', 4); +} +if (!defined('IDNA_CHECK_CONTEXTJ')) { + define('IDNA_CHECK_CONTEXTJ', 8); +} +if (!defined('IDNA_NONTRANSITIONAL_TO_ASCII')) { + define('IDNA_NONTRANSITIONAL_TO_ASCII', 16); +} +if (!defined('IDNA_NONTRANSITIONAL_TO_UNICODE')) { + define('IDNA_NONTRANSITIONAL_TO_UNICODE', 32); +} +if (!defined('INTL_IDNA_VARIANT_2003')) { + define('INTL_IDNA_VARIANT_2003', 0); +} +if (!defined('INTL_IDNA_VARIANT_UTS46')) { + define('INTL_IDNA_VARIANT_UTS46', 1); +} +if (!defined('IDNA_ERROR_EMPTY_LABEL')) { + define('IDNA_ERROR_EMPTY_LABEL', 1); +} +if (!defined('IDNA_ERROR_LABEL_TOO_LONG')) { + define('IDNA_ERROR_LABEL_TOO_LONG', 2); +} +if (!defined('IDNA_ERROR_DOMAIN_NAME_TOO_LONG')) { + define('IDNA_ERROR_DOMAIN_NAME_TOO_LONG', 4); +} +if (!defined('IDNA_ERROR_LEADING_HYPHEN')) { + define('IDNA_ERROR_LEADING_HYPHEN', 8); +} +if (!defined('IDNA_ERROR_TRAILING_HYPHEN')) { + define('IDNA_ERROR_TRAILING_HYPHEN', 16); +} +if (!defined('IDNA_ERROR_HYPHEN_3_4')) { + define('IDNA_ERROR_HYPHEN_3_4', 32); +} +if (!defined('IDNA_ERROR_LEADING_COMBINING_MARK')) { + define('IDNA_ERROR_LEADING_COMBINING_MARK', 64); +} +if (!defined('IDNA_ERROR_DISALLOWED')) { + define('IDNA_ERROR_DISALLOWED', 128); +} +if (!defined('IDNA_ERROR_PUNYCODE')) { + define('IDNA_ERROR_PUNYCODE', 256); +} +if (!defined('IDNA_ERROR_LABEL_HAS_DOT')) { + define('IDNA_ERROR_LABEL_HAS_DOT', 512); +} +if (!defined('IDNA_ERROR_INVALID_ACE_LABEL')) { + define('IDNA_ERROR_INVALID_ACE_LABEL', 1024); +} +if (!defined('IDNA_ERROR_BIDI')) { + define('IDNA_ERROR_BIDI', 2048); +} +if (!defined('IDNA_ERROR_CONTEXTJ')) { + define('IDNA_ERROR_CONTEXTJ', 4096); +} + +if (!function_exists('idn_to_ascii')) { + function idn_to_ascii(string $domain, int $flags = 0, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); } +} +if (!function_exists('idn_to_utf8')) { + function idn_to_utf8(string $domain, int $flags = 0, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); } +} diff --git a/src/Intl/Normalizer/bootstrap.php b/src/Intl/Normalizer/bootstrap.php index bac4318c..ed56bac8 100644 --- a/src/Intl/Normalizer/bootstrap.php +++ b/src/Intl/Normalizer/bootstrap.php @@ -11,9 +11,13 @@ use Symfony\Polyfill\Intl\Normalizer as p; +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!function_exists('normalizer_is_normalized')) { - function normalizer_is_normalized($input, $form = p\Normalizer::NFC) { return p\Normalizer::isNormalized($input, $form); } + function normalizer_is_normalized($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::isNormalized($string, $form); } } if (!function_exists('normalizer_normalize')) { - function normalizer_normalize($input, $form = p\Normalizer::NFC) { return p\Normalizer::normalize($input, $form); } + function normalizer_normalize($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::normalize($string, $form); } } diff --git a/src/Intl/Normalizer/bootstrap80.php b/src/Intl/Normalizer/bootstrap80.php new file mode 100644 index 00000000..c9a29d7a --- /dev/null +++ b/src/Intl/Normalizer/bootstrap80.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Intl\Normalizer as p; + +if (!function_exists('normalizer_is_normalized')) { + function normalizer_is_normalized(string $string, int $form = p\Normalizer::FORM_C): bool { return p\Normalizer::isNormalized($string, $form); } +} +if (!function_exists('normalizer_normalize')) { + function normalizer_normalize(string $string, int $form = p\Normalizer::FORM_C): string|false { return p\Normalizer::normalize($string, $form); } +} diff --git a/src/Mbstring/bootstrap.php b/src/Mbstring/bootstrap.php index d0a93d4d..b585bc3e 100644 --- a/src/Mbstring/bootstrap.php +++ b/src/Mbstring/bootstrap.php @@ -11,6 +11,10 @@ use Symfony\Polyfill\Mbstring as p; +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!function_exists('mb_convert_encoding')) { function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } } @@ -18,7 +22,7 @@ function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { ret function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } } if (!function_exists('mb_encode_mimeheader')) { - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = null, $indent = null) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } + function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } } if (!function_exists('mb_decode_numericentity')) { function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } @@ -108,15 +112,11 @@ function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstri function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } } if (!function_exists('mb_http_input')) { - function mb_http_input($type = '') { return p\Mbstring::mb_http_input($type); } + function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } } if (!function_exists('mb_convert_variables')) { - if (PHP_VERSION_ID >= 80000) { - function mb_convert_variables($to_encoding, $from_encoding, &$var, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, $var, ...$vars); } - } else { - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } - } + function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } } if (!function_exists('mb_ord')) { diff --git a/src/Mbstring/bootstrap80.php b/src/Mbstring/bootstrap80.php new file mode 100644 index 00000000..f7acde73 --- /dev/null +++ b/src/Mbstring/bootstrap80.php @@ -0,0 +1,143 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Mbstring as p; + +if (!function_exists('mb_convert_encoding')) { + function mb_convert_encoding(array|string $string, string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } +} +if (!function_exists('mb_decode_mimeheader')) { + function mb_decode_mimeheader(string $string): string { return p\Mbstring::mb_decode_mimeheader($string); } +} +if (!function_exists('mb_encode_mimeheader')) { + function mb_encode_mimeheader(string $string, string $charset = null, string $transfer_encoding = null, string $newline = "\r\n", int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } +} +if (!function_exists('mb_decode_numericentity')) { + function mb_decode_numericentity(string $string, array $map, string $encoding = null): string { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } +} +if (!function_exists('mb_encode_numericentity')) { + function mb_encode_numericentity(string $string, array $map, string $encoding = null, bool $hex = false): string { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } +} +if (!function_exists('mb_convert_case')) { + function mb_convert_case(string $string, int $mode, string $encoding = null): string { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } +} +if (!function_exists('mb_internal_encoding')) { + function mb_internal_encoding(string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } +} +if (!function_exists('mb_language')) { + function mb_language(string $language = null): string|bool { return p\Mbstring::mb_language($language); } +} +if (!function_exists('mb_list_encodings')) { + function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } +} +if (!function_exists('mb_encoding_aliases')) { + function mb_encoding_aliases(string $encoding): array { return p\Mbstring::mb_encoding_aliases($encoding); } +} +if (!function_exists('mb_check_encoding')) { + function mb_check_encoding(array|string|null $value = null, string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } +} +if (!function_exists('mb_detect_encoding')) { + function mb_detect_encoding(string $string, array|string|null $encodings = null, bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } +} +if (!function_exists('mb_detect_order')) { + function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } +} +if (!function_exists('mb_parse_str')) { + function mb_parse_str(string $string, &$result = array()): bool { parse_str($string, $result); } +} +if (!function_exists('mb_strlen')) { + function mb_strlen(string $string, string $encoding = null): int { return p\Mbstring::mb_strlen($string, $encoding); } +} +if (!function_exists('mb_strpos')) { + function mb_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } +} +if (!function_exists('mb_strtolower')) { + function mb_strtolower(string $string, string $encoding = null): string { return p\Mbstring::mb_strtolower($string, $encoding); } +} +if (!function_exists('mb_strtoupper')) { + function mb_strtoupper(string $string, string $encoding = null): string { return p\Mbstring::mb_strtoupper($string, $encoding); } +} +if (!function_exists('mb_substitute_character')) { + function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } +} +if (!function_exists('mb_substr')) { + function mb_substr(string $string, int $start, int $length = null, string $encoding = null): string { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } +} +if (!function_exists('mb_stripos')) { + function mb_stripos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } +} +if (!function_exists('mb_stristr')) { + function mb_stristr(string $haystack, string $needle, bool $before_needle = false, string $encoding = null): string|false { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } +} +if (!function_exists('mb_strrchr')) { + function mb_strrchr(string $haystack, string $needle, bool $before_needle = false, string $encoding = null): string|false { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } +} +if (!function_exists('mb_strrichr')) { + function mb_strrichr(string $haystack, string $needle, bool $before_needle = false, string $encoding = null): string|false { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } +} +if (!function_exists('mb_strripos')) { + function mb_strripos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } +} +if (!function_exists('mb_strrpos')) { + function mb_strrpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } +} +if (!function_exists('mb_strstr')) { + function mb_strstr(string $haystack, string $needle, bool $before_needle = false, string $encoding = null): string|false { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } +} +if (!function_exists('mb_get_info')) { + function mb_get_info(string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info($type); } +} +if (!function_exists('mb_http_output')) { + function mb_http_output(string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } +} +if (!function_exists('mb_strwidth')) { + function mb_strwidth(string $string, string $encoding = null): int { return p\Mbstring::mb_strwidth($string, $encoding); } +} +if (!function_exists('mb_substr_count')) { + function mb_substr_count(string $haystack, string $needle, string $encoding = null): int { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } +} +if (!function_exists('mb_output_handler')) { + function mb_output_handler(string $string, int $status): string { return p\Mbstring::mb_output_handler($string, $status); } +} +if (!function_exists('mb_http_input')) { + function mb_http_input(string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } +} + +if (!function_exists('mb_convert_variables')) { + function mb_convert_variables(string $to_encoding, array|string $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, $var, ...$vars); } +} + +if (!function_exists('mb_ord')) { + function mb_ord(string $string, string $encoding = null): int|false { return p\Mbstring::mb_ord($string, $encoding); } +} +if (!function_exists('mb_chr')) { + function mb_chr(int $codepoint, string $encoding = null): string|false { return p\Mbstring::mb_chr($codepoint, $encoding); } +} +if (!function_exists('mb_scrub')) { + function mb_scrub(string $string, string $encoding = null): string { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } +} +if (!function_exists('mb_str_split')) { + function mb_str_split(string $string, int $length = 1, string $encoding = null): array { return p\Mbstring::mb_str_split($string, $length, $encoding); } +} + +if (extension_loaded('mbstring')) { + return; +} + +if (!defined('MB_CASE_UPPER')) { + define('MB_CASE_UPPER', 0); +} +if (!defined('MB_CASE_LOWER')) { + define('MB_CASE_LOWER', 1); +} +if (!defined('MB_CASE_TITLE')) { + define('MB_CASE_TITLE', 2); +} diff --git a/src/Php80/bootstrap.php b/src/Php80/bootstrap.php index 4b938e6d..96bf8ca5 100644 --- a/src/Php80/bootstrap.php +++ b/src/Php80/bootstrap.php @@ -38,5 +38,5 @@ function str_ends_with(string $haystack, string $needle): bool { return p\Php80: function get_debug_type($value): string { return p\Php80::get_debug_type($value); } } if (!function_exists('get_resource_id')) { - function get_resource_id($res): int { return p\Php80::get_resource_id($res); } + function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } } diff --git a/src/Util/TestListenerTrait.php b/src/Util/TestListenerTrait.php index 7ce20868..1cb908df 100644 --- a/src/Util/TestListenerTrait.php +++ b/src/Util/TestListenerTrait.php @@ -13,6 +13,8 @@ use PHPUnit\Framework\SkippedTestError; use PHPUnit\Util\Test; +use Symfony\Component\VarDumper\Caster\ReflectionCaster; +use Symfony\Component\VarDumper\Cloner\Stub; /** * @author Nicolas Grekas @@ -35,6 +37,7 @@ public function startTestSuite($mainSuite) continue; } if (\in_array('class-polyfill', Test::getGroups($testClass), true)) { + // TODO: check signatures for all polyfilled methods on PHP >= 8 continue; } $testedClass = new \ReflectionClass($testClass); @@ -49,7 +52,8 @@ public function startTestSuite($mainSuite) continue; } $testedClass = new \ReflectionClass($m[1].$m[2]); - $bootstrap = new \SplFileObject(\dirname($testedClass->getFileName()).'/bootstrap.php'); + $bootstrap = \dirname($testedClass->getFileName()).'/bootstrap'; + $bootstrap = new \SplFileObject($bootstrap.(\PHP_VERSION_ID >= 80000 && file_exists($bootstrap.'80.php') ? '80' : '').'.php'); $newWarnings = 0; $defLine = null; @@ -93,6 +97,7 @@ public function startTestSuite($mainSuite) $defLine = sprintf("return \\call_user_func_array('%s', \\func_get_args())", $f['name']); } } catch (\ReflectionException $e) { + $r = null; $defLine = sprintf("throw new \\%s('Internal function not found: %s')", SkippedTestError::class, $f['name']); } @@ -112,6 +117,16 @@ function {$f['name']}{$f['signature']} } EOPHP ); + + if (\PHP_VERSION_ID >= 80000 && $r && false === strpos($bootstrap->getPath(), 'Php7') && false === strpos($bootstrap->getPath(), 'Php80')) { + $originalSignature = ReflectionCaster::getSignature(ReflectionCaster::castFunctionAbstract($r, [], new Stub(), true)); + $polyfillSignature = ReflectionCaster::castFunctionAbstract(new \ReflectionFunction($testNamespace.'\\'.$f['name']), [], new Stub(), true); + $polyfillSignature = ReflectionCaster::getSignature($polyfillSignature); + + if ($polyfillSignature !== $originalSignature) { + $warnings[] = TestListener::warning("Incompatible signature for PHP >= 8:\n- {$f['name']}$originalSignature\n+ {$f['name']}$polyfillSignature"); + } + } } if (!$newWarnings && null === $defLine) { $warnings[] = TestListener::warning('No polyfills found in bootstrap.php for '.$testClass); diff --git a/src/Uuid/bootstrap.php b/src/Uuid/bootstrap.php index c41403ba..25b07d0d 100644 --- a/src/Uuid/bootstrap.php +++ b/src/Uuid/bootstrap.php @@ -15,6 +15,10 @@ return; } +if (PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + if (!defined('UUID_VARIANT_NCS')) { define('UUID_VARIANT_NCS', 0); } @@ -56,7 +60,7 @@ } if (!function_exists('uuid_create')) { - function uuid_create($type = UUID_TYPE_DEFAULT) { return p\Uuid::uuid_create($type); } + function uuid_create($uuid_type = UUID_TYPE_DEFAULT) { return p\Uuid::uuid_create($uuid_type); } } if (!function_exists('uuid_generate_md5')) { function uuid_generate_md5($uuid_ns, $name) { return p\Uuid::uuid_generate_md5($uuid_ns, $name); } diff --git a/src/Uuid/bootstrap80.php b/src/Uuid/bootstrap80.php new file mode 100644 index 00000000..9611abc6 --- /dev/null +++ b/src/Uuid/bootstrap80.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Uuid as p; + +if (!defined('UUID_VARIANT_NCS')) { + define('UUID_VARIANT_NCS', 0); +} +if (!defined('UUID_VARIANT_DCE')) { + define('UUID_VARIANT_DCE', 1); +} +if (!defined('UUID_VARIANT_MICROSOFT')) { + define('UUID_VARIANT_MICROSOFT', 2); +} +if (!defined('UUID_VARIANT_OTHER')) { + define('UUID_VARIANT_OTHER', 3); +} +if (!defined('UUID_TYPE_DEFAULT')) { + define('UUID_TYPE_DEFAULT', 0); +} +if (!defined('UUID_TYPE_TIME')) { + define('UUID_TYPE_TIME', 1); +} +if (!defined('UUID_TYPE_MD5')) { + define('UUID_TYPE_MD5', 3); +} +if (!defined('UUID_TYPE_DCE')) { + define('UUID_TYPE_DCE', 4); // Deprecated alias +} +if (!defined('UUID_TYPE_NAME')) { + define('UUID_TYPE_NAME', 1); // Deprecated alias +} +if (!defined('UUID_TYPE_RANDOM')) { + define('UUID_TYPE_RANDOM', 4); +} +if (!defined('UUID_TYPE_SHA1')) { + define('UUID_TYPE_SHA1', 5); +} +if (!defined('UUID_TYPE_NULL')) { + define('UUID_TYPE_NULL', -1); +} +if (!defined('UUID_TYPE_INVALID')) { + define('UUID_TYPE_INVALID', -42); +} + +if (!function_exists('uuid_create')) { + function uuid_create(int $uuid_type = UUID_TYPE_DEFAULT): string { return p\Uuid::uuid_create($uuid_type); } +} +if (!function_exists('uuid_generate_md5')) { + function uuid_generate_md5(string $uuid_ns, string $name): string { return p\Uuid::uuid_generate_md5($uuid_ns, $name); } +} +if (!function_exists('uuid_generate_sha1')) { + function uuid_generate_sha1(string $uuid_ns, string $name): string { return p\Uuid::uuid_generate_sha1($uuid_ns, $name); } +} +if (!function_exists('uuid_is_valid')) { + function uuid_is_valid(string $uuid): bool { return p\Uuid::uuid_is_valid($uuid); } +} +if (!function_exists('uuid_compare')) { + function uuid_compare(string $uuid1, string $uuid2): int { return p\Uuid::uuid_compare($uuid1, $uuid2); } +} +if (!function_exists('uuid_is_null')) { + function uuid_is_null(string $uuid): bool { return p\Uuid::uuid_is_null($uuid); } +} +if (!function_exists('uuid_type')) { + function uuid_type(string $uuid): int { return p\Uuid::uuid_type($uuid); } +} +if (!function_exists('uuid_variant')) { + function uuid_variant(string $uuid): int { return p\Uuid::uuid_variant($uuid); } +} +if (!function_exists('uuid_time')) { + function uuid_time(string $uuid): int { return p\Uuid::uuid_time($uuid); } +} +if (!function_exists('uuid_mac')) { + function uuid_mac(string $uuid): string { return p\Uuid::uuid_mac($uuid); } +} +if (!function_exists('uuid_parse')) { + function uuid_parse(string $uuid): string { return p\Uuid::uuid_parse($uuid); } +} +if (!function_exists('uuid_unparse')) { + function uuid_unparse(string $uuid): string { return p\Uuid::uuid_unparse($uuid); } +}