From ca95a4f7001b64a5ec78ce6dbaa13dbb34418721 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 8 Feb 2023 11:35:10 +0000 Subject: [PATCH] make 2 protected properties deprecated --- NEWS.md | 1 + doc/api_changes_v4.10.md | 8 ++++- src/Request.php | 66 ++++++++++++++++++++++++++++++++++++-- src/Server.php | 68 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 137 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1f8286ce..e0ba37dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -200,6 +200,7 @@ is now static - new methods in helper classes: `Charset::knownCharsets`, `Http::parseAcceptHeader`, `XMLParser::truncateValueForLog` - new method `Response::xml_header` has replaced `Server::xml_header` + - protected property `Server::$accepted_charset_encodings` is now deprecated - exception `\PhpXmlRpc\Exception\PhpXmlRpcException` is deprecated. Use `\PhpXmlRpc\Exception` instead diff --git a/doc/api_changes_v4.10.md b/doc/api_changes_v4.10.md index 0a4d969f..2a586ddf 100644 --- a/doc/api_changes_v4.10.md +++ b/doc/api_changes_v4.10.md @@ -207,7 +207,6 @@ The following properties have now protected access. Replacement accessor for pub | Response | errstr | faultString | __construct | | Response | content_type | getContentType | setPayload | | Response | payload | getPayload | setPayload | -| Server | accepted_charset_encodings | - | - | | Server | accepted_compression | getOption | setOption | | Server | allow_system_funcs | getOption | setOption | | Server | compress_response | getOption | setOption | @@ -221,3 +220,10 @@ The following properties have now protected access. Replacement accessor for pub | Value | mytype | kindOf | __construct | | Wrapper | $objectholder | getHeldObject | holdObject | | XMLParser | $_xh | results of parse() | - | + +The following previously protected properties are now deprecated for access by subclasses + +| Class | Property | Read via | Write via | +|-----------|----------------------------|------------------------|----------------------------------| +| Request | httpResponse | - | - | +| Server | accepted_charset_encodings | - | - | diff --git a/src/Request.php b/src/Request.php index ace63df4..86560ed6 100644 --- a/src/Request.php +++ b/src/Request.php @@ -38,9 +38,9 @@ class Request /** * holds data while parsing the response. NB: Not a full Response object - * @deprecated will be removed in a future release + * @deprecated will be removed in a future release; still accessible by subclasses for the moment */ - protected $httpResponse = array(); + private $httpResponse = array(); /** * @param string $methodName the name of the method to invoke @@ -437,6 +437,22 @@ class Request case 'content_type': $this->logDeprecation('Getting property Request::' . $name . ' is deprecated'); return $this->$name; + case 'httpResponse': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Request')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Getting property Request::' . $name . ' is deprecated'); + return $this->httpResponse; + } else { + trigger_error("Cannot access protected property Request::httpResponse in " . __FILE__, E_USER_ERROR); + } + 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, 1); @@ -457,6 +473,22 @@ class Request $this->logDeprecation('Setting property Request::' . $name . ' is deprecated'); $this->$name = $value; break; + case 'httpResponse': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Request')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Setting property Request::' . $name . ' is deprecated'); + $this->httpResponse = $value; + } else { + trigger_error("Cannot access protected property Request::httpResponse in " . __FILE__, E_USER_ERROR); + } + 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, 1); @@ -474,6 +506,20 @@ class Request case 'content_type': $this->logDeprecation('Checking property Request::' . $name . ' is deprecated'); return isset($this->$name); + case 'httpResponse': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Request')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Checking property Request::' . $name . ' is deprecated'); + return isset($this->httpResponse); + } + // break through voluntarily default: return false; } @@ -490,6 +536,22 @@ class Request $this->logDeprecation('Unsetting property Request::' . $name . ' is deprecated'); unset($this->$name); break; + case 'httpResponse': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Request')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Unsetting property Request::' . $name . ' is deprecated'); + unset($this->httpResponse); + } else { + trigger_error("Cannot access protected property Request::httpResponse in " . __FILE__, E_USER_ERROR); + } + 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, 1); diff --git a/src/Server.php b/src/Server.php index d9c91fbf..87eb575f 100644 --- a/src/Server.php +++ b/src/Server.php @@ -103,9 +103,9 @@ class Server /** * List of charset encodings natively accepted for requests. * Set at constructor time. - * @deprecated UNUSED so far... + * @deprecated UNUSED so far by this library. It is still accessible by subclasses but will be dropped in the future. */ - protected $accepted_charset_encodings = array(); + private $accepted_charset_encodings = array(); /** * @var string @@ -463,7 +463,7 @@ class Server public function addToMap($methodName, $function, $sig = null, $doc = false, $sigDoc = false, $parametersType = false, $exceptionHandling = false) { - return $this->addToMap($methodName, $function, $sig, $doc, $sigDoc, $parametersType, $exceptionHandling); + $this->add_to_map($methodName, $function, $sig, $doc, $sigDoc, $parametersType, $exceptionHandling); } /** @@ -1474,6 +1474,22 @@ class Server case self::OPT_RESPONSE_CHARSET_ENCODING: $this->logDeprecation('Getting property Request::' . $name . ' is deprecated'); return $this->$name; + case 'accepted_charset_encodings': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Server')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Getting property Request::' . $name . ' is deprecated'); + return $this->accepted_compression; + } else { + trigger_error("Cannot access protected property Server::accepted_charset_encodings in " . __FILE__, E_USER_ERROR); + } + 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, 1); @@ -1497,6 +1513,22 @@ class Server $this->logDeprecation('Setting property Request::' . $name . ' is deprecated'); $this->$name = $value; break; + case 'accepted_charset_encodings': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Server')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Setting property Request::' . $name . ' is deprecated'); + $this->accepted_compression = $value; + } else { + trigger_error("Cannot access protected property Server::accepted_charset_encodings in " . __FILE__, E_USER_ERROR); + } + 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, 1); @@ -1517,6 +1549,20 @@ class Server case self::OPT_RESPONSE_CHARSET_ENCODING: $this->logDeprecation('Checking property Request::' . $name . ' is deprecated'); return isset($this->$name); + case 'accepted_charset_encodings': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Server')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Checking property Request::' . $name . ' is deprecated'); + return isset($this->accepted_compression); + } + // break through voluntarily default: return false; } @@ -1536,6 +1582,22 @@ class Server $this->logDeprecation('Unsetting property Request::' . $name . ' is deprecated'); unset($this->$name); break; + case 'accepted_charset_encodings': + // manually implement the 'protected property' behaviour + $canAccess = false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[1]) && isset($trace[1]['class'])) { + if (is_subclass_of($trace[1]['class'], 'PhpXmlRpc\Server')) { + $canAccess = true; + } + } + if ($canAccess) { + $this->logDeprecation('Unsetting property Request::' . $name . ' is deprecated'); + unset($this->accepted_compression); + } else { + trigger_error("Cannot access protected property Server::accepted_charset_encodings in " . __FILE__, E_USER_ERROR); + } + 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, 1); -- 2.47.0