1 | <?php |
||
12 | class Response |
||
13 | { |
||
14 | /// @todo: do these need to be public? |
||
15 | public $val = 0; |
||
16 | public $valtyp; |
||
17 | public $errno = 0; |
||
18 | public $errstr = ''; |
||
19 | public $payload; |
||
20 | public $hdrs = array(); |
||
21 | public $_cookies = array(); |
||
22 | public $content_type = 'text/xml'; |
||
23 | public $raw_data = ''; |
||
24 | |||
25 | /** |
||
26 | * @param mixed $val either a Value object, a php value or the xml serialization of an xmlrpc value (a string) |
||
27 | * @param integer $fCode set it to anything but 0 to create an error response. In that case, $val is discarded |
||
28 | * @param string $fString the error string, in case of an error response |
||
29 | * @param string $valType The type of $val passed in. Either 'xmlrpcvals', 'phpvals' or 'xml'. Leave empty to let |
||
30 | * the code guess the correct type. |
||
31 | * |
||
32 | * @todo add check that $val / $fCode / $fString is of correct type??? |
||
33 | * NB: as of now we do not do it, since it might be either an xmlrpc value or a plain php val, or a complete |
||
34 | * xml chunk, depending on usage of Client::send() inside which creator is called... |
||
35 | */ |
||
36 | 603 | public function __construct($val, $fCode = 0, $fString = '', $valType = '') |
|
37 | { |
||
38 | 603 | if ($fCode != 0) { |
|
39 | // error response |
||
40 | 191 | $this->errno = $fCode; |
|
41 | 191 | $this->errstr = $fString; |
|
42 | } else { |
||
43 | // successful response |
||
44 | 534 | $this->val = $val; |
|
45 | 534 | if ($valType == '') { |
|
46 | // user did not declare type of response value: try to guess it |
||
47 | 441 | if (is_object($this->val) && is_a($this->val, 'PhpXmlRpc\Value')) { |
|
48 | 441 | $this->valtyp = 'xmlrpcvals'; |
|
49 | } elseif (is_string($this->val)) { |
||
50 | $this->valtyp = 'xml'; |
||
51 | } else { |
||
52 | 23 | $this->valtyp = 'phpvals'; |
|
53 | } |
||
54 | } else { |
||
55 | // user declares type of resp value: believe him |
||
56 | 533 | $this->valtyp = $valType; |
|
57 | } |
||
58 | } |
||
59 | 603 | } |
|
60 | |||
61 | /** |
||
62 | * Returns the error code of the response. |
||
63 | * |
||
64 | * @return integer the error code of this response (0 for not-error responses) |
||
65 | */ |
||
66 | 591 | public function faultCode() |
|
70 | |||
71 | /** |
||
72 | * Returns the error code of the response. |
||
73 | * |
||
74 | * @return string the error string of this response ('' for not-error responses) |
||
75 | */ |
||
76 | 485 | public function faultString() |
|
80 | |||
81 | /** |
||
82 | * Returns the value received by the server. If the Response's faultCode is non-zero then the value returned by this |
||
83 | * method should not be used (it may not even be an object). |
||
84 | * |
||
85 | * @return Value|string|mixed the Value object returned by the server. Might be an xml string or plain php value |
||
86 | * depending on the convention adopted when creating the Response |
||
87 | */ |
||
88 | 531 | public function value() |
|
92 | |||
93 | /** |
||
94 | * Returns an array with the cookies received from the server. |
||
95 | * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 => $val2, ...) |
||
96 | * with attributes being e.g. 'expires', 'path', domain'. |
||
97 | * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past) are still present in the array. |
||
98 | * It is up to the user-defined code to decide how to use the received cookies, and whether they have to be sent back |
||
99 | * with the next request to the server (using Client::setCookie) or not. |
||
100 | * |
||
101 | * @return array array of cookies received from the server |
||
102 | */ |
||
103 | 18 | public function cookies() |
|
107 | |||
108 | /** |
||
109 | * Returns xml representation of the response. XML prologue not included. |
||
110 | * |
||
111 | * @param string $charsetEncoding the charset to be used for serialization. If null, US-ASCII is assumed |
||
112 | * |
||
113 | * @return string the xml representation of the response |
||
114 | * |
||
115 | * @throws \Exception |
||
116 | */ |
||
117 | 441 | public function serialize($charsetEncoding = '') |
|
158 | } |
||
159 |