Просмотр исходного кода

iconv_set_encoding internal encoding deprecated in php 5.6

Minh-Quan Tran 11 лет назад
Родитель
Сommit
74acbbd989

+ 56 - 12
library/Zend/Locale/Format.php

@@ -310,8 +310,12 @@ class Zend_Locale_Format
         // Get correct signs for this locale
         $symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
         $oenc = iconv_get_encoding('internal_encoding');
-        iconv_set_encoding('internal_encoding', 'UTF-8');
-
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('default_charset', 'UTF-8');
+        }
+        
         // Get format
         $format = $options['number_format'];
         if ($format === null) {
@@ -345,7 +349,11 @@ class Zend_Locale_Format
         }
 
         if (iconv_strpos($format, '0') === false) {
-            iconv_set_encoding('internal_encoding', $oenc);
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', $oenc);
+            } else {
+                ini_set('default_charset', $oenc);
+            }
             require_once 'Zend/Locale/Exception.php';
             throw new Zend_Locale_Exception('Wrong format... missing 0');
         }
@@ -471,7 +479,11 @@ class Zend_Locale_Format
             }
         }
 
-        iconv_set_encoding('internal_encoding', $oenc);
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', $oenc);
+        } else {
+            ini_set('default_charset', $oenc);
+        }
         return (string) $format;
     }
 
@@ -790,7 +802,11 @@ class Zend_Locale_Format
         $result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience)
 
         $oenc = iconv_get_encoding('internal_encoding');
-        iconv_set_encoding('internal_encoding', 'UTF-8');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('default_charset', 'UTF-8');
+        }
         $day   = iconv_strpos($format, 'd');
         $month = iconv_strpos($format, 'M');
         $year  = iconv_strpos($format, 'y');
@@ -855,7 +871,11 @@ class Zend_Locale_Format
         }
 
         if (empty($parse)) {
-            iconv_set_encoding('internal_encoding', $oenc);
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', $oenc);
+            } else {
+                ini_set('default_charset', $oenc);
+            }
             require_once 'Zend/Locale/Exception.php';
             throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found");
         }
@@ -875,7 +895,11 @@ class Zend_Locale_Format
         preg_match_all('/\d+/u', $number, $splitted);
 
         if (count($splitted[0]) == 0) {
-            iconv_set_encoding('internal_encoding', $oenc);
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', $oenc);
+            } else {
+                ini_set('default_charset', $oenc);
+            }
             require_once 'Zend/Locale/Exception.php';
             throw new Zend_Locale_Exception("No date part in '$date' found.");
         }
@@ -981,7 +1005,11 @@ class Zend_Locale_Format
                 if (($position !== false) and ((iconv_strpos($date, $result['day']) === false) or
                                                (isset($result['year']) and (iconv_strpos($date, $result['year']) === false)))) {
                     if ($options['fix_date'] !== true) {
-                        iconv_set_encoding('internal_encoding', $oenc);
+                        if (PHP_VERSION_ID < 50600) {
+                            iconv_set_encoding('internal_encoding', $oenc);
+                        } else {
+                            ini_set('default_charset', $oenc);
+                        }
                         require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unable to parse date '$date' using '" . $format
                             . "' (false month, $position, $month)");
@@ -997,7 +1025,11 @@ class Zend_Locale_Format
             if (isset($result['day']) and isset($result['year'])) {
                 if ($result['day'] > 31) {
                     if ($options['fix_date'] !== true) {
-                        iconv_set_encoding('internal_encoding', $oenc);
+                        if (PHP_VERSION_ID < 50600) {
+                            iconv_set_encoding('internal_encoding', $oenc);
+                        } else {
+                            ini_set('default_charset', $oenc);
+                        }
                         require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
                                                       . $format . "' (d <> y)");
@@ -1013,7 +1045,11 @@ class Zend_Locale_Format
             if (isset($result['month']) and isset($result['year'])) {
                 if ($result['month'] > 31) {
                     if ($options['fix_date'] !== true) {
-                        iconv_set_encoding('internal_encoding', $oenc);
+                        if (PHP_VERSION_ID < 50600) {
+                            iconv_set_encoding('internal_encoding', $oenc);
+                        } else {
+                            ini_set('default_charset', $oenc);
+                        }
                         require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
                                                       . $format . "' (M <> y)");
@@ -1029,7 +1065,11 @@ class Zend_Locale_Format
             if (isset($result['month']) and isset($result['day'])) {
                 if ($result['month'] > 12) {
                     if ($options['fix_date'] !== true || $result['month'] > 31) {
-                        iconv_set_encoding('internal_encoding', $oenc);
+                        if (PHP_VERSION_ID < 50600) {
+                            iconv_set_encoding('internal_encoding', $oenc);
+                        } else {
+                            ini_set('default_charset', $oenc);
+                        }
                         require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
                                                       . $format . "' (M <> d)");
@@ -1056,7 +1096,11 @@ class Zend_Locale_Format
             }
         }
 
-        iconv_set_encoding('internal_encoding', $oenc);
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', $oenc);
+        } else {
+            ini_set('default_charset', $oenc);
+        }
         return $result;
     }
 

+ 9 - 3
library/Zend/Service/Audioscrobbler.php

@@ -71,9 +71,15 @@ class Zend_Service_Audioscrobbler
     {
         $this->set('version', '1.0');
 
-        iconv_set_encoding('output_encoding', 'UTF-8');
-        iconv_set_encoding('input_encoding', 'UTF-8');
-        iconv_set_encoding('internal_encoding', 'UTF-8');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('output_encoding', 'UTF-8');
+            iconv_set_encoding('input_encoding', 'UTF-8');
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('output_encoding', 'UTF-8');
+            ini_set('input_encoding', 'UTF-8');
+            ini_set('default_charset', 'UTF-8');
+        }
     }
 
     /**

+ 9 - 4
library/Zend/Service/Technorati.php

@@ -86,10 +86,15 @@ class Zend_Service_Technorati
      */
     public function __construct($apiKey)
     {
-        iconv_set_encoding('output_encoding', 'UTF-8');
-        iconv_set_encoding('input_encoding', 'UTF-8');
-        iconv_set_encoding('internal_encoding', 'UTF-8');
-
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('output_encoding', 'UTF-8');
+            iconv_set_encoding('input_encoding', 'UTF-8');
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('output_encoding', 'UTF-8');
+            ini_set('input_encoding', 'UTF-8');
+            ini_set('default_charset', 'UTF-8');
+        }
         $this->_apiKey = $apiKey;
     }
 

+ 10 - 2
library/Zend/Validate/Hostname.php

@@ -1106,7 +1106,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
             $status = false;
 
             $origenc = iconv_get_encoding('internal_encoding');
-            iconv_set_encoding('internal_encoding', 'UTF-8');
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', 'UTF-8');
+            } else {
+                ini_set('default_charset', 'UTF-8');
+            }
             do {
                 // First check TLD
                 $matches = array();
@@ -1202,7 +1206,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
                 }
             } while (false);
 
