<?php
require_once 'Zend/Amf/Parse/InputStream.php';
require_once 'Zend/Amf/Parse/Amf0/Deserializer.php';
require_once 'Zend/Amf/Constants.php';
require_once 'Zend/Amf/Value/MessageHeader.php';
require_once 'Zend/Amf/Value/MessageBody.php';
class Zend_Amf_Request
{
protected $_clientType = 0;
protected $_bodies = array();
protected $_headers = array();
protected $_objectEncoding = 0;
protected $_inputStream;
protected $_deserializer;
protected $_time;
public function initialize($request)
{
$this->_inputStream = new Zend_Amf_Parse_InputStream($request);
$this->_deserializer = new Zend_Amf_Parse_Amf0_Deserializer($this->_inputStream);
$this->readMessage($this->_inputStream);
return $this;
}
public function readMessage(Zend_Amf_Parse_InputStream $stream)
{
$clientVersion = $stream->readUnsignedShort();
if (($clientVersion != Zend_Amf_Constants::AMF0_OBJECT_ENCODING)
&& ($clientVersion != Zend_Amf_Constants::AMF3_OBJECT_ENCODING)
&& ($clientVersion != Zend_Amf_Constants::FMS_OBJECT_ENCODING)
) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Player Version ' . $clientVersion);
}
$this->_bodies = array();
$this->_headers = array();
$headerCount = $stream->readInt();
while ($headerCount--) {
$this->_headers[] = $this->readHeader();
}
$bodyCount = $stream->readInt();
while ($bodyCount--) {
$this->_bodies[] = $this->readBody();
}
return $this;
}
public function readHeader()
{
$name = $this->_inputStream->readUTF();
$mustRead = (bool)$this->_inputStream->readByte();
$length = $this->_inputStream->readLong();
try {
$data = $this->_deserializer->readTypeMarker();
} catch (Exception $e) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to parse ' . $name . ' header data: ' . $e->getMessage() . ' '. $e->getLine());
}
$header = new Zend_Amf_Value_MessageHeader($name, $mustRead, $data, $length);
return $header;
}
public function readBody()
{
$targetURI = $this->_inputStream->readUTF();
$responseURI = $this->_inputStream->readUTF();
$length = $this->_inputStream->readLong();
try {
$data = $this->_deserializer->readTypeMarker();
} catch (Exception $e) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to parse ' . $targetURI . ' body data ' . $e->getMessage());
}
if ($this->_deserializer->getObjectEncoding() == Zend_Amf_Constants::AMF3_OBJECT_ENCODING) {
if(is_array($data) && $data[0] instanceof Zend_Amf_Value_Messaging_AbstractMessage){
$data = $data[0];
}
$this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
}
$body = new Zend_Amf_Value_MessageBody($targetURI, $responseURI, $data);
return $body;
}
public function getAmfBodies()
{
return $this->_bodies;
}
public function addAmfBody(Zend_Amf_Value_MessageBody $message)
{
$this->_bodies[] = $message;
return $this;
}
public function getAmfHeaders()
{
return $this->_headers;
}
public function getObjectEncoding()
{
return $this->_objectEncoding;
}
public function setObjectEncoding($int)
{
$this->_objectEncoding = $int;
return $this;
}
}