web/lib/Zend/Amf/Parse/Amf0/Serializer.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Amf
    16  * @package    Zend_Amf
    17  * @subpackage Parse_Amf0
    17  * @subpackage Parse_Amf0
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Serializer.php 21968 2010-04-22 03:53:34Z matthew $
    20  * @version    $Id: Serializer.php 25179 2012-12-22 21:29:30Z rob $
    21  */
    21  */
    22 
    22 
    23 /** Zend_Amf_Constants */
    23 /** Zend_Amf_Constants */
    24 require_once 'Zend/Amf/Constants.php';
    24 require_once 'Zend/Amf/Constants.php';
    25 
    25 
    30  * Serializer PHP misc types back to there corresponding AMF0 Type Marker.
    30  * Serializer PHP misc types back to there corresponding AMF0 Type Marker.
    31  *
    31  *
    32  * @uses       Zend_Amf_Parse_Serializer
    32  * @uses       Zend_Amf_Parse_Serializer
    33  * @package    Zend_Amf
    33  * @package    Zend_Amf
    34  * @subpackage Parse_Amf0
    34  * @subpackage Parse_Amf0
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  */
    37  */
    38 class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
    38 class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
    39 {
    39 {
    40     /**
    40     /**
    61      * @return Zend_Amf_Parse_Amf0_Serializer
    61      * @return Zend_Amf_Parse_Amf0_Serializer
    62      * @throws Zend_Amf_Exception for unrecognized types or data
    62      * @throws Zend_Amf_Exception for unrecognized types or data
    63      */
    63      */
    64     public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
    64     public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
    65     {
    65     {
    66         // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
    66         // Workaround for PHP5 with E_STRICT enabled complaining about "Only
    67         // variables should be passed by reference" 
    67         // variables should be passed by reference"
    68         if ((null === $data) && ($dataByVal !== false)) {
    68         if ((null === $data) && ($dataByVal !== false)) {
    69             $data = &$dataByVal;
    69             $data = &$dataByVal;
    70         }
    70         }
    71         if (null !== $markerType) {
    71         if (null !== $markerType) {
    72             //try to reference the given object
    72             //try to reference the given object
   125                     $markerType = Zend_Amf_Constants::AMF0_NUMBER;
   125                     $markerType = Zend_Amf_Constants::AMF0_NUMBER;
   126                     break;
   126                     break;
   127                 case (is_bool($data)):
   127                 case (is_bool($data)):
   128                     $markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
   128                     $markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
   129                     break;
   129                     break;
   130                 case (is_string($data) && (strlen($data) > 65536)):
   130                 case (is_string($data) && (($this->_mbStringFunctionsOverloaded ? mb_strlen($data, '8bit') : strlen($data)) > 65536)):
   131                     $markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
   131                     $markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
   132                     break;
   132                     break;
   133                 case (is_string($data)):
   133                 case (is_string($data)):
   134                     $markerType = Zend_Amf_Constants::AMF0_STRING;
   134                     $markerType = Zend_Amf_Constants::AMF0_STRING;
   135                     break;
   135                     break;
   185 
   185 
   186     /**
   186     /**
   187      * Check if the given object is in the reference table, write the reference if it exists,
   187      * Check if the given object is in the reference table, write the reference if it exists,
   188      * otherwise add the object to the reference table
   188      * otherwise add the object to the reference table
   189      *
   189      *
   190      * @param mixed $object object reference to check for reference
   190      * @param mixed  $object object reference to check for reference
   191      * @param $markerType AMF type of the object to write
   191      * @param string $markerType AMF type of the object to write
   192      * @param mixed $objectByVal object to check for reference
   192      * @param mixed  $objectByVal object to check for reference
   193      * @return Boolean true, if the reference was written, false otherwise
   193      * @return Boolean true, if the reference was written, false otherwise
   194      */
   194      */
   195     protected function writeObjectReference(&$object, $markerType, $objectByVal = false) 
   195     protected function writeObjectReference(&$object, $markerType, $objectByVal = false)
   196     {
   196     {
   197         // Workaround for PHP5 with E_STRICT enabled complaining about "Only 
   197         // Workaround for PHP5 with E_STRICT enabled complaining about "Only
   198         // variables should be passed by reference"
   198         // variables should be passed by reference"
   199         if ((null === $object) && ($objectByVal !== false)) {
   199         if ((null === $object) && ($objectByVal !== false)) {
   200             $object = &$objectByVal;
   200             $object = &$objectByVal;
   201         }
   201         }
   202 
   202 
   203         if ($markerType == Zend_Amf_Constants::AMF0_OBJECT 
   203         if ($markerType == Zend_Amf_Constants::AMF0_OBJECT
   204             || $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY 
   204             || $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY
   205             || $markerType == Zend_Amf_Constants::AMF0_ARRAY 
   205             || $markerType == Zend_Amf_Constants::AMF0_ARRAY
   206             || $markerType == Zend_Amf_Constants::AMF0_TYPEDOBJECT 
   206             || $markerType == Zend_Amf_Constants::AMF0_TYPEDOBJECT
   207         ) {
   207         ) {
   208             $ref = array_search($object, $this->_referenceObjects, true);
   208             $ref = array_search($object, $this->_referenceObjects, true);
   209             //handle object reference
   209             //handle object reference
   210             if($ref !== false){
   210             if($ref !== false){
   211                 $this->writeTypeMarker($ref,Zend_Amf_Constants::AMF0_REFERENCE);
   211                 $this->writeTypeMarker($ref,Zend_Amf_Constants::AMF0_REFERENCE);