Fix constructors to be compliant with php 7
authorgggeek <giunta.gaetano@gmail.com>
Fri, 30 Jun 2017 22:49:59 +0000 (23:49 +0100)
committergggeek <giunta.gaetano@gmail.com>
Fri, 30 Jun 2017 22:49:59 +0000 (23:49 +0100)
lib/xmlrpc.inc
lib/xmlrpc_wrappers.inc
lib/xmlrpcs.inc

index dc2fa61..41dae8b 100644 (file)
                */\r
                var $user_agent;\r
 \r
+               /**\r
+               * @deprecated\r
+               */\r
+               function xmlrpc_client($path, $server='', $port='', $method='')\r
+               {\r
+                       self::__construct($path, $server, $port, $method);\r
+               }\r
+\r
                /**\r
                * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php\r
                * @param string $server the server name / ip address\r
                * @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used\r
                * @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed\r
                */\r
-               function xmlrpc_client($path, $server='', $port='', $method='')\r
+               function __construct($path, $server='', $port='', $method='')\r
                {\r
                        // allow user to specify all params in $path\r
                        if($server == '' and $port == '' and $method == '')\r
                var $content_type = 'text/xml';\r
                var $raw_data = '';\r
 \r
+               /**\r
+               * @deprecated\r
+               */\r
+               function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')\r
+               {\r
+                       self::__construct($val, $fcode, $fstr, $valtyp);\r
+               }\r
+\r
                /**\r
                * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)\r
                * @param integer $fcode set it to anything but 0 to create an error response\r
                * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain\r
                * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...\r
                */\r
-               function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')\r
+               function __construct($val, $fcode = 0, $fstr = '', $valtyp='')\r
                {\r
                        if($fcode != 0)\r
                        {\r
@@ -2119,11 +2135,19 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                var $debug=0;\r
                var $content_type = 'text/xml';\r
 \r
+               /**\r
+               * @deprecated\r
+               */\r
+               function xmlrpcmsg($meth, $pars=0)\r
+               {\r
+                       self::__construct($meth, $pars);\r
+               }\r
+\r
                /**\r
                * @param string $meth the name of the method to invoke\r
                * @param array $pars array of parameters to be passed to the method (xmlrpcval objects)\r
                */\r
-               function xmlrpcmsg($meth, $pars=0)\r
+               function __construct($meth, $pars=0)\r
                {\r
                        $this->methodname=$meth;\r
                        if(is_array($pars) && count($pars)>0)\r
@@ -2415,7 +2439,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                                                        {\r
                                                                                if ($tag != 'value')\r
                                                                                {\r
-                                                                                 $GLOBALS['_xh']['cookies'][$cookiename][$tag] = $val;\r
+                                                                                       $GLOBALS['_xh']['cookies'][$cookiename][$tag] = $val;\r
                                                                                }\r
                                                                        }\r
                                                                }\r
@@ -2751,11 +2775,19 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                var $mytype=0;\r
                var $_php_class=null;\r
 \r
+               /**\r
+               * @deprecated\r
+               */\r
+               function xmlrpcval($val=-1, $type='')\r
+               {\r
+                       self::__construct($val, $type);\r
+               }\r
+\r
                /**\r
                * @param mixed $val\r
                * @param string $type any valid xmlrpc type name (lowercase). If null, 'string' is assumed\r
                */\r
-               function xmlrpcval($val=-1, $type='')\r
+               function __construct($val=-1, $type='')\r
                {\r
                        /// @todo: optimization creep - do not call addXX, do it all inline.\r
                        /// downside: booleans will not be coerced anymore\r
@@ -3594,7 +3626,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        }\r
                }\r
 \r
-        $parser = xml_parser_create();\r
+               $parser = xml_parser_create();\r
                xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
                // What if internal encoding is not in one of the 3 allowed?\r
                // we use the broadest one, ie. utf8!\r
@@ -3831,7 +3863,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 \r
                // test if encoding is specified in the xml declaration\r
                // Details:\r
-               // SPACE:                (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+\r
+               // SPACE:               (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+\r
                // EQ:                  SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*\r
                if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .\r
                        '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",\r
index b2c6611..9d901a4 100644 (file)
                $catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';\r
 \r
                $exists = false;\r
-           if (is_string($funcname) && strpos($funcname, '::') !== false)\r
-           {\r
-               $funcname = explode('::', $funcname);\r
-           }\r
-        if(is_array($funcname))\r
-        {\r
-            if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))\r
-            {\r
-                       error_log('XML-RPC: syntax for function to be wrapped is wrong');\r
-                       return false;\r
-            }\r
-            if(is_string($funcname[0]))\r
-            {\r
-                $plainfuncname = implode('::', $funcname);\r
-            }\r
-            elseif(is_object($funcname[0]))\r
-            {\r
-                $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];\r
-            }\r
-            $exists = method_exists($funcname[0], $funcname[1]);\r
-        }\r
-        else\r
-        {\r
-            $plainfuncname = $funcname;\r
-            $exists = function_exists($funcname);\r
-        }\r
+               if (is_string($funcname) && strpos($funcname, '::') !== false)\r
+               {\r
+                       $funcname = explode('::', $funcname);\r
+               }\r
+               if(is_array($funcname))\r
+               {\r
+                       if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))\r
+                       {\r
+                               error_log('XML-RPC: syntax for function to be wrapped is wrong');\r
+                               return false;\r
+                       }\r
+                       if(is_string($funcname[0]))\r
+                       {\r
+                               $plainfuncname = implode('::', $funcname);\r
+                       }\r
+                       elseif(is_object($funcname[0]))\r
+                       {\r
+                               $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];\r
+                       }\r
+                       $exists = method_exists($funcname[0], $funcname[1]);\r
+               }\r
+               else\r
+               {\r
+                       $plainfuncname = $funcname;\r
+                       $exists = function_exists($funcname);\r
+               }\r
 \r
                if(!$exists)\r
                {\r
                        {\r
                                if(is_array($funcname))\r
                                {\r
-                               if(is_string($funcname[0]))\r
-                                       $xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);\r
-                               else\r
-                                       $xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];\r
+                                       if(is_string($funcname[0]))\r
+                                               $xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);\r
+                                       else\r
+                                               $xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];\r
                                }\r
                                else\r
                                {\r
                        // start to introspect PHP code\r
                        if(is_array($funcname))\r
                        {\r
-                       $func = new ReflectionMethod($funcname[0], $funcname[1]);\r
-                       if($func->isPrivate())\r
-                       {\r
-                               error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);\r
-                               return false;\r
-                       }\r
-                       if($func->isProtected())\r
-                       {\r
-                               error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);\r
-                               return false;\r
-                       }\r
-                       if($func->isConstructor())\r
-                       {\r
-                               error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);\r
-                               return false;\r
-                       }\r
-                if($func->isDestructor())\r
-                       {\r
-                               error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);\r
-                               return false;\r
-                       }\r
-                       if($func->isAbstract())\r
-                       {\r
-                               error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);\r
-                               return false;\r
-                       }\r
-                /// @todo add more checks for static vs. nonstatic?\r
-            }\r
+                               $func = new ReflectionMethod($funcname[0], $funcname[1]);\r
+                               if($func->isPrivate())\r
+                               {\r
+                                       error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);\r
+                                       return false;\r
+                               }\r
+                               if($func->isProtected())\r
+                               {\r
+                                       error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);\r
+                                       return false;\r
+                               }\r
+                               if($func->isConstructor())\r
+                               {\r
+                                       error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);\r
+                                       return false;\r
+                               }\r
+                               if($func->isDestructor())\r
+                               {\r
+                                       error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);\r
+                                       return false;\r
+                               }\r
+                               if($func->isAbstract())\r
+                               {\r
+                                       error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);\r
+                                       return false;\r
+                               }\r
+                               /// @todo add more checks for static vs. nonstatic?\r
+                       }\r
                        else\r
                        {\r
-                       $func = new ReflectionFunction($funcname);\r
-            }\r
+                               $func = new ReflectionFunction($funcname);\r
+                       }\r
                        if($func->isInternal())\r
                        {\r
                                // Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs\r
 \r
                        $innercode .= "\$np = false;\n";\r
                        // since there are no closures in php, if we are given an object instance,\r
-            // we store a pointer to it in a global var...\r
+                       // we store a pointer to it in a global var...\r
                        if ( is_array($funcname) && is_object($funcname[0]) )\r
                        {\r
-                           $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];\r
-                           $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";\r
-                           $realfuncname = '$obj->'.$funcname[1];\r
+                               $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];\r
+                               $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";\r
+                               $realfuncname = '$obj->'.$funcname[1];\r
                        }\r
                        else\r
                        {\r
-                       $realfuncname = $plainfuncname;\r
-            }\r
+                               $realfuncname = $plainfuncname;\r
+                       }\r
                        foreach($parsvariations as $pars)\r
                        {\r
                                $innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";\r
                }\r
        }\r
 \r
