/source/Plug-in/xajax/xajax_core/xajaxResponseManager.inc.php

http://prosporous.googlecode.com/ · PHP · 222 lines · 99 code · 16 blank · 107 comment · 30 complexity · 94b21cc0e8cfe53b6ef79c950b1f4808 MD5 · raw file

  1. <?php
  2. /*
  3. File: xajaxResponseManager.inc.php
  4. Contains the xajaxResponseManager class
  5. Title: xajaxResponseManager class
  6. Please see <copyright.inc.php> for a detailed description, copyright
  7. and license information.
  8. */
  9. /*
  10. @package xajax
  11. @version $Id: xajaxResponseManager.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
  12. @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
  13. @license http://www.xajaxproject.org/bsd_license.txt BSD License
  14. */
  15. /*
  16. Class: xajaxResponseManager
  17. This class stores and tracks the response that will be returned after
  18. processing a request. The response manager represents a single point
  19. of contact for working with <xajaxResponse> objects as well as
  20. <xajaxCustomResponse> objects.
  21. */
  22. class xajaxResponseManager
  23. {
  24. /*
  25. Object: objResponse
  26. The current response object that will be sent back to the browser
  27. once the request processing phase is complete.
  28. */
  29. var $objResponse;
  30. /*
  31. String: sCharacterEncoding
  32. */
  33. var $sCharacterEncoding;
  34. /*
  35. Boolean: bOutputEntities
  36. */
  37. var $bOutputEntities;
  38. /*
  39. Array: aDebugMessages
  40. */
  41. var $aDebugMessages;
  42. /*
  43. Function: xajaxResponseManager
  44. Construct and initialize the one and only xajaxResponseManager object.
  45. */
  46. function xajaxResponseManager()
  47. {
  48. $this->objResponse = NULL;
  49. $this->aDebugMessages = array();
  50. }
  51. /*
  52. Function: getInstance
  53. Implementation of the singleton pattern: provide a single instance of the <xajaxResponseManager>
  54. to all who request it.
  55. */
  56. function &getInstance()
  57. {
  58. static $obj;
  59. if (!$obj) {
  60. $obj = new xajaxResponseManager();
  61. }
  62. return $obj;
  63. }
  64. /*
  65. Function: configure
  66. Called by the xajax object when configuration options are set in the main script. Option
  67. values are passed to each of the main xajax components and stored locally as needed. The
  68. <xajaxResponseManager> will track the characterEncoding and outputEntities settings.
  69. */
  70. function configure($sName, $mValue)
  71. {
  72. if ('characterEncoding' == $sName)
  73. {
  74. $this->sCharacterEncoding = $mValue;
  75. if (isset($this->objResponse))
  76. $this->objResponse->setCharacterEncoding($this->sCharacterEncoding);
  77. }
  78. else if ('outputEntities' == $sName)
  79. {
  80. if (true === $mValue || false === $mValue)
  81. {
  82. $this->bOutputEntities = $mValue;
  83. if (isset($this->objResponse))
  84. $this->objResponse->setOutputEntities($this->bOutputEntities);
  85. }
  86. }
  87. }
  88. /*
  89. Function: clear
  90. Clear the current response. A new response will need to be appended
  91. before the request processing is complete.
  92. */
  93. function clear()
  94. {
  95. $this->objResponse = NULL;
  96. }
  97. /*
  98. Function: append
  99. Used, primarily internally, to append one response object onto the end of another. You can
  100. append one xajaxResponse to the end of another, or append a xajaxCustomResponse onto the end of
  101. another xajaxCustomResponse. However, you cannot append a standard response object onto the end
  102. of a custom response and likewise, you cannot append a custom response onto the end of a standard
  103. response.
  104. $mResponse - (object): The new response object to be added to the current response object.
  105. If no prior response has been appended, this response becomes the main response object to which other
  106. response objects will be appended.
  107. */
  108. function append($mResponse)
  109. {
  110. if (is_a($mResponse, 'xajaxResponse')) {
  111. if (NULL == $this->objResponse) {
  112. $this->objResponse = $mResponse;
  113. } else if (is_a($this->objResponse, 'xajaxResponse')) {
  114. if ($this->objResponse != $mResponse)
  115. $this->objResponse->absorb($mResponse);
  116. } else {
  117. $objLanguageManager =& xajaxLanguageManager::getInstance();
  118. $this->debug(
  119. $objLanguageManager->getText('XJXRM:MXRTERR')
  120. . get_class($this->objResponse)
  121. . ')'
  122. );
  123. }
  124. } else if (is_a($mResponse, 'xajaxCustomResponse')) {
  125. if (NULL == $this->objResponse) {
  126. $this->objResponse = $mResponse;
  127. } else if (is_a($this->objResponse, 'xajaxCustomResponse')) {
  128. if ($this->objResponse != $mResponse)
  129. $this->objResponse->absorb($mResponse);
  130. } else {
  131. $objLanguageManager =& xajaxLanguageManager::getInstance();
  132. $this->debug(
  133. $objLanguageManager->getText('XJXRM:MXRTERR')
  134. . get_class($this->objResponse)
  135. . ')'
  136. );
  137. }
  138. } else {
  139. $objLanguageManager =& xajaxLanguageManager::getInstance();
  140. $this->debug($objLanguageManager->getText('XJXRM:IRERR'));
  141. }
  142. }
  143. /*
  144. Function: debug
  145. Appends a debug message on the end of the debug message queue. Debug messages
  146. will be sent to the client with the normal response (if the response object supports
  147. the sending of debug messages, see: <xajaxResponse>)
  148. $sMessage - (string): The text of the debug message to be sent.
  149. */
  150. function debug($sMessage)
  151. {
  152. $this->aDebugMessages[] = $sMessage;
  153. }
  154. /*
  155. Function: send
  156. Prints the response object to the output stream, thus sending the response to the client.
  157. */
  158. function send()
  159. {
  160. if (NULL != $this->objResponse) {
  161. foreach ($this->aDebugMessages as $sMessage)
  162. $this->objResponse->debug($sMessage);
  163. $this->aDebugMessages = array();
  164. $this->objResponse->printOutput();
  165. }
  166. }
  167. /*
  168. Function: getCharacterEncoding
  169. Called automatically by new response objects as they are constructed to obtain the
  170. current character encoding setting. As the character encoding is changed, the <xajaxResponseManager>
  171. will automatically notify the current response object since it would have been constructed
  172. prior to the setting change, see <xajaxResponseManager::configure>.
  173. */
  174. function getCharacterEncoding()
  175. {
  176. return $this->sCharacterEncoding;
  177. }
  178. /*
  179. Function: getOutputEntities
  180. Called automatically by new response objects as they are constructed to obtain the
  181. current output entities setting. As the output entities setting is changed, the
  182. <xajaxResponseManager> will automatically notify the current response object since it would
  183. have been constructed prior to the setting change, see <xajaxResponseManager::configure>.
  184. */
  185. function getOutputEntities()
  186. {
  187. return $this->bOutputEntities;
  188. }
  189. }