6 /// @todo: do these need to be public?
12 public $hdrs = array();
13 public $_cookies = array();
14 public $content_type = 'text/xml';
15 public $raw_data = '';
18 * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
19 * @param integer $fcode set it to anything but 0 to create an error response
20 * @param string $fstr the error string, in case of an error response
21 * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
23 * @todo add check that $val / $fcode / $fstr is of correct type???
24 * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
25 * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
27 function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
32 $this->errno = $fcode;
33 $this->errstr = $fstr;
34 //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
38 // successful response
42 // user did not declare type of response value: try to guess it
43 if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
45 $this->valtyp = 'xmlrpcvals';
47 else if (is_string($this->val))
49 $this->valtyp = 'xml';
54 $this->valtyp = 'phpvals';
59 // user declares type of resp value: believe him
60 $this->valtyp = $valtyp;
66 * Returns the error code of the response.
67 * @return integer the error code of this response (0 for not-error responses)
69 public function faultCode()
75 * Returns the error code of the response.
76 * @return string the error string of this response ('' for not-error responses)
78 public function faultString()
84 * Returns the value received by the server.
85 * @return mixed the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
87 public function value()
93 * Returns an array with the cookies received from the server.
94 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
95 * with attributes being e.g. 'expires', 'path', domain'.
96 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
97 * are still present in the array. It is up to the user-defined code to decide
98 * how to use the received cookies, and whether they have to be sent back with the next
99 * request to the server (using xmlrpc_client::setCookie) or not
100 * @return array array of cookies received from the server
102 public function cookies()
104 return $this->_cookies;
108 * Returns xml representation of the response. XML prologue not included
109 * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
110 * @return string the xml representation of the response
112 public function serialize($charset_encoding='')
114 $xmlrpc = Phpxmlrpc::instance();
116 if ($charset_encoding != '')
117 $this->content_type = 'text/xml; charset=' . $charset_encoding;
119 $this->content_type = 'text/xml';
120 if ($xmlrpc->xmlrpc_null_apache_encoding)
122 $result = "<methodResponse xmlns:ex=\"".$xmlrpc->xmlrpc_null_apache_encoding_ns."\">\n";
126 $result = "<methodResponse>\n";
130 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
131 // by xml-encoding non ascii chars
132 $result .= "<fault>\n" .
133 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
134 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
135 xmlrpc_encode_entitites($this->errstr, $xmlrpc->xmlrpc_internalencoding, $charset_encoding) . "</string></value>\n</member>\n" .
136 "</struct>\n</value>\n</fault>";
140 if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
142 if (is_string($this->val) && $this->valtyp == 'xml')
144 $result .= "<params>\n<param>\n" .
146 "</param>\n</params>";
150 /// @todo try to build something serializable?
151 die('cannot serialize xmlrpcresp objects whose content is native php values');
156 $result .= "<params>\n<param>\n" .
157 $this->val->serialize($charset_encoding) .
158 "</param>\n</params>";
161 $result .= "\n</methodResponse>";
162 $this->payload = $result;