## XML-RPC for PHP version 4.xx - unreleased
+* changed: the minimum php version required has increased to 5.4
+
* new: allow to specify other charsets than the canonical three (UTF-8, ISO-8859-1, ASCII), when mbstring is
available, both for outgoing and incoming data.
changed: it now returns a Response for the cases in which it previously returned false, and an array of Response
objects for the cases in which it previously returned a string
- if you subclassed the `Client` class, take care of new static variables `$requestClass` and `$responseClass`
-
+ - traits have been introduced for all classes dealing with Logger, XMLParser and CharsetEncoder; method `setCharsetEncoder`
+ is now static
## XML-RPC for PHP version 4.9.5 - 2023/01/11
"homepage": "https://gggeek.github.io/phpxmlrpc/",
"keywords": [ "xmlrpc", "xml-rpc","webservices" ],
"require": {
- "php": "^5.3.0 || ^7.0 || ^8.0",
+ "php": "^5.4.0 || ^7.0 || ^8.0",
"ext-xml": "*"
},
"_comment::tests": "The dev packages below require a minimum of php 5.4, even though we support php 5.3. Can we manage to do better?",
namespace PhpXmlRpc;
//use PhpXmlRpc\Helper\Charset;
-use PhpXmlRpc\Helper\Logger;
use PhpXmlRpc\Helper\XMLParser;
+use PhpXmlRpc\Traits\LoggerAware;
/**
* Used to represent a client of an XML-RPC server.
*/
class Client
{
+ use LoggerAware;
+
const USE_CURL_NEVER = 0;
const USE_CURL_ALWAYS = 1;
const USE_CURL_AUTO = 2;
- protected static $logger;
/** @var string */
protected static $requestClass = '\\PhpXmlRpc\\Request';
/** @var string */
*/
public $xmlrpc_curl_handle = null;
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
/**
* @param string $path either the PATH part of the xml-rpc server URL, or complete server URL (in which case you
* should use and empty string for all other parameters)
namespace PhpXmlRpc;
-use PhpXmlRpc\Helper\Logger;
use PhpXmlRpc\Helper\XMLParser;
+use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\ParserAware;
/**
* A helper class to easily convert between Value objects and php native values.
*/
class Encoder
{
- protected static $logger;
- protected static $parser;
-
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
- public function getParser()
- {
- if (self::$parser === null) {
- self::$parser = new XMLParser();
- }
- return self::$parser;
- }
-
- /**
- * @param $parser
- * @return void
- */
- public static function setParser($parser)
- {
- self::$parser = $parser;
- }
+ use LoggerAware;
+ use ParserAware;
/**
* Takes an xml-rpc Value in object instance and translates it into native PHP types, recursively.
namespace PhpXmlRpc\Helper;
use PhpXmlRpc\PhpXmlRpc;
+use PhpXmlRpc\Traits\LoggerAware;
/**
* @todo implement an interface
*/
class Charset
{
- protected static $logger;
+ use LoggerAware;
// tables used for transcoding different charsets into us-ascii xml
protected $xml_iso88591_Entities = array("in" => array(), "out" => array());
return self::$instance;
}
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
/**
* Force usage as singleton.
*/
use PhpXmlRpc\Exception\HttpException;
use PhpXmlRpc\PhpXmlRpc;
+use PhpXmlRpc\Traits\LoggerAware;
-/**
- *
- */
class Http
{
- protected static $logger;
-
- public static function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
+ use LoggerAware;
/**
* Decode a string that is encoded with "chunked" transfer encoding as defined in rfc2068 par. 19.4.6.
namespace PhpXmlRpc\Helper;
use PhpXmlRpc\PhpXmlRpc;
+use PhpXmlRpc\Traits\LoggerAware;
use PhpXmlRpc\Value;
/**
*/
class XMLParser
{
+ use LoggerAware;
+
const RETURN_XMLRPCVALS = 'xmlrpcvals';
const RETURN_EPIVALS = 'epivals';
const RETURN_PHP = 'phpvals';
const ACCEPT_VALUE = 4;
const ACCEPT_FAULT = 8;
- protected static $logger;
-
/**
* @var int
* The max length beyond which data will get truncated in error messages
/** @var array supported keys: accept, target_charset, methodname_callback, xmlrpc_null_extension, xmlrpc_return_datetimes */
protected $current_parsing_options = array();
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
/**
* @param array $options integer keys: options passed to the xml parser
* string keys:
namespace PhpXmlRpc;
use PhpXmlRpc\Exception\HttpException;
-use PhpXmlRpc\Helper\Charset;
use PhpXmlRpc\Helper\Http;
-use PhpXmlRpc\Helper\Logger;
use PhpXmlRpc\Helper\XMLParser;
+use PhpXmlRpc\Traits\CharsetEncoderAware;
+use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\ParserAware;
/**
* This class provides the representation of a request to an XML-RPC server.
*/
class Request
{
- protected static $logger;
- protected static $parser;
- protected static $charsetEncoder;
+ use CharsetEncoderAware;
+ use LoggerAware;
+ use ParserAware;
/// @todo: do these need to be public?
public $payload;
/** @deprecated will be removed in a future release */
protected $httpResponse = array();
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
- public function getParser()
- {
- if (self::$parser === null) {
- self::$parser = new XMLParser();
- }
- return self::$parser;
- }
-
- /**
- * @param $parser
- * @return void
- */
- public static function setParser($parser)
- {
- self::$parser = $parser;
- }
-
- public function getCharsetEncoder()
- {
- if (self::$charsetEncoder === null) {
- self::$charsetEncoder = Charset::instance();
- }
- return self::$charsetEncoder;
- }
-
- /**
- * @param $charsetEncoder
- * @return void
- *
- * @todo this should be a static method
- */
- public function setCharsetEncoder($charsetEncoder)
- {
- self::$charsetEncoder = $charsetEncoder;
- }
-
/**
* @param string $methodName the name of the method to invoke
* @param Value[] $params array of parameters to be passed to the method (NB: Value objects, not plain php values)
namespace PhpXmlRpc;
-use PhpXmlRpc\Helper\Charset;
+use PhpXmlRpc\Traits\CharsetEncoderAware;
/**
* This class provides the representation of the response of an XML-RPC server.
*/
class Response
{
- protected static $charsetEncoder;
+ use CharsetEncoderAware;
/// @todo: do these need to be public?
/** @internal */
public $content_type = 'text/xml';
protected $httpResponse = array('headers' => array(), 'cookies' => array(), 'raw_data' => '', 'status_code' => null);
- public function getCharsetEncoder()
- {
- if (self::$charsetEncoder === null) {
- self::$charsetEncoder = Charset::instance();
- }
- return self::$charsetEncoder;
- }
-
- /**
- * @param $charsetEncoder
- * @return void
- *
- * @todo this should be a static method
- */
- public function setCharsetEncoder($charsetEncoder)
- {
- self::$charsetEncoder = $charsetEncoder;
- }
-
/**
* @param Value|string|mixed $val either a Value object, a php value or the xml serialization of an xml-rpc value (a string)
* @param integer $fCode set it to anything but 0 to create an error response. In that case, $val is discarded
namespace PhpXmlRpc;
use PhpXmlRpc\Exception\PhpXmlrpcException;
-use PhpXmlRpc\Helper\Charset;
use PhpXmlRpc\Helper\Http;
use PhpXmlRpc\Helper\Logger;
use PhpXmlRpc\Helper\XMLParser;
+use PhpXmlRpc\Traits\CharsetEncoderAware;
+use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\ParserAware;
/**
* Allows effortless implementation of XML-RPC servers
*/
class Server
{
- protected static $logger;
- protected static $parser;
- protected static $charsetEncoder;
+ use CharsetEncoderAware;
+ use LoggerAware;
+ use ParserAware;
/**
* @var string
protected static $_xmlrpcs_occurred_errors = '';
protected static $_xmlrpcs_prev_ehandler = '';
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
- public function getParser()
- {
- if (self::$parser === null) {
- self::$parser = new XMLParser();
- }
- return self::$parser;
- }
-
- /**
- * @param $parser
- * @return void
- */
- public static function setParser($parser)
- {
- self::$parser = $parser;
- }
-
- public function getCharsetEncoder()
- {
- if (self::$charsetEncoder === null) {
- self::$charsetEncoder = Charset::instance();
- }
- return self::$charsetEncoder;
- }
-
- /**
- * @param $charsetEncoder
- * @return void
- *
- * @todo this should be a static method
- */
- public function setCharsetEncoder($charsetEncoder)
- {
- self::$charsetEncoder = $charsetEncoder;
- }
-
/**
* @param array[] $dispatchMap the dispatch map with definition of exposed services
* Array keys are the names of the method names.
--- /dev/null
+<?php
+
+namespace PhpXmlRpc\Traits;
+
+use PhpXmlRpc\Helper\Charset;
+
+trait CharsetEncoderAware
+{
+ protected static $charsetEncoder;
+
+ public function getCharsetEncoder()
+ {
+ if (self::$charsetEncoder === null) {
+ self::$charsetEncoder = Charset::instance();
+ }
+ return self::$charsetEncoder;
+ }
+
+ /**
+ * @param $charsetEncoder
+ * @return void
+ */
+ public static function setCharsetEncoder($charsetEncoder)
+ {
+ self::$charsetEncoder = $charsetEncoder;
+ }
+}
--- /dev/null
+<?php
+
+namespace PhpXmlRpc\Traits;
+
+use PhpXmlRpc\Helper\Logger;
+
+trait LoggerAware
+{
+ protected static $logger;
+
+ public function getLogger()
+ {
+ if (self::$logger === null) {
+ self::$logger = Logger::instance();
+ }
+ return self::$logger;
+ }
+
+ /**
+ * @param $logger
+ * @return void
+ */
+ public static function setLogger($logger)
+ {
+ self::$logger = $logger;
+ }
+}
--- /dev/null
+<?php
+
+namespace PhpXmlRpc\Traits;
+
+use PhpXmlRpc\Helper\XMLParser;
+
+trait ParserAware
+{
+ protected static $parser;
+
+ public function getParser()
+ {
+ if (self::$parser === null) {
+ self::$parser = new XMLParser();
+ }
+ return self::$parser;
+ }
+
+ /**
+ * @param $parser
+ * @return void
+ */
+ public static function setParser($parser)
+ {
+ self::$parser = $parser;
+ }
+}
namespace PhpXmlRpc;
-use PhpXmlRpc\Helper\Charset;
-use PhpXmlRpc\Helper\Logger;
+use PhpXmlRpc\Traits\CharsetEncoderAware;
+use PhpXmlRpc\Traits\LoggerAware;
/**
* This class enables the creation of values for XML-RPC, by encapsulating plain php values.
*/
class Value implements \Countable, \IteratorAggregate, \ArrayAccess
{
+ use CharsetEncoderAware;
+ use LoggerAware;
+
public static $xmlrpcI4 = "i4";
public static $xmlrpcI8 = "i8";
public static $xmlrpcInt = "int";
"null" => 1,
);
- protected static $logger;
- protected static $charsetEncoder;
-
/// @todo: do these need to be public?
/** @var Value[]|mixed */
public $me = array();
/** @var string|null */
public $_php_class = null;
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
- public function getCharsetEncoder()
- {
- if (self::$charsetEncoder === null) {
- self::$charsetEncoder = Charset::instance();
- }
- return self::$charsetEncoder;
- }
-
- /**
- * @param $charsetEncoder
- * @return void
- *
- * @todo this should be a static method
- */
- public function setCharsetEncoder($charsetEncoder)
- {
- self::$charsetEncoder = $charsetEncoder;
- }
-
/**
* Build an xml-rpc value.
*
namespace PhpXmlRpc;
-use PhpXmlRpc\Helper\Logger;
+use PhpXmlRpc\Traits\LoggerAware;
/**
* PHPXMLRPC "wrapper" class - generate stubs to transparently access xml-rpc methods as php functions and vice-versa.
*/
class Wrapper
{
+ use LoggerAware;
+
/**
* @var object[]
* Used to hold a reference to object instances whose methods get wrapped by wrapPhpFunction(), in 'create source' mode
*/
public static $objHolder = array();
- protected static $logger;
-
/** @var string */
protected static $namespace = '\\PhpXmlRpc\\';
- public function getLogger()
- {
- if (self::$logger === null) {
- self::$logger = Logger::instance();
- }
- return self::$logger;
- }
-
- /**
- * @param $logger
- * @return void
- */
- public static function setLogger($logger)
- {
- self::$logger = $logger;
- }
-
/**
* Given a string defining a php type or phpxmlrpc type (loosely defined: strings
* accepted come from javadoc blocks), return corresponding phpxmlrpc type.
$l = $ch->getLogger();
Charset::setLogger($this);
+ ob_start();
$ch->encodeEntities('hello world', 'UTF-8', 'NOT-A-CHARSET');
+ $o = ob_get_clean();
+ $this->assertEquals('', $o);
$this->assertStringContainsString("via mbstring: failed", $this->errorBuffer);
Charset::setLogger($l);
public function testHttpAltLogger()
{
- $l = Http::getLogger();
+ $h = new Http();
+ $l = $h->getLogger();
Http::setLogger($this);
- $h = new Http();
$s = "HTTP/1.0 200 OK\r\n" .
"Content-Type: unknown\r\n" .
"\r\n" .
"body";
+ ob_start();
$h->parseResponseHeaders($s, false, 1);
+ $o = ob_get_clean();
+ $this->assertEquals('', $o);
$this->assertStringContainsString("HEADER: content-type: unknown", $this->debugBuffer);
Http::setLogger($l);
}
$l = $xp->getLogger();
XMLParser::setLogger($this);
+ ob_start();
$xp->parse('<?xml version="1.0" ?><methodResponse><params><param><value><boolean>x</boolean></value></param></params></methodResponse>');
+ $o = ob_get_clean();
+ $this->assertEquals('', $o);
$this->assertStringContainsString("invalid data received in BOOLEAN value", $this->errorBuffer);
XMLParser::setLogger($l);