MessageBody.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Amf
  17. * @subpackage Value
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * An AMF Message contains information about the actual individual
  23. * transaction that is to be performed. It specifies the remote
  24. * operation that is to be performed; a local (client) operation
  25. * to be invoked upon success; and, the data to be used in the
  26. * operation.
  27. * <p/>
  28. * This Message structure defines how a local client would
  29. * invoke a method/operation on a remote server. Additionally,
  30. * the response from the Server is structured identically.
  31. *
  32. * @package Zend_Amf
  33. * @subpackage Value
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Amf_Value_MessageBody
  38. {
  39. /**
  40. * A string describing which operation, function, or method
  41. * is to be remotley invoked.
  42. * @var string
  43. */
  44. protected $_targetUri = "";
  45. /**
  46. * Universal Resource Identifier that uniquely targets the originator's
  47. * Object that should receive the server's response. The server will
  48. * use this path specification to target the "OnResult()" or "onStatus()"
  49. * handlers within the client. For Flash, it specifies an ActionScript
  50. * Object path only. The NetResponse object pointed to by the Response Uri
  51. * contains the connection state information. Passing/specifying this
  52. * provides a convenient mechanism for the client/server to share access
  53. * to an object that is managing the state of the shared connection.
  54. *
  55. * Since the server will use this field in the event of an error,
  56. * this field is required even if a successful server request would
  57. * not be expected to return a value to the client.
  58. *
  59. * @var string
  60. */
  61. protected $_responseUri = "";
  62. /**
  63. * Contains the actual data associated with the operation. It contains
  64. * the client's parameter data that is passed to the server's operation/method.
  65. * When serializing a root level data type or a parameter list array, no
  66. * name field is included. That is, the data is anonomously represented
  67. * as "Type Marker"/"Value" pairs. When serializing member data, the data is
  68. * represented as a series of "Name"/"Type"/"Value" combinations.
  69. *
  70. * For server generated responses, it may contain any ActionScript
  71. * data/objects that the server was expected to provide.
  72. *
  73. * @var string
  74. */
  75. protected $_data;
  76. /**
  77. * Constructor
  78. *
  79. * @param string $targetUri
  80. * @param string $responseUri
  81. * @param string $data
  82. * @return void
  83. */
  84. public function __construct($targetUri, $responseUri, $data)
  85. {
  86. $this->setTargetUri($targetUri);
  87. $this->setResponseUri($responseUri);
  88. $this->setData($data);
  89. }
  90. /**
  91. * Retrieve target Uri
  92. *
  93. * @return string
  94. */
  95. public function getTargetUri()
  96. {
  97. return $this->_targetUri;
  98. }
  99. /**
  100. * Set target Uri
  101. *
  102. * @param string $targetUri
  103. * @return Zend_Amf_Value_MessageBody
  104. */
  105. public function setTargetUri($targetUri)
  106. {
  107. if (null === $targetUri) {
  108. $targetUri = '';
  109. }
  110. $this->_targetUri = (string) $targetUri;
  111. return $this;
  112. }
  113. /**
  114. * Get target Uri
  115. *
  116. * @return string
  117. */
  118. public function getResponseUri()
  119. {
  120. return $this->_responseUri;
  121. }
  122. /**
  123. * Set response Uri
  124. *
  125. * @param string $responseUri
  126. * @return Zend_Amf_Value_MessageBody
  127. */
  128. public function setResponseUri($responseUri)
  129. {
  130. if (null === $responseUri) {
  131. $responseUri = '';
  132. }
  133. $this->_responseUri = $responseUri;
  134. return $this;
  135. }
  136. /**
  137. * Retrieve response data
  138. *
  139. * @return string
  140. */
  141. public function getData()
  142. {
  143. return $this->_data;
  144. }
  145. /**
  146. * Set response data
  147. *
  148. * @param mixed $data
  149. * @return Zend_Amf_Value_MessageBody
  150. */
  151. public function setData($data)
  152. {
  153. $this->_data = $data;
  154. return $this;
  155. }
  156. /**
  157. * Set reply method
  158. *
  159. * @param string $methodName
  160. * @return Zend_Amf_Value_MessageBody
  161. */
  162. public function setReplyMethod($methodName)
  163. {
  164. if (!preg_match('#^[/?]#', $methodName)) {
  165. $this->_targetUri = rtrim($this->_targetUri, '/') . '/';
  166. }
  167. $this->_targetUri = $this->_targetUri . $methodName;
  168. return $this;
  169. }
  170. }