5 use PhpXmlRpc\Helper\Charset;
9 /// @todo: do these need to be public?
15 public $hdrs = array();
16 public $_cookies = array();
17 public $content_type = 'text/xml';
18 public $raw_data = '';
21 * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
22 * @param integer $fcode set it to anything but 0 to create an error response
23 * @param string $fstr the error string, in case of an error response
24 * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
26 * @todo add check that $val / $fcode / $fstr is of correct type???
27 * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
28 * php val, or a complete xml chunk, depending on usage of Client::send() inside which creator is called...
30 public function __construct($val, $fcode = 0, $fstr = '', $valtyp = '')
34 $this->errno = $fcode;
35 $this->errstr = $fstr;
36 //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
38 // successful response
41 // user did not declare type of response value: try to guess it
42 if (is_object($this->val) && is_a($this->val, 'PhpXmlRpc\Value')) {
43 $this->valtyp = 'xmlrpcvals';
44 } elseif (is_string($this->val)) {
45 $this->valtyp = 'xml';
47 $this->valtyp = 'phpvals';
50 // user declares type of resp value: believe him
51 $this->valtyp = $valtyp;
57 * Returns the error code of the response.
59 * @return integer the error code of this response (0 for not-error responses)
61 public function faultCode()
67 * Returns the error code of the response.
69 * @return string the error string of this response ('' for not-error responses)
71 public function faultString()
77 * Returns the value received by the server.
79 * @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 Client objects
81 public function value()
87 * Returns an array with the cookies received from the server.
88 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
89 * with attributes being e.g. 'expires', 'path', domain'.
90 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
91 * are still present in the array. It is up to the user-defined code to decide
92 * how to use the received cookies, and whether they have to be sent back with the next
93 * request to the server (using Client::setCookie) or not.
95 * @return array array of cookies received from the server
97 public function cookies()
99 return $this->_cookies;
103 * Returns xml representation of the response. XML prologue not included.
105 * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
107 * @return string the xml representation of the response
109 public function serialize($charset_encoding = '')
111 if ($charset_encoding != '') {
112 $this->content_type = 'text/xml; charset=' . $charset_encoding;
114 $this->content_type = 'text/xml';
116 if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
117 $result = "<methodResponse xmlns:ex=\"" . PhpXmlRpc::$xmlrpc_null_apache_encoding_ns . "\">\n";
119 $result = "<methodResponse>\n";
122 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
123 // by xml-encoding non ascii chars
125 $result .= "<fault>\n" .
126 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
127 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
128 Charset::instance()->encode_entities($this->errstr, PhpXmlRpc::$xmlrpc_internalencoding, $charset_encoding) . "</string></value>\n</member>\n" .
129 "</struct>\n</value>\n</fault>";
131 if (!is_object($this->val) || !is_a($this->val, 'PhpXmlRpc\Value')) {
132 if (is_string($this->val) && $this->valtyp == 'xml') {
133 $result .= "<params>\n<param>\n" .
135 "</param>\n</params>";
137 /// @todo try to build something serializable?
138 die('cannot serialize xmlrpc response objects whose content is native php values');
141 $result .= "<params>\n<param>\n" .
142 $this->val->serialize($charset_encoding) .
143 "</param>\n</params>";
146 $result .= "\n</methodResponse>";
147 $this->payload = $result;