make 2 protected properties deprecated
authorgggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 11:35:10 +0000 (11:35 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 11:35:10 +0000 (11:35 +0000)
NEWS.md
doc/api_changes_v4.10.md
src/Request.php
src/Server.php

diff --git a/NEWS.md b/NEWS.md
index 1f8286c..e0ba37d 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
     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
 
 
index 0a4d969..2a586dd 100644 (file)
@@ -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 | -                      | -                                |
index ace63df..86560ed 100644 (file)
@@ -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);
index d9c91fb..87eb575 100644 (file)
@@ -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);