Browse Source

[ZF-10159] Zend_Locale_Format:

- added a detection for PRCE without UTF-8 support and throw an exception before PCRE does it without knowing why

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22807 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 15 years ago
parent
commit
51e80110c5
1 changed files with 23 additions and 0 deletions
  1. 23 0
      library/Zend/Locale/Format.php

+ 23 - 0
library/Zend/Locale/Format.php

@@ -193,6 +193,10 @@ class Zend_Locale_Format
      */
     public static function convertNumerals($input, $from, $to = null)
     {
+        if (!self::_getUniCodeSupport()) {
+            throw new Zend_Locale_Exception('Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core');
+        }
+
         $from   = strtolower($from);
         $source = Zend_Locale_Data::getContent('en', 'numberingsystem', $from);
         if (empty($source)) {
@@ -497,6 +501,10 @@ class Zend_Locale_Format
      */
     public static function isNumber($input, array $options = array())
     {
+        if (!self::_getUniCodeSupport()) {
+            throw new Zend_Locale_Exception('Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core');
+        }
+
         $options = self::_checkOptions($options) + self::$_options;
 
         // Get correct signs for this locale
@@ -757,6 +765,10 @@ class Zend_Locale_Format
      */
     private static function _parseDate($date, $options)
     {
+        if (!self::_getUniCodeSupport()) {
+            throw new Zend_Locale_Exception('Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core');
+        }
+
         $options = self::_checkOptions($options) + self::$_options;
         $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I',
                        'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v');
@@ -1239,4 +1251,15 @@ class Zend_Locale_Format
         }
         return self::_parseDate($datetime, $options);
     }
+
+    /**
+     * Internal method to detect of Unicode supports UTF8
+     * which should be enabled within vanilla php installations
+     *
+     * @return boolean
+     */
+    protected static function _getUniCodeSupport()
+    {
+        return (@preg_match('/\pL/u', 'a')) ? true : false;
+    }
 }