Example #1
0
 /**
  * deserialize 
  * 
  * This method deserializes a request. It requires an SabreAMF_InputStream with valid AMF data. After
  * deserialization the contents of the request can be found through the getBodies and getHeaders methods
  *
  * @param SabreAMF_InputStream $stream 
  * @return void
  */
 public function deserialize(SabreAMF_InputStream $stream)
 {
     $this->headers = array();
     $this->bodies = array();
     $this->InputStream = $stream;
     $stream->readByte();
     $this->clientType = $stream->readByte();
     $deserializer = new SabreAMF_AMF0_Deserializer($stream);
     $totalHeaders = $stream->readInt();
     for ($i = 0; $i < $totalHeaders; $i++) {
         $header = array('name' => $deserializer->readString(), 'required' => $stream->readByte() == true);
         $stream->readLong();
         $header['data'] = $deserializer->readAMFData(null, true);
         $this->headers[] = $header;
     }
     $totalBodies = $stream->readInt();
     for ($i = 0; $i < $totalBodies; $i++) {
         try {
             $target = $deserializer->readString();
         } catch (Exception $e) {
             // Could not fetch next body.. this happens with some versions of AMFPHP where the body
             // count isn't properly set. If this happens we simply stop decoding
             break;
         }
         $body = array('target' => $target, 'response' => $deserializer->readString(), 'length' => $stream->readLong(), 'data' => $deserializer->readAMFData(null, true));
         if (is_object($body['data']) && $body['data'] instanceof SabreAMF_AMF3_Wrapper) {
             $body['data'] = $body['data']->getData();
             $this->encoding = SabreAMF_Const::AMF3;
         } else {
             if (is_array($body['data']) && isset($body['data'][0]) && is_object($body['data'][0]) && $body['data'][0] instanceof SabreAMF_AMF3_Wrapper) {
                 $body['data'] = $body['data'][0]->getData();
                 $this->encoding = SabreAMF_Const::AMF3;
             }
         }
         $this->bodies[] = $body;
     }
 }