Skip to content

Commit

Permalink
Fix declaring extra constants when intl is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 12, 2020
1 parent 9d1c1f2 commit f968149
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 175 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 1.17.0

* added `get_resource_id()` to the PHP 8 polyfill
* fix declaring extra constants when `intl` is loaded

# 1.16.0

Expand Down
4 changes: 4 additions & 0 deletions src/Iconv/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

use Symfony\Polyfill\Iconv as p;

if (extension_loaded('iconv')) {
return;
}

if (!defined('ICONV_IMPL')) {
define('ICONV_IMPL', 'Symfony');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Intl/Grapheme/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

use Symfony\Polyfill\Intl\Grapheme as p;

if (extension_loaded('intl')) {
return;
}

if (!defined('GRAPHEME_EXTR_COUNT')) {
define('GRAPHEME_EXTR_COUNT', 0);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Intl/Idn/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

use Symfony\Polyfill\Intl\Idn as p;

if (extension_loaded('intl')) {
return;
}

if (!defined('U_IDNA_PROHIBITED_ERROR')) {
define('U_IDNA_PROHIBITED_ERROR', 66560);
}
Expand Down
24 changes: 14 additions & 10 deletions src/Mbstring/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@

use Symfony\Polyfill\Mbstring as p;

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);
}

if (!function_exists('mb_convert_encoding')) {
function mb_convert_encoding($s, $to, $from = null) { return p\Mbstring::mb_convert_encoding($s, $to, $from); }
}
Expand Down Expand Up @@ -135,3 +125,17 @@ function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding
if (!function_exists('mb_str_split')) {
function mb_str_split($string, $split_length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $split_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);
}
36 changes: 19 additions & 17 deletions src/Php54/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@

use Symfony\Polyfill\Php54 as p;

