Open Monograph Press  3.3.0
generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php
1 <?php
2 
3 namespace PhpXmlRpc;
4 
6 
7 class Response
8 {
10  public $val = 0;
11  public $valType;
12  public $errno = 0;
13  public $errstr = '';
14  public $payload;
15  public $hdrs = array();
16  public $_cookies = array();
17  public $content_type = 'text/xml';
18  public $raw_data = '';
19 
30  public function __construct($val, $fCode = 0, $fString = '', $valType = '')
31  {
32  if ($fCode != 0) {
33  // error response
34  $this->errno = $fCode;
35  $this->errstr = $fString;
36  } else {
37  // successful response
38  $this->val = $val;
39  if ($valType == '') {
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';
45  } else {
46  $this->valtyp = 'phpvals';
47  }
48  } else {
49  // user declares type of resp value: believe him
50  $this->valtyp = $valType;
51  }
52  }
53  }
54 
60  public function faultCode()
61  {
62  return $this->errno;
63  }
64 
70  public function faultString()
71  {
72  return $this->errstr;
73  }
74 
80  public function value()
81  {
82  return $this->val;
83  }
84 
96  public function cookies()
97  {
98  return $this->_cookies;
99  }
100 
110  public function serialize($charsetEncoding = '')
111  {
112  if ($charsetEncoding != '') {
113  $this->content_type = 'text/xml; charset=' . $charsetEncoding;
114  } else {
115  $this->content_type = 'text/xml';
116  }
117  if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
118  $result = "<methodResponse xmlns:ex=\"" . PhpXmlRpc::$xmlrpc_null_apache_encoding_ns . "\">\n";
119  } else {
120  $result = "<methodResponse>\n";
121  }
122  if ($this->errno) {
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>";
130  } else {
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" .
134  $this->val .
135  "</param>\n</params>";
136  } else {
138  throw new \Exception('cannot serialize xmlrpc response objects whose content is native php values');
139  }
140  } else {
141  $result .= "<params>\n<param>\n" .
142  $this->val->serialize($charsetEncoding) .
143  "</param>\n</params>";
144  }
145  }
146  $result .= "\n</methodResponse>";
147  $this->payload = $result;
148 
149  return $result;
150  }
151 }
PhpXmlRpc\Helper\Charset
Definition: Charset.php:7
PhpXmlRpc\Response
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:7
PhpXmlRpc\Response\$valType
$valType
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:11
PhpXmlRpc\Response\cookies
cookies()
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:96
PhpXmlRpc\Response\faultCode
faultCode()
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:60
PhpXmlRpc\Response\serialize
serialize($charsetEncoding='')
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:110
PhpXmlRpc\Response\$payload
$payload
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:14
PhpXmlRpc\Response\value
value()
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:80
PhpXmlRpc\Response\faultString
faultString()
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:70
PhpXmlRpc
Definition: Autoloader.php:3
PhpXmlRpc\Response\__construct
__construct($val, $fCode=0, $fString='', $valType='')
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Response.php:30