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

merge revision 25178 to release-1.12

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25179 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob 13 лет назад
Родитель
Сommit
5a9cf80e46

+ 1 - 1
library/Zend/Amf/Parse/Amf0/Serializer.php

@@ -127,7 +127,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
                 case (is_bool($data)):
                     $markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
                     break;
-                case (is_string($data) && (strlen($data) > 65536)):
+                case (is_string($data) && (($this->_mbStringFunctionsOverloaded ? mb_strlen($data, '8bit') : strlen($data)) > 65536)):
                     $markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
                     break;
                 case (is_string($data)):

+ 2 - 2
library/Zend/Amf/Parse/Amf3/Serializer.php

@@ -215,7 +215,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @return Zend_Amf_Parse_Amf3_Serializer
      */
     protected function writeBinaryString(&$string){
-        $ref = strlen($string) << 1 | 0x01;
+        $ref = ($this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string)) << 1 | 0x01;
         $this->writeInteger($ref);
         $this->_stream->writeBytes($string);
 
@@ -230,7 +230,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      */
     public function writeString(&$string)
     {
-        $len = strlen($string);
+        $len = $this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string);
         if(!$len){
             $this->writeInteger(0x01);
             return $this;

+ 8 - 0
library/Zend/Amf/Parse/Serializer.php

@@ -38,6 +38,13 @@ abstract class Zend_Amf_Parse_Serializer
     protected $_stream;
 
     /**
+     * str* functions overloaded using mbstring.func_overload
+     *
+     * @var bool
+     */
+    protected $mbStringFunctionsOverloaded;
+
+    /**
      * Constructor
      *
      * @param  Zend_Amf_Parse_OutputStream $stream
@@ -46,6 +53,7 @@ abstract class Zend_Amf_Parse_Serializer
     public function __construct(Zend_Amf_Parse_OutputStream $stream)
     {
         $this->_stream = $stream;
+        $this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
     }
 
     /**

+ 11 - 5
library/Zend/Amf/Util/BinaryStream.php

@@ -51,6 +51,11 @@ class Zend_Amf_Util_BinaryStream
     protected $_needle;
 
     /**
+     * @var bool str* functions overloaded using mbstring.func_overload?
+     */
+    protected $_mbStringFunctionsOverloaded;
+
+    /**
      * Constructor
      *
      * Create a reference to a byte stream that is going to be parsed or created
@@ -69,7 +74,8 @@ class Zend_Amf_Util_BinaryStream
 
         $this->_stream       = $stream;
         $this->_needle       = 0;
-        $this->_streamLength = strlen($stream);
+        $this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
+        $this->_streamLength = $this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream);
         $this->_bigEndian    = (pack('l', 1) === "\x00\x00\x00\x01");
     }
 
@@ -97,7 +103,7 @@ class Zend_Amf_Util_BinaryStream
             require_once 'Zend/Amf/Exception.php';
             throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
         }
-        $bytes = substr($this->_stream, $this->_needle, $length);
+        $bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, $length, '8bit') : substr($this->_stream, $this->_needle, $length);
         $this->_needle+= $length;
         return $bytes;
     }
@@ -184,7 +190,7 @@ class Zend_Amf_Util_BinaryStream
      */
     public function writeUtf($stream)
     {
-        $this->writeInt(strlen($stream));
+        $this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
         $this->_stream.= $stream;
         return $this;
     }
@@ -209,7 +215,7 @@ class Zend_Amf_Util_BinaryStream
      */
     public function writeLongUtf($stream)
     {
-        $this->writeLong(strlen($stream));
+        $this->writeLong($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
         $this->_stream.= $stream;
     }
 
@@ -255,7 +261,7 @@ class Zend_Amf_Util_BinaryStream
      */
     public function readDouble()
     {
-        $bytes = substr($this->_stream, $this->_needle, 8);
+        $bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, 8, '8bit') : substr($this->_stream, $this->_needle, 8);
         $this->_needle+= 8;
 
         if (!$this->_bigEndian) {