if (PHP_VERSION_ID < 50400) {
if (!function_exists('trait_exists')) {
function trait_exists($class, $autoload = true) { return $autoload && \class_exists($class, $autoload) && false; }
}
if (!function_exists('class_uses')) {
function class_uses($class, $autoload = true)
{
if (\is_object($class) || \class_exists($class, $autoload) || \interface_exists($class, false)) {
return array();
}
if (PHP_VERSION_ID >= 50400) {
return;
}

return false;
if (!function_exists('trait_exists')) {
function trait_exists($class, $autoload = true) { return $autoload && \class_exists($class, $autoload) && false; }
}
if (!function_exists('class_uses')) {
function class_uses($class, $autoload = true)
{
if (\is_object($class) || \class_exists($class, $autoload) || \interface_exists($class, false)) {
return array();
}

return false;
}
if (!function_exists('hex2bin')) {
function hex2bin($data) { return p\Php54::hex2bin($data); }
}
if (!function_exists('session_register_shutdown')) {
function session_register_shutdown() { register_shutdown_function('session_write_close'); }
}
}
if (!function_exists('hex2bin')) {
function hex2bin($data) { return p\Php54::hex2bin($data); }
}
if (!function_exists('session_register_shutdown')) {
function session_register_shutdown() { register_shutdown_function('session_write_close'); }
}
28 changes: 15 additions & 13 deletions src/Php55/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

use Symfony\Polyfill\Php55 as p;

if (PHP_VERSION_ID < 50500) {
if (!function_exists('boolval')) {
function boolval($val) { return p\Php55::boolval($val); }
}
if (!function_exists('json_last_error_msg')) {
function json_last_error_msg() { return p\Php55::json_last_error_msg(); }
}
if (!function_exists('array_column')) {
function array_column($array, $columnKey, $indexKey = null) { return p\Php55ArrayColumn::array_column($array, $columnKey, $indexKey); }
}
if (!function_exists('hash_pbkdf2')) {
function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) { return p\Php55::hash_pbkdf2($algorithm, $password, $salt, $iterations, $length, $rawOutput); }
}
if (PHP_VERSION_ID >= 50500) {
return;
}

if (!function_exists('boolval')) {
function boolval($val) { return p\Php55::boolval($val); }
}
if (!function_exists('json_last_error_msg')) {
function json_last_error_msg() { return p\Php55::json_last_error_msg(); }
}
if (!function_exists('array_column')) {
function array_column($array, $columnKey, $indexKey = null) { return p\Php55ArrayColumn::array_column($array, $columnKey, $indexKey); }
}
if (!function_exists('hash_pbkdf2')) {
function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) { return p\Php55::hash_pbkdf2($algorithm, $password, $salt, $iterations, $length, $rawOutput); }
}
52 changes: 27 additions & 25 deletions src/Php56/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,34 @@

use Symfony\Polyfill\Php56 as p;

if (PHP_VERSION_ID < 50600) {
if (!function_exists('hash_equals')) {
function hash_equals($knownString, $userInput) { return p\Php56::hash_equals($knownString, $userInput); }
}
if (extension_loaded('ldap') && !defined('LDAP_ESCAPE_FILTER')) {
define('LDAP_ESCAPE_FILTER', 1);
}
if (extension_loaded('ldap') && !defined('LDAP_ESCAPE_DN')) {
define('LDAP_ESCAPE_DN', 2);
}
if (PHP_VERSION_ID >= 50600) {
return;
}

if (extension_loaded('ldap') && !function_exists('ldap_escape')) {
function ldap_escape($subject, $ignore = '', $flags = 0) { return p\Php56::ldap_escape($subject, $ignore, $flags); }
}
if (!function_exists('hash_equals')) {
function hash_equals($knownString, $userInput) { return p\Php56::hash_equals($knownString, $userInput); }
}
if (extension_loaded('ldap') && !defined('LDAP_ESCAPE_FILTER')) {
define('LDAP_ESCAPE_FILTER', 1);
}
if (extension_loaded('ldap') && !defined('LDAP_ESCAPE_DN')) {
define('LDAP_ESCAPE_DN', 2);
}

if (extension_loaded('ldap') && !function_exists('ldap_escape')) {
function ldap_escape($subject, $ignore = '', $flags = 0) { return p\Php56::ldap_escape($subject, $ignore, $flags); }
}

if (50509 === PHP_VERSION_ID && 4 === PHP_INT_SIZE) {
// Missing functions in PHP 5.5.9 - affects 32 bit builds of Ubuntu 14.04LTS
// See https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1315888
if (!function_exists('gzopen') && function_exists('gzopen64')) {
function gzopen($filename, $mode, $use_include_path = 0) { return gzopen64($filename, $mode, $use_include_path); }
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
function gzseek($zp, $offset, $whence = SEEK_SET) { return gzseek64($zp, $offset, $whence); }
}
if (!function_exists('gztell') && function_exists('gztell64')) {
function gztell($zp) { return gztell64($zp); }
}
if (50509 === PHP_VERSION_ID && 4 === PHP_INT_SIZE) {
// Missing functions in PHP 5.5.9 - affects 32 bit builds of Ubuntu 14.04LTS
// See https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1315888
if (!function_exists('gzopen') && function_exists('gzopen64')) {
function gzopen($filename, $mode, $use_include_path = 0) { return gzopen64($filename, $mode, $use_include_path); }
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
function gzseek($zp, $offset, $whence = SEEK_SET) { return gzseek64($zp, $offset, $whence); }
}
if (!function_exists('gztell') && function_exists('gztell64')) {
function gztell($zp) { return gztell64($zp); }
}
}
29 changes: 16 additions & 13 deletions src/Php70/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

use Symfony\Polyfill\Php70 as p;

if (PHP_VERSION_ID < 70000) {
if (!defined('PHP_INT_MIN')) {
define('PHP_INT_MIN', ~PHP_INT_MAX);
}
if (!function_exists('intdiv')) {
function intdiv($dividend, $divisor) { return p\Php70::intdiv($dividend, $divisor); }
}
if (!function_exists('preg_replace_callback_array')) {
function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0) { return p\Php70::preg_replace_callback_array($patterns, $subject, $limit, $count); }
}
if (!function_exists('error_clear_last')) {
function error_clear_last() { return p\Php70::error_clear_last(); }
}
if (PHP_VERSION_ID >= 70000) {
return;
}

if (!defined('PHP_INT_MIN')) {
define('PHP_INT_MIN', ~PHP_INT_MAX);
}

if (!function_exists('intdiv')) {
function intdiv($dividend, $divisor) { return p\Php70::intdiv($dividend, $divisor); }
}
if (!function_exists('preg_replace_callback_array')) {
function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0) { return p\Php70::preg_replace_callback_array($patterns, $subject, $limit, $count); }
}
if (!function_exists('error_clear_last')) {
function error_clear_last() { return p\Php70::error_clear_last(); }
}
6 changes: 2 additions & 4 deletions src/Php71/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

use Symfony\Polyfill\Php71 as p;

if (PHP_VERSION_ID < 70100) {
if (!function_exists('is_iterable')) {
function is_iterable($var) { return p\Php71::is_iterable($var); }
}
if (!function_exists('is_iterable')) {
function is_iterable($var) { return p\Php71::is_iterable($var); }
}
82 changes: 42 additions & 40 deletions src/Php72/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,47 @@

use Symfony\Polyfill\Php72 as p;

if (PHP_VERSION_ID < 70200) {
if (!defined('PHP_FLOAT_DIG')) {
define('PHP_FLOAT_DIG', 15);
}
if (!defined('PHP_FLOAT_EPSILON')) {
define('PHP_FLOAT_EPSILON', 2.2204460492503E-16);
}
if (!defined('PHP_FLOAT_MIN')) {
define('PHP_FLOAT_MIN', 2.2250738585072E-308);
}
if (!defined('PHP_FLOAT_MAX')) {
define('PHP_FLOAT_MAX', 1.7976931348623157E+308);
}
if (!defined('PHP_OS_FAMILY')) {
define('PHP_OS_FAMILY', p\Php72::php_os_family());
}
if (PHP_VERSION_ID >= 70200) {
return;
}

if (!defined('PHP_FLOAT_DIG')) {
define('PHP_FLOAT_DIG', 15);
}
if (!defined('PHP_FLOAT_EPSILON')) {
define('PHP_FLOAT_EPSILON', 2.2204460492503E-16);
}
if (!defined('PHP_FLOAT_MIN')) {
define('PHP_FLOAT_MIN', 2.2250738585072E-308);
}
if (!defined('PHP_FLOAT_MAX')) {
define('PHP_FLOAT_MAX', 1.7976931348623157E+308);
}
if (!defined('PHP_OS_FAMILY')) {
define('PHP_OS_FAMILY', p\Php72::php_os_family());
}

if ('\\' === DIRECTORY_SEPARATOR && !function_exists('sapi_windows_vt100_support')) {
function sapi_windows_vt100_support($stream, $enable = null) { return p\Php72::sapi_windows_vt100_support($stream, $enable); }
}
if (!function_exists('stream_isatty')) {
function stream_isatty($stream) { return p\Php72::stream_isatty($stream); }
}
if (!function_exists('utf8_encode')) {
function utf8_encode($s) { return p\Php72::utf8_encode($s); }
}
if (!function_exists('utf8_decode')) {
function utf8_decode($s) { return p\Php72::utf8_decode($s); }
}
if (!function_exists('spl_object_id')) {
function spl_object_id($s) { return p\Php72::spl_object_id($s); }
}
if (!function_exists('mb_ord')) {
function mb_ord($s, $enc = null) { return p\Php72::mb_ord($s, $enc); }
}
if (!function_exists('mb_chr')) {
function mb_chr($code, $enc = null) { return p\Php72::mb_chr($code, $enc); }
}
if (!function_exists('mb_scrub')) {
function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding() : $enc; return mb_convert_encoding($s, $enc, $enc); }
}
if ('\\' === DIRECTORY_SEPARATOR && !function_exists('sapi_windows_vt100_support')) {
function sapi_windows_vt100_support($stream, $enable = null) { return p\Php72::sapi_windows_vt100_support($stream, $enable); }
}
if (!function_exists('stream_isatty')) {
function stream_isatty($stream) { return p\Php72::stream_isatty($stream); }
}
if (!function_exists('utf8_encode')) {
function utf8_encode($s) { return p\Php72::utf8_encode($s); }
}
if (!function_exists('utf8_decode')) {
function utf8_decode($s) { return p\Php72::utf8_decode($s); }
}
if (!function_exists('spl_object_id')) {
function spl_object_id($s) { return p\Php72::spl_object_id($s); }
}
if (!function_exists('mb_ord')) {
function mb_ord($s, $enc = null) { return p\Php72::mb_ord($s, $enc); }
}
if (!function_exists('mb_chr')) {
function mb_chr($code, $enc = null) { return p\Php72::mb_chr($code, $enc); }
}
if (!function_exists('mb_scrub')) {
function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding() : $enc; return mb_convert_encoding($s, $enc, $enc); }
}
33 changes: 16 additions & 17 deletions src/Php73/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@

use Symfony\Polyfill\Php73 as p;

if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($var) { return is_array($var) || $var instanceof Countable || $var instanceof ResourceBundle || $var instanceof SimpleXmlElement; }
}

if (!function_exists('hrtime')) {
require_once __DIR__.'/Php73.php';
p\Php73::$startAt = (int) microtime(true);
function hrtime($asNum = false) { return p\Php73::hrtime($asNum); }
}

if (!function_exists('array_key_first')) {
function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } }
}
if (PHP_VERSION_ID >= 70300) {
return;
}

if (!function_exists('array_key_last')) {
function array_key_last(array $array) { end($array); return key($array); }
}
if (!function_exists('is_countable')) {
function is_countable($var) { return is_array($var) || $var instanceof Countable || $var instanceof ResourceBundle || $var instanceof SimpleXmlElement; }
}
if (!function_exists('hrtime')) {
require_once __DIR__.'/Php73.php';
p\Php73::$startAt = (int) microtime(true);
function hrtime($asNum = false) { return p\Php73::hrtime($asNum); }
}
if (!function_exists('array_key_first')) {
function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } }
}
if (!function_exists('array_key_last')) {
function array_key_last(array $array) { end($array); return key($array); }
}

0 comments on commit f968149

Please sign in to comment.