$msg[0] = new $requestClass($method, array(), $id);
// hack! build payload by hand
if ($wstype == 1) {
- $msg[0]->payload = "{\n" .
+ $payload = "{\n" .
'"method": "' . $method . "\",\n\"params\": [" .
$payload .
"\n],\n\"id\": ";
// fix: if user gave an empty string, use NULL, or we'll break json syntax
if ($id == "") {
- $msg[0]->payload .= "null\n}";
+ $payload .= "null\n}";
} else {
if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null') {
- $msg[0]->payload .= "$id\n}";
+ $payload .= "$id\n}";
} else {
- $msg[0]->payload .= "\"$id\"\n}";
+ $payload .= "\"$id\"\n}";
}
}
+ $msg[0]->setPayload($payload);
} else {
- $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
+ $msg[0]->setPayload(
+ $msg[0]->xml_header($inputcharset) .
'<methodName>' . $method . "</methodName>\n<params>" .
$payload .
- "</params>\n" . $msg[0]->xml_footer();
+ "</params>\n" . $msg[0]->xml_footer()
+ );
}
$actionname = 'Execution of method ' . $method;
break;
return $this->multicall($req, $timeout, $method);
} elseif (is_string($req)) {
$n = new static::$requestClass('');
- $n->payload = $req;
+ $n->setPayload($req);
$req = $n;
}
// Only create the payload if it was not created previously
/// @todo what if the request's payload was created with a different encoding?
/// Also, if we do not call serialize(), the request will not set its content-type to have the charset declared
- if (empty($req->payload)) {
- $req->serialize($opts['request_charset_encoding']);
+ $payload = $req->getPayload();
+ if (empty($payload)) {
+ $payload = $req->serialize($opts['request_charset_encoding']);
}
- $payload = $req->payload;
// Deflate request body and set appropriate request headers
$encodingHdr = '';
}
// Only create the payload if it was not created previously
- if (empty($req->payload)) {
- $req->serialize($opts['request_charset_encoding']);
+ $payload = $req->getPayload();
+ if (empty($payload)) {
+ $payload = $req->serialize($opts['request_charset_encoding']);
}
// Deflate request body and set appropriate request headers
- $payload = $req->payload;
$encodingHdr = '';
/// @todo test for existence of proper function, in case of polyfills
if (function_exists('gzdeflate') && ($opts['request_compression'] == 'gzip' || $opts['request_compression'] == 'deflate')) {
use PhpXmlRpc\Traits\CharsetEncoderAware;
use PhpXmlRpc\Traits\DeprecationLogger;
use PhpXmlRpc\Traits\ParserAware;
+use PhpXmlRpc\Traits\PayloadBearer;
/**
* This class provides the representation of a request to an XML-RPC server.
use CharsetEncoderAware;
use DeprecationLogger;
use ParserAware;
+ use PayloadBearer;
/// @todo: do these need to be public?
- public $payload;
/** @internal */
public $methodname;
/** @internal */
public $params = array();
/** @var int */
public $debug = 0;
- /** @var string */
- public $content_type = 'text/xml';
// holds data while parsing the response. NB: Not a full Response object
/** @deprecated will be removed in a future release */
use PhpXmlRpc\Exception\StateErrorException;
use PhpXmlRpc\Traits\CharsetEncoderAware;
use PhpXmlRpc\Traits\DeprecationLogger;
+use PhpXmlRpc\Traits\PayloadBearer;
/**
* This class provides the representation of the response of an XML-RPC server.
{
use CharsetEncoderAware;
use DeprecationLogger;
+ use PayloadBearer;
/// @todo: do these need to be public?
/** @internal */
public $errno = 0;
/** @internal */
public $errstr = '';
- public $payload;
- /** @var string */
- public $content_type = 'text/xml';
protected $httpResponse = array('headers' => array(), 'cookies' => array(), 'raw_data' => '', 'status_code' => null);
/// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
- return null;
+ $result = null;
+ return $result;
}
}
static::$_xmlrpcs_occurred_errors . "+++END+++");
}
- $payload = $resp->xml_header($respCharset);
+ $header = $resp->xml_header($respCharset);
if ($this->debug > 0) {
- $payload = $payload . $this->serializeDebug($respCharset);
+ $header .= $this->serializeDebug($respCharset);
}
// Do not create response serialization if it has already happened. Helps to build json magic
/// @todo what if the payload was created targeting a different charset than $respCharset?
/// Also, if we do not call serialize(), the request will not set its content-type to have the charset declared
- if (empty($resp->payload)) {
- $resp->serialize($respCharset);
+ $payload = $resp->getPayload();
+ if (empty($payload)) {
+ $payload = $resp->serialize($respCharset);
}
- $payload = $payload . $resp->payload;
+ $payload = $header . $payload;
if ($returnPayload) {
return $payload;
--- /dev/null
+<?php
+
+namespace PhpXmlRpc\Traits;
+
+trait PayloadBearer
+{
+ /** @var string */
+ public $payload;
+ /** @var string */
+ public $content_type = 'text/xml';
+
+ /**
+ * @internal
+ *
+ * @param string $payload
+ * @param string $contentType
+ * @return $this
+ */
+ public function setPayload($payload, $contentType = '')
+ {
+ $this->payload = $payload;
+
+ if ($contentType != '') {
+ $this->content_type = $contentType;
+ }
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPayload()
+ {
+ return $this->payload;
+ }
+}