. * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) ***************************************************************************** * Ported to PHP4 by Kulikov Alexey * * * require_once("ajax.class.php"); * $R = new AjaxResponseWddx; * $R->set('foo','bar'); * $R->send(); * *********************************************************/ class AjaxResponse{ /** * Data Storage * * @var unknown_type * @access private */ var $result; /** * Object Constructor * * @return AjaxResponse */ function AjaxResponse(){ $this->clear(); } /** * Resets the internal data storage * */ function clear(){ $this->result = array(); } /** * Returns some internal data value * * @param string $name Array Key * @return string */ function get($name){ return $this->result[$name]; } /** * Sets some internal data into the result array * * @param string $name Array Key * @param string $value Array Value */ function set($name, $value){ $this->result[$name] = $value; } /** * An imitation of the wddx_serialize_value function, * in case the host does not support the packaged C * function, this one will be called instead. It is simple and * primitive and does not support ADTs * * @param array $value * @return string * @access private */ function wddx_serialize_value($value){ //typecast $value = (array)$value; $toReturn = null; foreach($value as $key => $val){ $toReturn .= ''.$val.''; } return '
'.$toReturn.''; } /** * This function will serialize all the data gathered by the ajax server * and also prepend the data with the neccessary headers * * @return array * @access private */ function serializeResult(){ //checking if the WDDX module is installed if(function_exists('wddx_serialize_value')){ $text = wddx_serialize_value($this->result); }else{ $text = $this->wddx_serialize_value($this->result); } return array( $text, array( "Content-type" => "text/xml" //"Content-length" => strlen($text), ) ); } /** * As this is a port to PHP4, thus a send() method need to be called to * actually send the reply to the ajax client. In PHP5 this happened * automatically. * * @param bool $echo * @return string | echo */ function send($echo=true){ list($result, $headers) = $this->serializeResult(); foreach($headers as $name => $content){ header("$name: $content"); } if(!$echo){ return $result; }else{ echo $result; } } } ?>