PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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