Amfphp_Core_Amf_Deserializer::readAmf3Vector PHP Method

readAmf3Vector() protected method

Reads a vector array of objects from the AMF stream. This works for all vector arrays: vector-object, vector-int vector-uint and vector-double. The Vector is cast to a PHP array. Please note that because of the way php handles integers, uints have to be cast as floats. See {@link http://php.net/manual/en/language.types.integer.php}
protected readAmf3Vector ( $type ) : array
return array The objects in the vector in a native PHP array.
    protected function readAmf3Vector($type)
    {
        /* AMF Spec: "The first (low) bit is a flag with value 1. The remaining 1 to 28 significant bits are used to encode the count of 
           items in Vector." */
        // according to the above - $inline will always be 1 after the bitshift, and what remains in $handle
        // after the bitshift is the count of the vector
        $handle = $this->readAmf3Int();
        $inline = ($handle & 1) != 0;
        $handle = $handle >> 1;
        if ($inline) {
            $vector = new Amfphp_Core_Amf_Types_Vector();
            $vector->type = $type;
            /* AMF Spec: "Boolean U8 value, 0x00 if not a fixed-length Vector, otherwise 0x01 if fixed-length." */
            // we are not really concerned in PHP if the vector is fixed-length right now.
            $vector->fixed = $this->readByte();
            $vector->data = array();
            $this->storedObjects[] =& $vector;
            if ($type === Amfphp_Core_Amf_Types_Vector::VECTOR_OBJECT) {
                $vector->className = $this->readAmf3String();
                for ($i = 0; $i < $handle; $i++) {
                    //Grab the type for each element.
                    $vector->data[] = $this->readAmf3Data();
                }
            } else {
                switch ($type) {
                    case Amfphp_Core_Amf_Types_Vector::VECTOR_INT:
                        $length = 4;
                        $format = "ival";
                        break;
                    case Amfphp_Core_Amf_Types_Vector::VECTOR_UINT:
                        $length = 4;
                        $format = "Ival";
                        break;
                    case Amfphp_Core_Amf_Types_Vector::VECTOR_DOUBLE:
                        $length = 8;
                        $format = "dval";
                        break;
                }
                for ($i = 0; $i < $handle; $i++) {
                    //Grab the type for each element.
                    $vector->data[] = $this->readAmf3VectorValue($length, $format);
                }
            }
            return $vector;
        } else {
            return $this->storedObjects[$handle];
        }
    }

Usage Example

コード例 #1
0
 /**
  * read vector
  * @return Amfphp_Core_Amf_Types_Vector
  */
 public function readAmf3Vector($type)
 {
     return parent::readAmf3Vector($type);
 }