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