diff -ru Amf.noref-writeString/Parse/Amf0/Serializer.php Amf.mod/Parse/Amf0/Serializer.php --- Amf.noref-writeString/Parse/Amf0/Serializer.php 2009-11-12 10:26:19.000000000 -0600 +++ Amf.mod/Parse/Amf0/Serializer.php 2009-12-18 14:17:14.000000000 -0600 @@ -57,58 +57,9 @@ * @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) { - if (null !== $markerType) { - //try to refrence the given object - if( !$this->writeObjectReference($data, $markerType) ) { - - // Write the Type Marker to denote the following action script data type - $this->_stream->writeByte($markerType); - switch($markerType) { - case Zend_Amf_Constants::AMF0_NUMBER: - $this->_stream->writeDouble($data); - break; - case Zend_Amf_Constants::AMF0_BOOLEAN: - $this->_stream->writeByte($data); - break; - case Zend_Amf_Constants::AMF0_STRING: - $this->_stream->writeUTF($data); - break; - case Zend_Amf_Constants::AMF0_OBJECT: - $this->writeObject($data); - break; - case Zend_Amf_Constants::AMF0_NULL: - break; - case Zend_Amf_Constants::AMF0_REFERENCE: - $this->_stream->writeInt($data); - break; - case Zend_Amf_Constants::AMF0_MIXEDARRAY: - // Write length of numeric keys as zero. - $this->_stream->writeLong(0); - $this->writeObject($data); - break; - case Zend_Amf_Constants::AMF0_ARRAY: - $this->writeArray($data); - break; - case Zend_Amf_Constants::AMF0_DATE: - $this->writeDate($data); - break; - case Zend_Amf_Constants::AMF0_LONGSTRING: - $this->_stream->writeLongUTF($data); - break; - case Zend_Amf_Constants::AMF0_TYPEDOBJECT: - $this->writeTypedObject($data); - break; - case Zend_Amf_Constants::AMF0_AMF3: - $this->writeAmf3TypeMarker($data); - break; - default: - require_once 'Zend/Amf/Exception.php'; - throw new Zend_Amf_Exception("Unknown Type Marker: " . $markerType); - } - } - } else { + if (null === $markerType) { if(is_resource($data)) { $data = Zend_Amf_Parse_TypeLoader::handleResource($data); } @@ -168,9 +119,56 @@ default: require_once 'Zend/Amf/Exception.php'; throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data)); + return; } + } - $this->writeTypeMarker($data, $markerType); + //try to refrence the given object + if( !$this->writeObjectReference($data, $markerType) ) { + // Write the Type Marker to denote the following action script data type + $this->_stream->writeByte($markerType); + switch($markerType) { + case Zend_Amf_Constants::AMF0_NUMBER: + $this->_stream->writeDouble($data); + break; + case Zend_Amf_Constants::AMF0_BOOLEAN: + $this->_stream->writeByte($data); + break; + case Zend_Amf_Constants::AMF0_STRING: + $this->_stream->writeUTF($data); + break; + case Zend_Amf_Constants::AMF0_OBJECT: + $this->writeObject($data); + break; + case Zend_Amf_Constants::AMF0_NULL: + break; + case Zend_Amf_Constants::AMF0_REFERENCE: + $this->_stream->writeInt($data); + break; + case Zend_Amf_Constants::AMF0_MIXEDARRAY: + // Write length of numeric keys as zero. + $this->_stream->writeLong(0); + $this->writeObject($data); + break; + case Zend_Amf_Constants::AMF0_ARRAY: + $this->writeArray($data); + break; + case Zend_Amf_Constants::AMF0_DATE: + $this->writeDate($data); + break; + case Zend_Amf_Constants::AMF0_LONGSTRING: + $this->_stream->writeLongUTF($data); + break; + case Zend_Amf_Constants::AMF0_TYPEDOBJECT: + $this->writeTypedObject($data); + break; + case Zend_Amf_Constants::AMF0_AMF3: + $this->writeAmf3TypeMarker($data); + break; + default: + require_once 'Zend/Amf/Exception.php'; + throw new Zend_Amf_Exception("Unknown Type Marker: " . $markerType); + } } return $this; } @@ -183,7 +181,7 @@ * @param $markerType AMF type of the object to write * @return Boolean true, if the reference was written, false otherwise */ - protected function writeObjectReference($object, $markerType){ + protected function writeObjectReference(&$object, $markerType){ if( $markerType == Zend_Amf_Constants::AMF0_OBJECT || $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY || $markerType == Zend_Amf_Constants::AMF0_ARRAY || @@ -208,10 +206,10 @@ * @param object $data * @return Zend_Amf_Parse_Amf0_Serializer */ - public function writeObject($object) + 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 _ provate transient if( $key[0] == "_") continue; $this->_stream->writeUTF($key); @@ -231,7 +229,7 @@ * @param array $array * @return Zend_Amf_Parse_Amf0_Serializer */ - public function writeArray($array) + public function writeArray(&$array) { $length = count($array); if (!$length < 0) { @@ -254,7 +252,7 @@ * @param DateTime|Zend_Date $data * @return Zend_Amf_Parse_Amf0_Serializer */ - public function writeDate($data) + public function writeDate(&$data) { if ($data instanceof DateTime) { $dateString = $data->format('U'); @@ -281,7 +279,7 @@ * @param object $data * @return Zend_Amf_Parse_Amf0_Serializer */ - public function writeTypedObject($data) + public function writeTypedObject(&$data) { $this->_stream->writeUTF($this->_className); $this->writeObject($data); @@ -295,7 +293,7 @@ * @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); @@ -310,7 +308,7 @@ * @param object $object * @return false|string $className */ - protected function getClassName($object) + protected function getClassName(&$object) { require_once 'Zend/Amf/Parse/TypeLoader.php'; //Check to see if the object is a typed object and we need to change diff -ru Amf.noref-writeString/Parse/Amf3/Serializer.php Amf.mod/Parse/Amf3/Serializer.php --- Amf.noref-writeString/Parse/Amf3/Serializer.php 2009-12-30 10:22:02.000000000 -0600 +++ Amf.mod/Parse/Amf3/Serializer.php 2009-12-30 10:20:32.000000000 -0600 @@ -37,6 +37,12 @@ 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 */ @@ -65,54 +71,15 @@ * @param int $markerType * @return void */ - public function writeTypeMarker($data, $markerType=null) + public function writeTypeMarker(&$data, $markerType=null) { - if (null !== $markerType) { - // Write the Type Marker to denote the following action script data type - $this->_stream->writeByte($markerType); - - switch ($markerType) { - case Zend_Amf_Constants::AMF3_NULL: - break; - case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE: - break; - case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE: - break; - case Zend_Amf_Constants::AMF3_INTEGER: - $this->writeInteger($data); - break; - case Zend_Amf_Constants::AMF3_NUMBER: - $this->_stream->writeDouble($data); - break; - case Zend_Amf_Constants::AMF3_STRING: - $this->writeString($data); - break; - case Zend_Amf_Constants::AMF3_DATE: - $this->writeDate($data); - break; - case Zend_Amf_Constants::AMF3_ARRAY: - $this->writeArray($data); - break; - case Zend_Amf_Constants::AMF3_OBJECT: - $this->writeObject($data); - break; - case Zend_Amf_Constants::AMF3_BYTEARRAY: - $this->writeByteArray($data); - break; - case Zend_Amf_Constants::AMF3_XMLSTRING; - $this->writeXml($data); - break; - default: - require_once 'Zend/Amf/Exception.php'; - throw new Zend_Amf_Exception('Unknown Type Marker: ' . $markerType); - } - } else { + if (null === $markerType) { // Detect Type Marker if(is_resource($data)) { $data = Zend_Amf_Parse_TypeLoader::handleResource($data); } - switch (true) { - case (null === $data): + switch (true) { + case (null === $data): $markerType = Zend_Amf_Constants::AMF3_NULL; break; case (is_bool($data)): @@ -153,8 +120,47 @@ default: require_once 'Zend/Amf/Exception.php'; throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data)); - } - $this->writeTypeMarker($data, $markerType); + return; + } + } + + // Write the Type Marker to denote the following action script data type + $this->_stream->writeByte($markerType); + + switch ($markerType) { + case Zend_Amf_Constants::AMF3_NULL: + break; + case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE: + break; + case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE: + break; + case Zend_Amf_Constants::AMF3_INTEGER: + $this->writeInteger($data); + break; + case Zend_Amf_Constants::AMF3_NUMBER: + $this->_stream->writeDouble($data); + break; + case Zend_Amf_Constants::AMF3_STRING: + $this->writeString($data); + break; + case Zend_Amf_Constants::AMF3_DATE: + $this->writeDate($data); + break; + case Zend_Amf_Constants::AMF3_ARRAY: + $this->writeArray($data); + break; + case Zend_Amf_Constants::AMF3_OBJECT: + $this->writeObject($data); + break; + case Zend_Amf_Constants::AMF3_BYTEARRAY: + $this->writeByteArray($data); + break; + case Zend_Amf_Constants::AMF3_XMLSTRING; + $this->writeXml($data); + break; + default: + require_once 'Zend/Amf/Exception.php'; + throw new Zend_Amf_Exception('Unknown Type Marker: ' . $markerType); } } @@ -198,7 +204,7 @@ * @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); @@ -212,7 +218,7 @@ * @param string $string * @return Zend_Amf_Parse_Amf3_Serializer */ - public function writeString($string) + public function writeString(&$string) { $len = strlen($string); if(!$len){ @@ -238,7 +244,7 @@ * @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; } @@ -263,7 +269,7 @@ * @param DOMDocument|SimpleXMLElement $xml * @return Zend_Amf_Parse_Amf3_Serializer */ - public function writeXml($xml) + public function writeXml(&$xml) { if($this->writeObjectReference($xml)){ return $this; @@ -291,7 +297,7 @@ * @param DateTime|Zend_Date $date * @return Zend_Amf_Parse_Amf3_Serializer */ - public function writeDate($date) + public function writeDate(&$date) { if($this->writeObjectReference($date)){ return $this; @@ -318,16 +324,16 @@ * @param array $array * @return Zend_Amf_Parse_Amf3_Serializer */ - public function writeArray(array $array) + public function writeArray(&$array) { if($this->writeObjectReference($array)){ return $this; } - // have to seperate mixed from numberic keys. + // have to seperate mixed from numeric keys. $numeric = array(); $string = array(); - foreach ($array as $key => $value) { + foreach ($array as $key => &$value) { if (is_int($key)) { $numeric[] = $value; } else { @@ -341,14 +347,14 @@ $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; @@ -361,7 +367,7 @@ * @param mixed $object object to check for reference * @return Boolean true, if the reference was written, false otherwise */ - protected function writeObjectReference($object){ + protected function writeObjectReference(&$object){ $ref = array_search($object, $this->_referenceObjects,true); //quickly handle object references if($ref !== false){ @@ -379,7 +385,7 @@ * @param mixed $data * @return Zend_Amf_Parse_Amf3_Serializer */ - public function writeObject($object) + public function writeObject(&$object) { if($this->writeObjectReference($object)){ return $this; @@ -484,7 +490,7 @@ } //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'; diff -ru Amf.noref-writeString/Parse/Serializer.php Amf.mod/Parse/Serializer.php --- Amf.noref-writeString/Parse/Serializer.php 2009-11-12 10:26:19.000000000 -0600 +++ Amf.mod/Parse/Serializer.php 2009-12-18 14:13:08.000000000 -0600 @@ -55,5 +55,5 @@ * @param int $markerType * @return void */ - public abstract function writeTypeMarker($content, $markerType=null); + public abstract function writeTypeMarker(&$content, $markerType=null); }