Browse Source

Changes to suport fixing ZF-7493. Rolled Zend_Amf back to 1.9.6 and manually applied changes to roll it forward. Left in support for passing by ref.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21849 44c647ce-9c0f-0410-b52a-842ac1e357ba
calevans 16 years ago
parent
commit
295678ff19

+ 20 - 9
library/Zend/Amf/Parse/Amf0/Serializer.php

@@ -55,13 +55,18 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * auto negotiates the type or relies on the user defined markerType to
      * serialize the data into amf
      *
-     * @param  misc $data
-     * @param  misc $markerType
+     * @param  mixed $data
+     * @param  mixed $markerType
+     * @param  mixed $dataByVal
      * @return Zend_Amf_Parse_Amf0_Serializer
      * @throws Zend_Amf_Exception for unrecognized types or data
      */
-    public function writeTypeMarker($data, $markerType = null)
+    public function writeTypeMarker(&$data, $markerType=null, $dataByVal=false)
     {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference" 
+        if (is_null($data) && ($dataByVal !== false)) {
+            $data = &$dataByVal;
+        }
         if (null !== $markerType) {
             //try to reference the given object
             if( !$this->writeObjectReference($data, $markerType) ) {
@@ -182,17 +187,23 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * Check if the given object is in the reference table, write the reference if it exists,
      * otherwise add the object to the reference table
      *
-     * @param mixed $object object to check for reference
+     * @param mixed $object object reference to check for reference
      * @param $markerType AMF type of the object to write
+     * @param mixed $objectByVal object to check for reference
      * @return Boolean true, if the reference was written, false otherwise
      */
-    protected function writeObjectReference($object, $markerType){
+    protected function writeObjectReference(&$object, $markerType, $objectByVal=false) {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+        if (is_null($object) && ($objectByVal !== false)) {
+            $object = &$objectByVal;
+        }
+
         if( $markerType == Zend_Amf_Constants::AMF0_OBJECT ||
             $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY ||
             $markerType == Zend_Amf_Constants::AMF0_ARRAY ||
             $markerType == Zend_Amf_Constants::AMF0_TYPEDOBJECT ) {
 
-            $ref = array_search($object, $this->_referenceObjects,true);
+            $ref = array_search($object, $this->_referenceObjects, true);
             //handle object reference
             if($ref !== false){
                 $this->writeTypeMarker($ref,Zend_Amf_Constants::AMF0_REFERENCE);
@@ -214,7 +225,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
     public function writeObject($object)
     {
         // Loop each element and write the name of the property.
-        foreach ($object as $key => $value) {
+        foreach ($object as $key => &$value) {
             // skip variables starting with an _ private transient
             if( $key[0] == "_") continue;
             $this->_stream->writeUTF($key);
@@ -234,7 +245,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * @param array $array
      * @return Zend_Amf_Parse_Amf0_Serializer
      */
-    public function writeArray($array)
+    public function writeArray(&$array)
     {
         $length = count($array);
         if (!$length < 0) {
@@ -298,7 +309,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * @param  string $data
      * @return Zend_Amf_Parse_Amf0_Serializer
      */
-    public function writeAmf3TypeMarker($data)
+    public function writeAmf3TypeMarker(&$data)
     {
         require_once 'Zend/Amf/Parse/Amf3/Serializer.php';
         $serializer = new Zend_Amf_Parse_Amf3_Serializer($this->_stream);

+ 7 - 10
library/Zend/Amf/Parse/Amf3/Deserializer.php

@@ -20,9 +20,6 @@
  * @version    $Id$
  */
 
-/** Zend_Amf_Constants */
-require_once 'Zend/Amf/Constants.php';
-
 /** Zend_Amf_Parse_Deserializer */
 require_once 'Zend/Amf/Parse/Deserializer.php';
 
@@ -34,7 +31,7 @@ require_once 'Zend/Amf/Parse/TypeLoader.php';
  *
  * @todo       readObject to handle Typed Objects
  * @todo       readXMLStrimg to be implemented.
- * @todo       Class could be implemented as Factory Class with each data type it's own class.
+ * @todo       Class could be implmented as Factory Class with each data type it's own class.
  * @package    Zend_Amf
  * @subpackage Parse_Amf3
  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
@@ -397,13 +394,13 @@ class Zend_Amf_Parse_Amf3_Deserializer extends Zend_Amf_Parse_Deserializer
 
         }
 
-        if($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
-            if(isset($returnObject->externalizedData)) {
-                $returnObject = $returnObject->externalizedData;
-            } else {
-                $returnObject = get_object_vars($returnObject);
-            }
+       if($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
+        if(isset($returnObject->externalizedData)) {
+            $returnObject = $returnObject->externalizedData;
+        } else {
+            $returnObject = get_object_vars($returnObject);
         }
+       }
 
         return $returnObject;
     }

+ 36 - 17
library/Zend/Amf/Parse/Amf3/Serializer.php

@@ -23,6 +23,7 @@
 /** Zend_Amf_Constants */
 require_once 'Zend/Amf/Constants.php';
 
+
 /** Zend_Amf_Parse_Serializer */
 require_once 'Zend/Amf/Parse/Serializer.php';
 
@@ -39,6 +40,13 @@ require_once 'Zend/Amf/Parse/TypeLoader.php';
  */
 class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
 {
+
+     /**
+     * A constant empty string
+     * @var string
+     */
+    protected $_strEmpty = '';
+    
     /**
      * An array of reference objects per amf body
      * @var array
@@ -64,12 +72,17 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * auto negotiates the type or use the user defined markerType to
      * serialize the data from php back to AMF3
      *
-     * @param  mixed $content
+     * @param  mixed $data
      * @param  int $markerType
+     * @param  mixed $dataByVal
      * @return void
      */
-    public function writeTypeMarker($data, $markerType=null)
+    public function writeTypeMarker(&$data, $markerType=null, $dataByVal=false)
     {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+        if (is_null($data) && ($dataByVal !== false)) {
+            $data = &$dataByVal;
+        }
         if (null !== $markerType) {
             // Write the Type Marker to denote the following action script data type
             $this->_stream->writeByte($markerType);
@@ -114,7 +127,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
             if(is_resource($data)) {
                 $data = Zend_Amf_Parse_TypeLoader::handleResource($data);
             }
-             switch (true) {
+            switch (true) {
                 case (null === $data):
                     $markerType = Zend_Amf_Constants::AMF3_NULL;
                     break;
@@ -156,7 +169,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
                 default:
                     require_once 'Zend/Amf/Exception.php';
                     throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
-             }
+            }
             $this->writeTypeMarker($data, $markerType);
         }
     }
@@ -201,7 +214,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param  string $string
      * @return Zend_Amf_Parse_Amf3_Serializer
      */
-    protected function writeBinaryString($string){
+    protected function writeBinaryString(&$string){
         $ref = strlen($string) << 1 | 0x01;
         $this->writeInteger($ref);
         $this->_stream->writeBytes($string);
@@ -215,7 +228,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param  string $string
      * @return Zend_Amf_Parse_Amf3_Serializer
      */
-    public function writeString($string)
+    public function writeString(&$string)
     {
         $len = strlen($string);
         if(!$len){
@@ -241,7 +254,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param  string|Zend_Amf_Value_ByteArray  $data
      * @return Zend_Amf_Parse_Amf3_Serializer
      */
-    public function writeByteArray($data){
+    public function writeByteArray(&$data){
         if($this->writeObjectReference($data)){
             return $this;
         }
@@ -321,15 +334,15 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param array $array
      * @return Zend_Amf_Parse_Amf3_Serializer
      */
-    public function writeArray(array $array)
+    public function writeArray(&$array)
     {
-	// arrays aren't reference here but still counted
+        // arrays aren't reference here but still counted
         $this->_referenceObjects[] = $array;
 
         // have to seperate mixed from numberic keys.
         $numeric = array();
         $string  = array();
-        foreach ($array as $key => $value) {
+        foreach ($array as $key => &$value) {
             if (is_int($key)) {
                 $numeric[] = $value;
             } else {
@@ -343,14 +356,14 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
         $this->writeInteger($id);
 
         //Write the mixed type array to the output stream
-        foreach($string as $key => $value) {
+        foreach($string as $key => &$value) {
             $this->writeString($key)
                  ->writeTypeMarker($value);
         }
-        $this->writeString('');
+        $this->writeString($this->_strEmpty);
 
         // Write the numeric array to ouput stream
-        foreach($numeric as $value) {
+        foreach($numeric as &$value) {
             $this->writeTypeMarker($value);
         }
         return $this;
@@ -360,11 +373,17 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * Check if the given object is in the reference table, write the reference if it exists,
      * otherwise add the object to the reference table
      *
-     * @param mixed $object object to check for reference
+     * @param mixed $object object reference to check for reference
+     * @param mixed $objectByVal object to check for reference
      * @return Boolean true, if the reference was written, false otherwise
      */
-    protected function writeObjectReference($object)
+    protected function writeObjectReference(&$object, $objectByVal=false)
     {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+        if (is_null($object) && ($objectByVal !== false)) {
+            $object = &$objectByVal;
+        }
+
         $ref = array_search($object, $this->_referenceObjects,true);
         //quickly handle object references
         if($ref !== false){
@@ -411,7 +430,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
                 $className = '';
                 break;
 
-            // By default, use object's class name
+             // By default, use object's class name
             default:
                 $className = get_class($object);
                 break;
@@ -487,7 +506,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
                     }
 
                     //Write an empty string to end the dynamic part
-                    $this->writeString('');
+                    $this->writeString($this->_strEmpty);
                     break;
                 case Zend_Amf_Constants::ET_EXTERNAL:
                     require_once 'Zend/Amf/Exception.php';

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

@@ -53,7 +53,8 @@ abstract class Zend_Amf_Parse_Serializer
      *
      * @param  mixed $content
      * @param  int $markerType
+     * @param  mixed $contentByVal
      * @return void
      */
-    public abstract function writeTypeMarker($content, $markerType=null);
+    public abstract function writeTypeMarker(&$content, $markerType=null, $contentByVal=false);
 }

+ 14 - 5
library/Zend/Amf/Response.php

@@ -94,7 +94,13 @@ class Zend_Amf_Response
             $stream->writeUTF($header->name);
             $stream->writeByte($header->mustRead);
             $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
-            $serializer->writeTypeMarker($header->data);
+            if (is_object($header->data)) {
+                // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+                $placeholder = null;
+                $serializer->writeTypeMarker($placeholder, null, $header->data);
+            } else {
+                $serializer->writeTypeMarker($header->data);
+            }
         }
 
         // loop through the AMF bodies that need to be returned.
@@ -105,11 +111,14 @@ class Zend_Amf_Response
             $stream->writeUTF($body->getTargetURI());
             $stream->writeUTF($body->getResponseURI());
             $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
-            if($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) {
-                $serializer->writeTypeMarker($body->getData());
+            $bodyData = $body->getData();
+            $markerType = ($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) ? null : Zend_Amf_Constants::AMF0_AMF3;
+            if (is_object($bodyData)) {
+                // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+                $placeholder = null;
+                $serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
             } else {
-                // Content is AMF3
-                $serializer->writeTypeMarker($body->getData(),Zend_Amf_Constants::AMF0_AMF3);
+                $serializer->writeTypeMarker($bodyData, $markerType);
             }
         }