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`,
which should be used to instantiate requests and responses
- - if you replaced the Logger class, take care that you will have to implement methods `error` and `debug` (all is ok
- if you subclassed id)
+ - if you replaced the Logger class, take care that you will have to implement methods `error`, `warning` and `debug`
+ (all is ok if you subclassed it)
- traits have been introduced for all classes dealing with Logger, XMLParser and CharsetEncoder; method `setCharsetEncoder`
is now static
- exception `\PhpXmlRpc\Exception\PhpXmlRpcException` is deprecated. Use `\PhpXmlRpc\Exception` instead
//use PhpXmlRpc\Helper\Charset;
use PhpXmlRpc\Exception\ValueErrorException;
use PhpXmlRpc\Helper\XMLParser;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
/**
* Used to represent a client of an XML-RPC server.
*/
class Client
{
- use LoggerAware;
+ use DeprecationLogger;
const USE_CURL_NEVER = 0;
const USE_CURL_ALWAYS = 1;
*/
public function send($req, $timeout = 0, $method = '')
{
- //if ($method !== '' || $timeout !== 0) {
- // trigger_error("Using non-default values for arguments 'method' and 'timeout' when calling method " . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
- //}
+ if ($method !== '' || $timeout !== 0) {
+ $this->logDeprecation("Using non-default values for arguments 'method' and 'timeout' when calling method " . __METHOD__ . ' is deprecated');
+ }
// if user does not specify http protocol, use native method of this client
// (i.e. method set during call to constructor)
$authType = 1, $proxyHost = '', $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1,
$method='http')
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return $this->sendPayloadSocket($req, $server, $port, $timeout, $username, $password, $authType, null, null,
null, null, $proxyHost, $proxyPort, $proxyUsername, $proxyPassword, $proxyAuthType, $method);
$proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $keepAlive = false, $key = '', $keyPass = '',
$sslVersion = 0)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return $this->sendPayloadCURL($req, $server, $port, $timeout, $username,
$password, $authType, $cert, $certPass, $caCert, $caCertDir, $proxyHost, $proxyPort,
if ($xmlRpcParser->_xh['isf'] > 1) {
// test that $xmlrpc->_xh['value'] is an obj, too???
- $this->getLogger()->error($xmlRpcParser->_xh['isf_reason']);
+ $this->getLogger()->error('XML-RPC: ' . $xmlRpcParser->_xh['isf_reason']);
return false;
}
use PhpXmlRpc\Exception\ValueErrorException;
use PhpXmlRpc\PhpXmlRpc;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
/**
* @todo implement an interface
*/
class Charset
{
- use LoggerAware;
+ use DeprecationLogger;
// tables used for transcoding different charsets into us-ascii xml
protected $xml_iso88591_Entities = array("in" => array(), "out" => array());
*/
public function isValidCharset($encoding, $validList)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
if (is_string($validList)) {
$validList = explode(',', $validList);
*/
public function getEntities($charset)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
switch ($charset)
{
}
}
+ /**
+ * Following the general principle of 'never break stdout', the default behaviour
+ *
+ * @param string $message
+ * @param $context
+ * @return void
+ */
+ public function warning($message, $context = array())
+ {
+ $this->errorLog(preg_replace('/^XML-RPC :/', 'XML-RPC Warning: ', $message));
+ }
+
/**
* Triggers the writing of a message to php's error log
*
*/
public function error($message, $context = array())
{
- $this->errorLog($message);
+ $this->errorLog(preg_replace('/^XML-RPC :/', 'XML-RPC Error: ', $message));
}
// BC interface
namespace PhpXmlRpc\Helper;
use PhpXmlRpc\PhpXmlRpc;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
use PhpXmlRpc\Value;
/**
*/
class XMLParser
{
- use LoggerAware;
+ use DeprecationLogger;
const RETURN_XMLRPCVALS = 'xmlrpcvals';
const RETURN_EPIVALS = 'epivals';
public function __set($name, $value)
{
- //trigger_error('setting property Response::' . $name . ' is deprecated', E_USER_DEPRECATED);
-
switch ($name) {
// this should only ever be called by subclasses which overtook `parse()`
case 'accept':
+ $this->logDeprecation('Setting property XMLParser::' . $name . ' is deprecated');
$this->current_parsing_options['accept'] = $value;
break;
default:
+ /// @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);
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
}
public function __isset($name)
{
- //trigger_error('checking property Response::' . $name . ' is deprecated', E_USER_DEPRECATED);
-
switch ($name) {
case 'accept':
+ $this->logDeprecation('Checking property XMLParser::' . $name . ' is deprecated');
return isset($this->current_parsing_options['accept']);
default:
return false;
switch ($name) {
// q: does this make sense at all?
case 'accept':
+ $this->logDeprecation('Unsetting property XMLParser::' . $name . ' is deprecated');
unset($this->current_parsing_options['accept']);
break;
default:
+ /// @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);
trigger_error('Undefined property via __unset(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
}
* received charset cannot be determined and mbstring extension is not enabled.
*/
public static $xmlrpc_defencoding = "UTF-8";
-
/**
* @var string[]
* The list of preferred encodings used by the server for requests and by the client for responses to detect the
* - mbstring extension is enabled
*/
public static $xmlrpc_detectencodings = array();
-
/**
* @var string
* The encoding used internally by PHP.
*/
public static $xmlrpc_methodname_format = '|^[ \t]*[a-zA-Z0-9_.:/]+[ \t]*$|';
+ /**
+ * @var bool
+ * Set this to false to have a warning added to the log whenever user code uses a deprecated method/parameter/property
+ */
+ public static $xmlrpc_silence_deprecations = true;
+
/**
* A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
* such as library version etc...
* @return void
+ *
+ * @deprecated
*/
public static function exportGlobals()
{
* 4. run your own code.
*
* @return void
+ *
+ * @deprecated
*/
public static function importGlobals()
{
use PhpXmlRpc\Helper\Http;
use PhpXmlRpc\Helper\XMLParser;
use PhpXmlRpc\Traits\CharsetEncoderAware;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
use PhpXmlRpc\Traits\ParserAware;
/**
class Request
{
use CharsetEncoderAware;
- use LoggerAware;
+ use DeprecationLogger;
use ParserAware;
/// @todo: do these need to be public?
use PhpXmlRpc\Exception\StateErrorException;
use PhpXmlRpc\Traits\CharsetEncoderAware;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
/**
* This class provides the representation of the response of an XML-RPC server.
class Response
{
use CharsetEncoderAware;
- use LoggerAware;
+ use DeprecationLogger;
/// @todo: do these need to be public?
/** @internal */
// we have to make this return by ref in order to allow calls such as `$resp->_cookies['name'] = ['value' => 'something'];`
public function &__get($name)
{
- //trigger_error('getting property Response::' . $name . ' is deprecated', E_USER_DEPRECATED);
-
switch ($name) {
case 'hdrs':
+ $this->logDeprecation('Getting property Response::' . $name . ' is deprecated');
return $this->httpResponse['headers'];
case '_cookies':
+ $this->logDeprecation('Getting property Response::' . $name . ' is deprecated');
return $this->httpResponse['cookies'];
case 'raw_data':
+ $this->logDeprecation('Getting property Response::' . $name . ' is deprecated');
return $this->httpResponse['raw_data'];
default:
+ /// @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);
trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
return null;
public function __set($name, $value)
{
- //trigger_error('setting property Response::' . $name . ' is deprecated', E_USER_DEPRECATED);
-
switch ($name) {
case 'hdrs':
+ $this->logDeprecation('Setting property Response::' . $name . ' is deprecated');
$this->httpResponse['headers'] = $value;
break;
case '_cookies':
+ $this->logDeprecation('Setting property Response::' . $name . ' is deprecated');
$this->httpResponse['cookies'] = $value;
break;
case 'raw_data':
+ $this->logDeprecation('Setting property Response::' . $name . ' is deprecated');
$this->httpResponse['raw_data'] = $value;
break;
default:
+ /// @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);
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
}
public function __isset($name)
{
- //trigger_error('checking property Response::' . $name . ' is deprecated', E_USER_DEPRECATED);
-
switch ($name) {
case 'hdrs':
+ $this->logDeprecation('Checking property Response::' . $name . ' is deprecated');
return isset($this->httpResponse['headers']);
case '_cookies':
+ $this->logDeprecation('Checking property Response::' . $name . ' is deprecated');
return isset($this->httpResponse['cookies']);
case 'raw_data':
+ $this->logDeprecation('Checking property Response::' . $name . ' is deprecated');
return isset($this->httpResponse['raw_data']);
default:
return false;
{
switch ($name) {
case 'hdrs':
+ $this->logDeprecation('Unsetting property Response::' . $name . ' is deprecated');
unset($this->httpResponse['headers']);
break;
case '_cookies':
+ $this->logDeprecation('Unsetting property Response::' . $name . ' is deprecated');
unset($this->httpResponse['cookies']);
break;
case 'raw_data':
+ $this->logDeprecation('Unsetting property Response::' . $name . ' is deprecated');
unset($this->httpResponse['raw_data']);
break;
default:
+ /// @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);
trigger_error('Undefined property via __unset(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
}
use PhpXmlRpc\Helper\Logger;
use PhpXmlRpc\Helper\XMLParser;
use PhpXmlRpc\Traits\CharsetEncoderAware;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
use PhpXmlRpc\Traits\ParserAware;
/**
class Server
{
use CharsetEncoderAware;
- use LoggerAware;
+ use DeprecationLogger;
use ParserAware;
const OPT_ACCEPTED_COMPRESSION = 'accepted_compression';
--- /dev/null
+<?php
+
+namespace PhpXmlRpc\Traits;
+
+use PhpXmlRpc\PhpXmlRpc;
+
+trait DeprecationLogger
+{
+ use LoggerAware;
+
+ protected function logDeprecation($message)
+ {
+ if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
+ return;
+ }
+
+ $this->getLogger()->warning('XML-RPC Deprecated: ' . $message);
+ }
+}
use PhpXmlRpc\Exception\TypeErrorException;
use PhpXmlRpc\Exception\ValueErrorException;
use PhpXmlRpc\Traits\CharsetEncoderAware;
-use PhpXmlRpc\Traits\LoggerAware;
+use PhpXmlRpc\Traits\DeprecationLogger;
/**
* 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;
+ use DeprecationLogger;
public static $xmlrpcI4 = "i4";
public static $xmlrpcI8 = "i8";
*/
public function structMemExists($key)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return array_key_exists($key, $this->me['struct']);
}
*/
public function structMem($key)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return $this->me['struct'][$key];
}
*/
public function structReset()
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
reset($this->me['struct']);
}
*/
public function structEach()
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return @each($this->me['struct']);
}
*/
public function arrayMem($key)
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return $this->me['array'][$key];
}
*/
public function arraySize()
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return count($this->me['array']);
}
*/
public function structSize()
{
- //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
+ $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
return count($this->me['struct']);
}