Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Amf/Request.php
Go to the documentation of this file.
00001 <?php
00023 require_once 'Zend/Amf/Parse/InputStream.php';
00024 
00026 require_once 'Zend/Amf/Parse/Amf0/Deserializer.php';
00027 
00029 require_once 'Zend/Amf/Constants.php';
00030 
00032 require_once 'Zend/Amf/Value/MessageHeader.php';
00033 
00035 require_once 'Zend/Amf/Value/MessageBody.php';
00036 
00046 class Zend_Amf_Request
00047 {
00051     protected $_clientType = 0; // default AMF0
00052 
00056     protected $_bodies = array();
00057 
00061     protected $_headers = array();
00062 
00066     protected $_objectEncoding = 0;
00067 
00071     protected $_inputStream;
00072 
00076     protected $_deserializer;
00077 
00082     protected $_time;
00083 
00090     public function initialize($request)
00091     {
00092         $this->_inputStream  = new Zend_Amf_Parse_InputStream($request);
00093         $this->_deserializer = new Zend_Amf_Parse_Amf0_Deserializer($this->_inputStream);
00094         $this->readMessage($this->_inputStream);
00095         return $this;
00096     }
00097 
00104     public function readMessage(Zend_Amf_Parse_InputStream $stream)
00105     {
00106         $clientVersion = $stream->readUnsignedShort();
00107         if (($clientVersion != Zend_Amf_Constants::AMF0_OBJECT_ENCODING)
00108             && ($clientVersion != Zend_Amf_Constants::AMF3_OBJECT_ENCODING)
00109             && ($clientVersion != Zend_Amf_Constants::FMS_OBJECT_ENCODING)
00110         ) {
00111             require_once 'Zend/Amf/Exception.php';
00112             throw new Zend_Amf_Exception('Unknown Player Version ' . $clientVersion);
00113         }
00114 
00115         $this->_bodies  = array();
00116         $this->_headers = array();
00117         $headerCount    = $stream->readInt();
00118 
00119         // Iterate through the AMF envelope header
00120         while ($headerCount--) {
00121             $this->_headers[] = $this->readHeader();
00122         }
00123 
00124         // Iterate through the AMF envelope body
00125         $bodyCount = $stream->readInt();
00126         while ($bodyCount--) {
00127             $this->_bodies[] = $this->readBody();
00128         }
00129 
00130         return $this;
00131     }
00132 
00144     public function readHeader()
00145     {
00146         $name     = $this->_inputStream->readUTF();
00147         $mustRead = (bool)$this->_inputStream->readByte();
00148         $length   = $this->_inputStream->readLong();
00149 
00150         try {
00151             $data = $this->_deserializer->readTypeMarker();
00152         } catch (Exception $e) {
00153             require_once 'Zend/Amf/Exception.php';
00154             throw new Zend_Amf_Exception('Unable to parse ' . $name . ' header data: ' . $e->getMessage() . ' '. $e->getLine(), 0, $e);
00155         }
00156 
00157         $header = new Zend_Amf_Value_MessageHeader($name, $mustRead, $data, $length);
00158         return $header;
00159     }
00160 
00166     public function readBody()
00167     {
00168         $targetURI   = $this->_inputStream->readUTF();
00169         $responseURI = $this->_inputStream->readUTF();
00170         $length      = $this->_inputStream->readLong();
00171 
00172         try {
00173             $data = $this->_deserializer->readTypeMarker();
00174         } catch (Exception $e) {
00175             require_once 'Zend/Amf/Exception.php';
00176             throw new Zend_Amf_Exception('Unable to parse ' . $targetURI . ' body data ' . $e->getMessage(), 0, $e);
00177         }
00178 
00179         // Check for AMF3 objectEncoding
00180         if ($this->_deserializer->getObjectEncoding() == Zend_Amf_Constants::AMF3_OBJECT_ENCODING) {
00181             /*
00182              * When and AMF3 message is sent to the server it is nested inside
00183              * an AMF0 array called Content. The following code gets the object
00184              * out of the content array and sets it as the message data.
00185              */
00186             if(is_array($data) && $data[0] instanceof Zend_Amf_Value_Messaging_AbstractMessage){
00187                 $data = $data[0];
00188             }
00189 
00190             // set the encoding so we return our message in AMF3
00191             $this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
00192         }
00193 
00194         $body = new Zend_Amf_Value_MessageBody($targetURI, $responseURI, $data);
00195         return $body;
00196     }
00197 
00203     public function getAmfBodies()
00204     {
00205         return $this->_bodies;
00206     }
00207 
00214     public function addAmfBody(Zend_Amf_Value_MessageBody $message)
00215     {
00216         $this->_bodies[] = $message;
00217         return $this;
00218     }
00219 
00225     public function getAmfHeaders()
00226     {
00227         return $this->_headers;
00228     }
00229 
00235     public function getObjectEncoding()
00236     {
00237         return $this->_objectEncoding;
00238     }
00239 
00246     public function setObjectEncoding($int)
00247     {
00248         $this->_objectEncoding = $int;
00249         return $this;
00250     }
00251 }
 All Data Structures Namespaces Files Functions Variables Enumerations