diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3bac36b..694bc03 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -651,10 +651,6 @@ function drupal_environment_initialize() { // Set sane locale settings, to ensure consistent string, dates, times and // numbers handling. setlocale(LC_ALL, 'C'); - - // Detect string handling method. - require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Utility/Unicode.php'; - Unicode::check(); } /** @@ -2201,6 +2197,9 @@ function _drupal_bootstrap_configuration() { // Start a page timer: Timer::start('page'); + // Detect string handling method. + Unicode::check(); + // Load the procedural configuration system helper functions. require_once DRUPAL_ROOT . '/core/includes/config.inc'; diff --git a/core/includes/unicode.inc b/core/includes/unicode.inc index 3b3a8da..5abf5ea 100644 --- a/core/includes/unicode.inc +++ b/core/includes/unicode.inc @@ -16,17 +16,17 @@ function unicode_requirements() { $t = get_t(); $libraries = array( - UNICODE_SINGLEBYTE => $t('Standard PHP'), - UNICODE_MULTIBYTE => $t('PHP Mbstring Extension'), - UNICODE_ERROR => $t('Error'), + Unicode::STATUS_SINGLEBYTE => $t('Standard PHP'), + Unicode::STATUS_MULTIBYTE => $t('PHP Mbstring Extension'), + Unicode::STATUS_ERROR => $t('Error'), ); $severities = array( - UNICODE_SINGLEBYTE => REQUIREMENT_WARNING, - UNICODE_MULTIBYTE => NULL, - UNICODE_ERROR => REQUIREMENT_ERROR, + Unicode::STATUS_SINGLEBYTE => REQUIREMENT_WARNING, + Unicode::STATUS_MULTIBYTE => NULL, + Unicode::STATUS_ERROR => REQUIREMENT_ERROR, ); $failed_check = Unicode::check(); - $library = $GLOBALS['multibyte']; + $library = Unicode::getStatus(); $requirements['unicode'] = array( 'title' => $t('Unicode library'), @@ -148,6 +148,9 @@ function drupal_convert_to_utf8($data, $encoding) { * @return string * The truncated string. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\Unicode::truncateBytes() instead. + * * @see \Drupal\Component\Utility\Unicode::truncateBytes(). */ function drupal_truncate_bytes($string, $len) { @@ -188,6 +191,9 @@ function drupal_truncate_bytes($string, $len) { * @return string * The truncated string. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::truncate() instead. + * * @see \Drupal\Component\Utility\Unicode::truncate(). */ function truncate_utf8($string, $max_length, $wordsafe = FALSE, $add_ellipsis = FALSE, $min_wordsafe_length = 1) { @@ -203,6 +209,9 @@ function truncate_utf8($string, $max_length, $wordsafe = FALSE, $add_ellipsis = * @return string * The mime-encoded header. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\Unicode::mimeHeaderEncode() instead. + * * @see mime_header_decode() * @see \Drupal\Component\Utility\Unicode::mimeHeaderEncode(). */ @@ -219,6 +228,9 @@ function mime_header_encode($string) { * @return string * The mime-decoded header. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\Unicode::mimeHeaderDecode() instead. + * * @see mime_header_encode() * @see \Drupal\Component\Utility\Unicode::mimeHeaderDecode(). */ @@ -235,6 +247,9 @@ function mime_header_decode($header) { * @return * The input $text, with all HTML entities decoded once. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\Unicode::decodeEntities() instead. + * * @see \Drupal\Component\Utility\Unicode::decodeEntities(). */ function decode_entities($text) { @@ -250,6 +265,9 @@ function decode_entities($text) { * @return integer * The length of the string. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::length() instead. + * * @see \Drupal\Component\Utility\String::length(). * @ingroup php_wrappers */ @@ -266,6 +284,9 @@ function drupal_strlen($text) { * @return string * The string in uppercase. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::toUpperCase() instead. + * * @see \Drupal\Component\Utility\String::toUpperCase(). * @ingroup php_wrappers */ @@ -282,6 +303,9 @@ function drupal_strtoupper($text) { * @return string * The string in lowercase. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::toLowerCase() instead. + * * @see \Drupal\Component\Utility\String::toLowerCase(). * @ingroup php_wrappers */ @@ -298,6 +322,9 @@ function drupal_strtolower($text) { * @return * The string with the first letter as uppercase. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::upperCaseFirst() instead. + * * @see \Drupal\Component\Utility\String::upperCaseFirst(). * @ingroup php_wrappers */ @@ -318,6 +345,9 @@ function drupal_ucfirst($text) { * @return * The shortened string. * + * @deprecated as of Drupal 8.0. + * Use \Drupal\Component\Utility\String::substract() instead. + * * @see \Drupal\Component\Utility\String::toUpper(). * @ingroup php_wrappers */ diff --git a/core/lib/Drupal/Component/Utility/String.php b/core/lib/Drupal/Component/Utility/String.php index 3bfa56d..5b04033 100644 --- a/core/lib/Drupal/Component/Utility/String.php +++ b/core/lib/Drupal/Component/Utility/String.php @@ -119,7 +119,7 @@ public static function placeholder($text) { * The length of the string. */ public static function length($text) { - if (Unicode::$status == Unicode::STATUS_MULTIBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_MULTIBYTE) { return mb_strlen($text); } else { @@ -138,14 +138,14 @@ public static function length($text) { * The string in uppercase. */ public static function toUpperCase($text) { - if (Unicode::$status == Unicode::STATUS_MULTIBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_MULTIBYTE) { return mb_strtoupper($text); } else { // Use C-locale for ASCII-only uppercase $text = strtoupper($text); // Case flip Latin-1 accented letters - $text = preg_replace_callback('/\xC3[\xA0-\xB6\xB8-\xBE]/', array('Unicode', 'caseFlip') , $text); + $text = preg_replace_callback('/\xC3[\xA0-\xB6\xB8-\xBE]/', array('\Drupal\Component\Utility\Unicode', 'caseFlip') , $text); return $text; } } @@ -160,15 +160,14 @@ public static function toUpperCase($text) { * The string in lowercase. */ public static function toLowerCase($text) { - global $multibyte; - if (Unicode::$status == Unicode::STATUS_MULTIBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_MULTIBYTE) { return mb_strtolower($text); } else { // Use C-locale for ASCII-only lowercase $text = strtolower($text); // Case flip Latin-1 accented letters - $text = preg_replace_callback('/\xC3[\x80-\x96\x98-\x9E]/', array('Unicode', 'caseFlip'), $text); + $text = preg_replace_callback('/\xC3[\x80-\x96\x98-\x9E]/', array('\Drupal\Component\Utility\Unicode', 'caseFlip'), $text); return $text; } } @@ -204,7 +203,7 @@ public static function upperCaseFirst($text) { * The shortened string. */ public static function substract($text, $start, $length = NULL) { - if (Unicode::$status == Unicode::STATUS_MULTIBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_MULTIBYTE) { return $length === NULL ? mb_substr($text, $start) : mb_substr($text, $start, $length); } else { diff --git a/core/lib/Drupal/Component/Utility/Unicode.php b/core/lib/Drupal/Component/Utility/Unicode.php index e26ab90..5a460b2 100644 --- a/core/lib/Drupal/Component/Utility/Unicode.php +++ b/core/lib/Drupal/Component/Utility/Unicode.php @@ -95,7 +95,29 @@ class Unicode { * * @var int */ - public static $status = 0; + protected static $status = 0; + + /** + * Get the current status of unicode/multibyte support on this enviroment. + */ + public static function getStatus() { + return static::$status; + } + + /** + * Sets the name for multibyte support status for the current enviroment. + * + * The following header keys are supported: + * - Unicode::STATUS_MULTIBYTE: Standard PHP (emulated) unicode support. + * - Unicode::STATUS_SINGLEBYTE: Full unicode support using an extension. + * - Unicode::STATUS_ERROR: An error occured. No unicode support. + * + * @param int $status + * The new status of multibyte support. + */ + public static function setStatus($status) { + static::$status = $status; + } /** * Checks for Unicode support in PHP and sets the proper settings if possible. @@ -295,6 +317,8 @@ public static function caseFlip(array $matches) { * * @return string * The mime-decoded string. + * + * @todo Find a better name for this method. */ public static function _mimeHeaderDecode($matches) { // Regexp groups: diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 15b8935..6501a85 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -1103,7 +1103,7 @@ function search_data($keys, $module, $conditions = NULL) { */ function search_excerpt($keys, $text, $langcode = NULL) { // We highlight around non-indexable or CJK characters. - $boundary = '(?:(?<=[' . Unicode::PREG_CLASS_WORD_BOUNDARY . PREG_CLASS_CJK . '])|(?=[' . PREG_CLASS_UNICODE_WORD_BOUNDARY . PREG_CLASS_CJK . ']))'; + $boundary = '(?:(?<=[' . Unicode::PREG_CLASS_WORD_BOUNDARY . PREG_CLASS_CJK . '])|(?=[' . Unicode::PREG_CLASS_WORD_BOUNDARY . PREG_CLASS_CJK . ']))'; // Extract positive keywords and phrases preg_match_all('/ ("([^"]+)"|(?!OR)([^" ]+))/', ' ' . $keys, $matches); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/UnicodeUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/System/UnicodeUnitTest.php index 052694f..a145f03 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/UnicodeUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/UnicodeUnitTest.php @@ -36,11 +36,11 @@ public static function getInfo() { function testMbStringUnicode() { // mbstring was not detected on this installation, there is no way to test // multibyte features. Treat that as an exception. - if (Unicode::$status == Unicode::STATUS_SINGLEBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_SINGLEBYTE) { $this->error(t('Unable to test Multibyte features: mbstring extension was not detected.')); } - $multibyte = Unicode::STATUS_MULTIBYTE; + Unicode::setStatus(Unicode::STATUS_MULTIBYTE); $this->extendedMode = TRUE; $this->pass(t('Testing in mbstring mode')); @@ -57,9 +57,7 @@ function testMbStringUnicode() { * Test emulated unicode features. */ function testEmulatedUnicode() { - global $multibyte; - - $multibyte = Unicode::STATUS_SINGLEBYTE; + Unicode::setStatus(Unicode::STATUS_SINGLEBYTE); $this->extendedMode = FALSE; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index bb1223d..8adfaff 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -243,8 +243,6 @@ public function sanitizeValue($value, $type = NULL) { * The transformed string. */ protected function caseTransform($string, $option) { - global $multibyte; - switch ($option) { default: return $string; @@ -255,7 +253,7 @@ protected function caseTransform($string, $option) { case 'ucfirst': return drupal_strtoupper(drupal_substr($string, 0, 1)) . drupal_substr($string, 1); case 'ucwords': - if ($multibyte == Unicode::STATUS_MULTIBYTE) { + if (Unicode::getStatus() == Unicode::STATUS_MULTIBYTE) { return mb_convert_case($string, MB_CASE_TITLE); } else {