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;
37 // 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, 'PhpXmlRpc\Value')) {
42 $this->valtyp = 'xmlrpcvals';
43 } elseif (is_string($this->val)) {
44 $this->valtyp = 'xml';
46 $this->valtyp = 'phpvals';
49 // user declares type of resp value: believe him
50 $this->valtyp = $valType;
56 * Returns the error code of the response.
58 * @return integer the error code of this response (0 for not-error responses)
60 public function faultCode()
66 * Returns the error code of the response.
68 * @return string the error string of this response ('' for not-error responses)
70 public function faultString()
76 * Returns the value received by the server.
78 * @return Value|string|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
80 public function value()
86 * Returns an array with the cookies received from the server.
87 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
88 * with attributes being e.g. 'expires', 'path', domain'.
89 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
90 * are still present in the array. It is up to the user-defined code to decide
91 * how to use the received cookies, and whether they have to be sent back with the next
92 * request to the server (using Client::setCookie) or not.
94 * @return array array of cookies received from the server
96 public function cookies()
98 return $this->_cookies;
102 * Returns xml representation of the response. XML prologue not included.
104 * @param string $charsetEncoding the charset to be used for serialization. if null, US-ASCII is assumed
106 * @return string the xml representation of the response
110 public function serialize($charsetEncoding = '')
112 if ($charsetEncoding != '') {
113 $this->content_type = 'text/xml; charset=' . $charsetEncoding;
115 $this->content_type = 'text/xml';
117 if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
118 $result = "<methodResponse xmlns:ex=\"" . PhpXmlRpc::$xmlrpc_null_apache_encoding_ns . "\">\n";
120 $result = "<methodResponse>\n";
123 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
124 // 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()->encodeEntities($this->errstr, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</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 throw new \Exception('cannot serialize xmlrpc response objects whose content is native php values');
141 $result .= "<params>\n<param>\n" .
142 $this->val->serialize($charsetEncoding) .
143 "</param>\n</params>";
146 $result .= "\n</methodResponse>";
147 $this->payload = $result;