-    /**\r
-    * Given a user-defined PHP class or php object, map its methods onto a list of\r
+       /**\r
+       * Given a user-defined PHP class or php object, map its methods onto a list of\r
        * PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server\r
        * object and called from remote clients (as well as their corresponding signature info).\r
        *\r
-    * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class\r
-    * @param array $extra_options see the docs for wrap_php_method for more options\r
-    *        string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance\r
-    * @return array or false on failure\r
-    *\r
-    * @todo get_class_methods will return both static and non-static methods.\r
-    *       we have to differentiate the action, depending on wheter we recived a class name or object\r
-    */\r
-    function wrap_php_class($classname, $extra_options=array())\r
-    {\r
+       * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class\r
+       * @param array $extra_options see the docs for wrap_php_method for more options\r
+       *        string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance\r
+       * @return array or false on failure\r
+       *\r
+       * @todo get_class_methods will return both static and non-static methods.\r
+       *       we have to differentiate the action, depending on whether we received a class name or object\r
+       */\r
+       function wrap_php_class($classname, $extra_options=array())\r
+       {\r
                $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';\r
                $methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';\r
 \r
-        $result = array();\r
+               $result = array();\r
                $mlist = get_class_methods($classname);\r
                foreach($mlist as $mname)\r
                {\r
-               if ($methodfilter == '' || preg_match($methodfilter, $mname))\r
-                       {\r
-                       // echo $mlist."\n";\r
-                       $func = new ReflectionMethod($classname, $mname);\r
-                       if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())\r
-                       {\r
-                               if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||\r
-                               (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))\r
-                       {\r
-                        $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);\r
-                        if ( $methodwrap )\r
-                        {\r
-                            $result[$methodwrap['function']] = $methodwrap['function'];\r
-                        }\r
-                    }\r
-                       }\r
+                       if ($methodfilter == '' || preg_match($methodfilter, $mname))\r
+                       {\r
+                               // echo $mlist."\n";\r
+                               $func = new ReflectionMethod($classname, $mname);\r
+                               if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())\r
+                               {\r
+                                       if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||\r
+                                               (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))\r
+                                       {\r
+                                               $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);\r
+                                               if ( $methodwrap )\r
+                                               {\r
+                                                       $result[$methodwrap['function']] = $methodwrap['function'];\r
+                                               }\r
+                                       }\r
+                               }\r
                        }\r
                }\r