-            iconv_set_encoding('internal_encoding', $origenc);
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', $origenc);
+            } else {
+                ini_set('default_charset', $origenc);
+            }
             // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
             // passes validation
             if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {

+ 10 - 2
library/Zend/Validate/StringLength.php

@@ -200,13 +200,21 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract
     {
         if ($encoding !== null) {
             $orig   = iconv_get_encoding('internal_encoding');
-            $result = iconv_set_encoding('internal_encoding', $encoding);
+            if (PHP_VERSION_ID < 50600) {
+                $result = iconv_set_encoding('internal_encoding', $encoding);
+            } else {
+                $result = ini_set('default_charset', $encoding);
+            }
             if (!$result) {
                 require_once 'Zend/Validate/Exception.php';
                 throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
             }
 
-            iconv_set_encoding('internal_encoding', $orig);
+            if (PHP_VERSION_ID < 50600) {
+                iconv_set_encoding('internal_encoding', $orig);
+            } else {
+                ini_set('default_charset', $orig);
+            }
         }
 
         $this->_encoding = $encoding;

+ 9 - 3
library/Zend/XmlRpc/Client.php

@@ -257,9 +257,15 @@ class Zend_XmlRpc_Client
     {
         $this->_lastRequest = $request;
 
-        iconv_set_encoding('input_encoding', 'UTF-8');
-        iconv_set_encoding('output_encoding', 'UTF-8');
-        iconv_set_encoding('internal_encoding', 'UTF-8');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('input_encoding', 'UTF-8');
+            iconv_set_encoding('output_encoding', 'UTF-8');
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('input_encoding', 'UTF-8');
+            ini_set('output_encoding', 'UTF-8');
+            ini_set('default_charset', 'UTF-8');
+        }
 
         $http = $this->getHttpClient();
         if($http->getUri() === null) {

+ 10 - 2
tests/Zend/Validate/HostnameTest.php

@@ -59,7 +59,11 @@ class Zend_Validate_HostnameTest extends PHPUnit_Framework_TestCase
      */
     public function tearDown()
     {
-        iconv_set_encoding('internal_encoding', $this->_origEncoding);
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', $this->_origEncoding);
+        } else {
+            ini_set('default_charset', $this->_origEncoding);
+        }
     }
 
     /**
@@ -361,7 +365,11 @@ class Zend_Validate_HostnameTest extends PHPUnit_Framework_TestCase
      */
     public function testDifferentIconvEncoding()
     {
-        iconv_set_encoding('internal_encoding', 'ISO8859-1');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', 'ISO8859-1');
+        } else {
+            ini_set('default_charset', 'ISO8859-1');
+        }
         $validator = new Zend_Validate_Hostname();
 
         $valuesExpected = array(

+ 10 - 2
tests/Zend/Validate/StringLengthTest.php

@@ -59,7 +59,11 @@ class Zend_Validate_StringLengthTest extends PHPUnit_Framework_TestCase
      */
     public function testBasic()
     {
-        iconv_set_encoding('internal_encoding', 'UTF-8');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('default_charset', 'UTF-8');
+        }
         /**
          * The elements of each array are, in order:
          *      - minimum length
@@ -161,7 +165,11 @@ class Zend_Validate_StringLengthTest extends PHPUnit_Framework_TestCase
      */
     public function testDifferentEncodingWithValidator()
     {
-        iconv_set_encoding('internal_encoding', 'UTF-8');
+        if (PHP_VERSION_ID < 50600) {
+            iconv_set_encoding('internal_encoding', 'UTF-8');
+        } else {
+            ini_set('default_charset', 'UTF-8');
+        }
         $validator = new Zend_Validate_StringLength(2, 2, 'UTF-8');
         $this->assertEquals(true, $validator->isValid('ab'));