5 use PhpXmlRpc\Helper\Charset;
10 /// @todo: do these need to be public?
16 public $hdrs = array();
17 public $_cookies = array();
18 public $content_type = 'text/xml';
19 public $raw_data = '';
22 * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
23 * @param integer $fcode set it to anything but 0 to create an error response
24 * @param string $fstr the error string, in case of an error response
25 * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
27 * @todo add check that $val / $fcode / $fstr is of correct type???
28 * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
29 * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
31 function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
36 $this->errno = $fcode;
37 $this->errstr = $fstr;
38 //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
42 // successful response
46 // user did not declare type of response value: try to guess it
47 if (is_object($this->val) && is_a($this->val, 'PhpXmlRpc\Value'))
49 $this->valtyp = 'xmlrpcvals';
51 else if (is_string($this->val))
53 $this->valtyp = 'xml';
57 $this->valtyp = 'phpvals';
62 // user declares type of resp value: believe him
63 $this->valtyp = $valtyp;
69 * Returns the error code of the response.
70 * @return integer the error code of this response (0 for not-error responses)
72 public function faultCode()
78 * Returns the error code of the response.
79 * @return string the error string of this response ('' for not-error responses)
81 public function faultString()
87 * Returns the value received by the server.
88 * @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
90 public function value()
96 * Returns an array with the cookies received from the server.
97 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
98 * with attributes being e.g. 'expires', 'path', domain'.
99 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
100 * are still present in the array. It is up to the user-defined code to decide
101 * how to use the received cookies, and whether they have to be sent back with the next
102 * request to the server (using xmlrpc_client::setCookie) or not
103 * @return array array of cookies received from the server
105 public function cookies()
107 return $this->_cookies;
111 * Returns xml representation of the response. XML prologue not included
112 * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
113 * @return string the xml representation of the response
115 public function serialize($charset_encoding='')
117 if ($charset_encoding != '')
118 $this->content_type = 'text/xml; charset=' . $charset_encoding;
120 $this->content_type = 'text/xml';
121 if (PhpXmlRpc::$xmlrpc_null_apache_encoding)
123 $result = "<methodResponse xmlns:ex=\"".PhpXmlRpc::$xmlrpc_null_apache_encoding_ns."\">\n";
127 $result = "<methodResponse>\n";
131 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
132 // by xml-encoding non ascii chars
134 $result .= "<fault>\n" .
135 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
136 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
137 Charset::instance()->encode_entities($this->errstr, PhpXmlRpc::$xmlrpc_internalencoding, $charset_encoding) . "</string></value>\n</member>\n" .
138 "</struct>\n</value>\n</fault>";
142 if(!is_object($this->val) || !is_a($this->val, 'PhpXmlRpc\Value'))
144 if (is_string($this->val) && $this->valtyp == 'xml')
146 $result .= "<params>\n<param>\n" .
148 "</param>\n</params>";
152 /// @todo try to build something serializable?
153 die('cannot serialize xmlrpcresp objects whose content is native php values');
158 $result .= "<params>\n<param>\n" .
159 $this->val->serialize($charset_encoding) .
160 "</param>\n</params>";
163 $result .= "\n</methodResponse>";
164 $this->payload = $result;