-        return $result;\r
-    }\r
+               return $result;\r
+       }\r
 \r
        /**\r
        * Given an xmlrpc client and a method name, register a php wrapper function\r
index 6dd64a5..0ab6d54 100644 (file)
                */\r
                var $user_data = null;\r
 \r
+               /**\r
+               * @deprecated\r
+               */\r
+               function xmlrpc_client($dispMap=null, $serviceNow=true)\r
+               {\r
+                       self::__construct($dispMap, $serviceNow);\r
+               }\r
+\r
                /**\r
                * @param array $dispmap the dispatch map with definition of exposed services\r
                * @param boolean $servicenow set to false to prevent the server from running upon construction\r
                */\r
-               function xmlrpc_server($dispMap=null, $serviceNow=true)\r
+               function __construct($dispMap=null, $serviceNow=true)\r
                {\r
                        // if ZLIB is enabled, let the server by default accept compressed requests,\r
                        // and compress responses sent to clients that support them\r
                        if ($data === null)\r
                        {\r
                                // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA\r
-                $data = file_get_contents('php://input');\r
+                               $data = file_get_contents('php://input');\r
                        }\r
                        $raw_data = $data;\r
 \r
 \r
                        if ($req_encoding != '')\r
                        {\r
-                // Since parsing will fail if charset is not specified in the xml prologue,\r
-                // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...\r
-                // The following code might be better for mb_string enabled installs, but\r
-                // makes the lib about 200% slower...\r
-                //if (!is_valid_charset($req_encoding, array('UTF-8')))\r
-                if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {\r
-                    if ($req_encoding == 'ISO-8859-1') {\r
-                        $data = utf8_encode($data);\r
-                    } else {\r
-                        if (extension_loaded('mbstring')) {\r
-                            $data = mb_convert_encoding($data, 'UTF-8', $req_encoding);\r
-                        } else {\r
-                            error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);\r
-                        }\r
-                    }\r
-                }\r
+                               // Since parsing will fail if charset is not specified in the xml prologue,\r
+                               // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...\r
+                               // The following code might be better for mb_string enabled installs, but\r
+                               // makes the lib about 200% slower...\r
+                               //if (!is_valid_charset($req_encoding, array('UTF-8')))\r
+                               if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {\r
+                                       if ($req_encoding == 'ISO-8859-1') {\r
+                                               $data = utf8_encode($data);\r
+                                       } else {\r
+                                               if (extension_loaded('mbstring')) {\r
+                                                       $data = mb_convert_encoding($data, 'UTF-8', $req_encoding);\r
+                                               } else {\r
+                                                       error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);\r
+                                               }\r
+                                       }\r
+                               }\r
                        }\r
 \r
                        $parser = xml_parser_create();\r