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 xmlrpc value obj, a php value or the xml serialization of an xmlrpc value (a string)
22 * @param integer $fCode set it to anything but 0 to create an error response
23 * @param string $fString the error string, in case of an error response
24 * @param string $valType either 'xmlrpcvals', 'phpvals' or 'xml'
26 * @todo add check that $val / $fCode / $fString is of correct type???
27 * NB: as of now we do not do it, since it might be either an xmlrpc value 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, $fString = '', $valType = '')
34 $this->errno = $fCode;
35 $this->errstr = $fString;
36 //$this->errstr = htmlspecialchars($fString); // 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 = $valType;
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 xmlrpc value 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 $charsetEncoding the charset to be used for serialization. if null, US-ASCII is assumed
107 * @return string the xml representation of the response
111 public function serialize($charsetEncoding = '')
113 if ($charsetEncoding != '') {
114 $this->content_type = 'text/xml; charset=' . $charsetEncoding;
116 $this->content_type = 'text/xml';
118 if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
119 $result = "<methodResponse xmlns:ex=\"" . PhpXmlRpc::$xmlrpc_null_apache_encoding_ns . "\">\n";
121 $result = "<methodResponse>\n";
124 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
125 // by xml-encoding non ascii chars
126 $result .= "<fault>\n" .
127 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
128 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
129 Charset::instance()->encodeEntities($this->errstr, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</string></value>\n</member>\n" .
130 "</struct>\n</value>\n</fault>";
132 if (!is_object($this->val) || !is_a($this->val, 'PhpXmlRpc\Value')) {
133 if (is_string($this->val) && $this->valtyp == 'xml') {
134 $result .= "<params>\n<param>\n" .
136 "</param>\n</params>";
138 /// @todo try to build something serializable?
139 throw new \Exception('cannot serialize xmlrpc response objects whose content is native php values');
142 $result .= "<params>\n<param>\n" .
143 $this->val->serialize($charsetEncoding) .
144 "</param>\n</params>";
147 $result .= "\n</methodResponse>";
148 $this->payload = $result;