Browse Source

ZF-7493: review, and code cleanup

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21968 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 years ago
parent
commit
6d9ead55d6

+ 16 - 14
library/Zend/Amf/Parse/Amf0/Serializer.php

@@ -61,16 +61,16 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * @return Zend_Amf_Parse_Amf0_Serializer
      * @throws Zend_Amf_Exception for unrecognized types or data
      */
-    public function writeTypeMarker(&$data, $markerType=null, $dataByVal=false)
+    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)) {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
+        // variables should be passed by reference" 
+        if ((null === $data) && ($dataByVal !== false)) {
             $data = &$dataByVal;
         }
         if (null !== $markerType) {
             //try to reference the given object
-            if( !$this->writeObjectReference($data, $markerType) ) {
-
+            if (!$this->writeObjectReference($data, $markerType)) {
                 // Write the Type Marker to denote the following action script data type
                 $this->_stream->writeByte($markerType);
                 switch($markerType) {
@@ -117,7 +117,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
                 }
             }
         } else {
-            if(is_resource($data)) {
+            if (is_resource($data)) {
                 $data = Zend_Amf_Parse_TypeLoader::handleResource($data);
             }
             switch (true) {
@@ -192,17 +192,19 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
      * @param mixed $objectByVal object to check for reference
      * @return Boolean true, if the reference was written, false otherwise
      */
-    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)) {
+    protected function writeObjectReference(&$object, $markerType, $objectByVal = false) 
+    {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
+        // variables should be passed by reference"
+        if ((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 ) {
-
+        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);
             //handle object reference
             if($ref !== false){

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

@@ -31,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 implmented as Factory Class with each data type it's own class.
+ * @todo       Class could be implemented 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)
@@ -394,12 +394,12 @@ 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;

+ 19 - 16
library/Zend/Amf/Parse/Amf3/Serializer.php

@@ -40,8 +40,7 @@ require_once 'Zend/Amf/Parse/TypeLoader.php';
  */
 class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
 {
-
-     /**
+    /**
      * A constant empty string
      * @var string
      */
@@ -77,10 +76,11 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param  mixed $dataByVal
      * @return void
      */
-    public function writeTypeMarker(&$data, $markerType=null, $dataByVal=false)
+    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)) {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
+        // variables should be passed by reference"
+        if ((null === $data) && ($dataByVal !== false)) {
             $data = &$dataByVal;
         }
         if (null !== $markerType) {
@@ -124,7 +124,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
             }
         } else {
             // Detect Type Marker
-            if(is_resource($data)) {
+            if (is_resource($data)) {
                 $data = Zend_Amf_Parse_TypeLoader::handleResource($data);
             }
             switch (true) {
@@ -254,12 +254,13 @@ 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){
-        if($this->writeObjectReference($data)){
+    public function writeByteArray(&$data)
+    {
+        if ($this->writeObjectReference($data)) {
             return $this;
         }
 
-        if(is_string($data)) {
+        if (is_string($data)) {
             //nothing to do
         } else if ($data instanceof Zend_Amf_Value_ByteArray) {
             $data = $data->getData();
@@ -281,7 +282,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      */
     public function writeXml($xml)
     {
-        if($this->writeObjectReference($xml)){
+        if ($this->writeObjectReference($xml)) {
             return $this;
         }
 
@@ -309,7 +310,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      */
     public function writeDate($date)
     {
-        if($this->writeObjectReference($date)){
+        if ($this->writeObjectReference($date)) {
             return $this;
         }
 
@@ -377,16 +378,18 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
      * @param mixed $objectByVal object to check for reference
      * @return Boolean true, if the reference was written, false otherwise
      */
-    protected function writeObjectReference(&$object, $objectByVal=false)
+    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)) {
+        // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
+        // variables should be passed by reference"
+        if ((null === $object) && ($objectByVal !== false)) {
             $object = &$objectByVal;
         }
 
         $ref = array_search($object, $this->_referenceObjects,true);
-        //quickly handle object references
-        if($ref !== false){
+
+        // quickly handle object references
+        if ($ref !== false){
             $ref <<= 1;
             $this->writeInteger($ref);
             return true;

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

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

+ 4 - 2
library/Zend/Amf/Response.php

@@ -95,7 +95,8 @@ class Zend_Amf_Response
             $stream->writeByte($header->mustRead);
             $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
             if (is_object($header->data)) {
-                // Workaround for PHP5 with E_STRICT enabled complaining about "Only variables should be passed by reference"
+                // 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 {
@@ -114,7 +115,8 @@ class Zend_Amf_Response
             $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"
+                // Workaround for PHP5 with E_STRICT enabled complaining about 
+                // "Only variables should be passed by reference"
                 $placeholder = null;
                 $serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
             } else {