4 /// @todo: does these need to be public?
10 public $hdrs = array();
11 public $_cookies = array();
12 public $content_type = 'text/xml';
13 public $raw_data = '';
16 * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
17 * @param integer $fcode set it to anything but 0 to create an error response
18 * @param string $fstr the error string, in case of an error response
19 * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
21 * @todo add check that $val / $fcode / $fstr is of correct type???
22 * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
23 * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
25 function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
30 $this->errno = $fcode;
31 $this->errstr = $fstr;
32 //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
36 // successful response
40 // user did not declare type of response value: try to guess it
41 if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
43 $this->valtyp = 'xmlrpcvals';
45 else if (is_string($this->val))
47 $this->valtyp = 'xml';
52 $this->valtyp = 'phpvals';
57 // user declares type of resp value: believe him
58 $this->valtyp = $valtyp;
64 * Returns the error code of the response.
65 * @return integer the error code of this response (0 for not-error responses)
67 public function faultCode()
73 * Returns the error code of the response.
74 * @return string the error string of this response ('' for not-error responses)
76 public function faultString()
82 * Returns the value received by the server.
83 * @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
85 public function value()
91 * Returns an array with the cookies received from the server.
92 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
93 * with attributes being e.g. 'expires', 'path', domain'.
94 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
95 * are still present in the array. It is up to the user-defined code to decide
96 * how to use the received cookies, and whether they have to be sent back with the next
97 * request to the server (using xmlrpc_client::setCookie) or not
98 * @return array array of cookies received from the server
100 public function cookies()
102 return $this->_cookies;
106 * Returns xml representation of the response. XML prologue not included
107 * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
108 * @return string the xml representation of the response
110 public function serialize($charset_encoding='')
112 $xmlrpc = Phpxmlrpc::instance();
114 if ($charset_encoding != '')
115 $this->content_type = 'text/xml; charset=' . $charset_encoding;
117 $this->content_type = 'text/xml';
118 if ($xmlrpc->xmlrpc_null_apache_encoding)
120 $result = "<methodResponse xmlns:ex=\"".$xmlrpc->xmlrpc_null_apache_encoding_ns."\">\n";
124 $result = "<methodResponse>\n";
128 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
129 // by xml-encoding non ascii chars
130 $result .= "<fault>\n" .
131 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
132 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
133 xmlrpc_encode_entitites($this->errstr, $xmlrpc->xmlrpc_internalencoding, $charset_encoding) . "</string></value>\n</member>\n" .
134 "</struct>\n</value>\n</fault>";
138 if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
140 if (is_string($this->val) && $this->valtyp == 'xml')
142 $result .= "<params>\n<param>\n" .
144 "</param>\n</params>";
148 /// @todo try to build something serializable?
149 die('cannot serialize xmlrpcresp objects whose content is native php values');
154 $result .= "<params>\n<param>\n" .
155 $this->val->serialize($charset_encoding) .
156 "</param>\n</params>";
159 $result .= "\n</methodResponse>";
160 $this->payload = $result;