AMFObject.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * AMFObject is a datatype representing the parsed representation of the binary AMF data.
  4. *
  5. * This object contains 2 major sections, headers and bodys. Headers contain all of the
  6. * header keys along with their associated data and body elements which include the target
  7. * URI, the response URI and the data to pass to the method.
  8. *
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @copyright (c) 2003 amfphp.org
  11. * @package flashservices
  12. * @subpackage util
  13. * @version $Id: AMFObject.php,v 1.14 2005/07/05 07:40:53 pmineault Exp $
  14. */
  15. class AMFObject {
  16. /**
  17. * The place to keep the headers data
  18. *
  19. * @access private
  20. * @var array
  21. */
  22. var $_incomingHeaders;
  23. /**
  24. * The variable to store outgoing headers
  25. *
  26. * @access private
  27. * @var array
  28. */
  29. var $_outgoingHeaders;
  30. /**
  31. * The header table is a quick lookup table for
  32. * a header by it's key
  33. */
  34. var $_headerTable;
  35. /**
  36. * The place to keep the body elements
  37. *
  38. * @access private
  39. * @var array
  40. */
  41. var $_bodys;
  42. var $outputStream;
  43. /**
  44. * The constructor function for a new amf object.
  45. *
  46. * All the constructor does is initialize the headers and bodys containers
  47. */
  48. function AMFObject($rawData = NULL) {
  49. $this->rawData = $rawData;
  50. $this->outputStream = "";
  51. $this->_incomingHeaders = array();
  52. $this->_outgoingHeaders = array();
  53. $this->_bodys = array();
  54. $this->_headerTable = array();
  55. }
  56. /**
  57. * addHeader places a new header into the pool of headers.
  58. *
  59. * Each header has 3 properties, they header key, the required flag
  60. * and the data associated with the header.
  61. *
  62. * @param object $header The AMFHeader object to add to the list
  63. */
  64. function addHeader(&$header) {
  65. //$len = array_push($this->_incomingHeaders, $header);
  66. $this->_incomingHeaders[] = $header;
  67. $name = $header->name;
  68. $this->_headerTable[$name] = $header;
  69. }
  70. /**
  71. * addOutgoingHeader places a new header into the pool of outbound headers.
  72. *
  73. * Each header has 3 properties, they header key, the required flag
  74. * and the data associated with the header.
  75. *
  76. * @param object $header The AMFHeader object to add to the list
  77. */
  78. function addOutgoingHeader(&$header) {
  79. //$len = array_push($this->_outgoingHeaders, $header);
  80. $this->_outgoingHeaders[] = $header;
  81. }
  82. /**
  83. * getHeader returns a header record for a given key
  84. *
  85. * @param string $key The header key
  86. * @return mixed The header record
  87. */
  88. function getHeader ($key) {
  89. if (isset($this->_headerTable[$key])) {
  90. return $this->_headerTable[$key];
  91. }
  92. return false;
  93. }
  94. /**
  95. * Gets the number of headers for this amf packet
  96. *
  97. * @return int The header count
  98. */
  99. function numHeader() {
  100. return count($this->_incomingHeaders);
  101. }
  102. /**
  103. * Gets the number of outgoing headers for this amf packet
  104. *
  105. * @return int The header count
  106. */
  107. function numOutgoingHeader() {
  108. return count($this->_outgoingHeaders);
  109. }
  110. /**
  111. * Get the header at the specified position.
  112. *
  113. * If you pass an id this method will return the header
  114. * located at that id, otherwise it will return the first header
  115. *
  116. * @param int $id Optional id field
  117. * @return array The header object
  118. */
  119. function &getHeaderAt($id = 0) {
  120. return $this->_incomingHeaders[$id];
  121. }
  122. /**
  123. * Get the header at the specified position from the outgoing header queue.
  124. *
  125. * If you pass an id this method will return the header
  126. * located at that id, otherwise it will return the first header
  127. *
  128. * @param int $id Optional id field
  129. * @return array The header object
  130. */
  131. function &getOutgoingHeaderAt($id = 0) {
  132. return $this->_outgoingHeaders[$id];
  133. }
  134. /**
  135. * addBody has the job of adding a new body element to the bodys array.
  136. *
  137. * @param string $t The target URI
  138. * @param string $r The response URI
  139. * @param mixed $v The value of the object
  140. * @param string $ty The type of the results
  141. * @param int $ps The pagesize of a recordset
  142. */
  143. function addBody($body) {
  144. $this->_bodys[] = $body;
  145. }
  146. /**
  147. * addBodyAt provides an interface to push a body element to a desired
  148. * position in the array.
  149. *
  150. * @param int $pos The position to add the body element
  151. * @param AMFBody $body The body element to add
  152. */
  153. function addBodyAt($pos, $body) {
  154. array_splice($this->_bodys, $pos, 0, array($body)); // splice the new body into the array
  155. }
  156. /**
  157. * removeBodyAt provides an interface to remove a body element to a desired
  158. * position in the array.
  159. *
  160. * @param int $pos The position to add the body element
  161. * @param AMFBody $body The body element to add
  162. */
  163. function removeBodyAt($pos) {
  164. array_splice($this->_bodys, $pos, 1); // splice the new body into the array
  165. }
  166. /**
  167. * numBody returns the total number of body elements. There is one body
  168. * element for each method call.
  169. *
  170. * @return int The number of body elements
  171. */
  172. function numBody() {
  173. return count($this->_bodys);
  174. }
  175. /**
  176. * getBodyAt returns the current body element the specified position.
  177. *
  178. * If a integer is passed this method will return the element at the given position.
  179. * Otherwise the first element will be returned.
  180. *
  181. * @param int $id The id of the body element desired
  182. * @return array The body element
  183. */
  184. function &getBodyAt($id = 0) {
  185. return $this->_bodys[$id];
  186. }
  187. }
  188. ?>