From: gggeek Date: Mon, 30 Jan 2023 16:11:39 +0000 (+0000) Subject: move all methods to camelCase X-Git-Tag: 4.10.0~63 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=30163ef768cf7615df78731fdf260e6319215def;p=plcapi.git move all methods to camelCase --- diff --git a/NEWS.md b/NEWS.md index ebcfc695..c05a6645 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,8 +2,10 @@ * changed: the minimum php version required has increased to 5.4 +* changed: dropped support for parsing cookie headers which follow the obsolete "version 2" specification + * new: allow to specify other charsets than the canonical three (UTF-8, ISO-8859-1, ASCII), when mbstring is - available, both for outgoing and incoming data. + available, both for outgoing and incoming data (issue #42). For outgoing data, this can be set in `$client->request_charset_encoding` and `$server->response_charset_encoding`. The library will then transcode the data fed to it by the application into the desired charset when serializing @@ -42,14 +44,12 @@ on to the application. The same will apply for elements of type struct-member which miss either the name or the value * new: it is now possible to tell the library to allow non-standard formats for received datetime value, such as f.e. - datetimes with a timezone specifier, by setting a custom value to `PhpXmlRpc\PhpXmlRpc::$xmlrpc_datetime_format`. + datetimes with a timezone specifier, by setting a custom value to `PhpXmlRpc\PhpXmlRpc::$xmlrpc_datetime_format` + (issue #46). * new: it is now possible to tell the library to allow non-standard formats for received int and float values, as well as for methdoname elements. See the api docs for `PhpXmlRpc\PhpXmlRpc` static variables. -* improved: limit the size of incoming data which will be used in error responses and logged error messages, making - it slightly harder to carry out DOS attacks against the library - * fixed: when a server is configured with its default value of 'xmlrpcvals' for `$functions_parameters_type`, and a method handler in the dispatch was defined with `'parameters_type' = 'phpvals'`, the handler would be passed a Request object instead of plain php values. @@ -76,10 +76,17 @@ * new: method `Server::setDispatchMap()` * new: it is now possible to inject a custom logger into helper classes `Charset`, `Http`, `XMLParser`, inching a step - closer to supporting DIC patterns + closer to supporting DIC patterns (issue #78) * new: method `PhpXmlRpc::setLogger()`, to simplify injecting the logger into all classes of the library in one step +* improved: the `Logger` class now sports methods adhering to Psr\Log\LoggerInterface + +* improved: made sure all debug output goes through the logger at response parsing time (there was one printf call left) + +* improved: limit the size of incoming data which will be used in error responses and logged error messages, making + it slightly harder to carry out DOS attacks against the library + * new: passing value -1 to `$client->setDebug` will avoid storing the full http response data in the returned Response object when executing `call`. This could be useful in reducing memory usage for big responses @@ -94,9 +101,7 @@ * new: methods `Wrapper::holdObject()` and `Wrapper::getheldObject()`, allowing flexibility in storing object instances for code-generation scenarios involving `Wrapper::wrapPhpClass` and `Wrapper::wrapPhpFunction` -* improved: the `Logger` class now sports methods adhering to Psr\Log\LoggerInterface - -* improved: made sure all debug output goes through the logger at response parsing time (there was one printf call left) +* improved: all `Value` methods now follow snakeCase convention * improved: all the Exceptions thrown by the library are now `\PhpXmlRpc\Exception` or subclasses thereof @@ -107,14 +112,12 @@ * new: method `Helper\Date::iso8601Encode` now accepts a DateTime input beside a timestamp -* new: in the dispatch map, it is now possible to set different exception handling modes for each expose xml-rpc method +* new: in the dispatch map, it is now possible to set different exception handling modes for each exposed xml-rpc method * new: method `Server::add_to_map` has acquired new parameters: `$parametersType = false, $exceptionHandling = false` * improved: the `XMLParser` accepts more options in its constructor (see phpdocs for details) -* improved: dropped support for parsing cookie headers which follow the obsolete "version 2" specification - * improved: removed usage of `extension_loaded` in favour of `function_exists` when checking for mbstring. This allows for mbstring functions to be polyfilled @@ -129,7 +132,7 @@ * improved: made sure the test container and gha test runners have at least one locale with comma as decimal separator -* BC notes: +* BC notes (besides what can be inferred from the changes listed above): for library users @@ -148,6 +151,8 @@ - an error message will now be generated if, in incoming data, a STRUCT element has no NAME - parameters `$timeout` and `$method` are now considered deprecated in `Client::send()` and `Client::multicall()` - Client properties `$errno` and `$errstring` are now deprecated + - direct access to all properties of Client and Server is now deprecated and should be replaced by calls to + `setOption` and `getOption`. The same applies to a few "setter" methods of the Client - direct access to `Wrapper::$objHolder` is now deprecated - the code generated by the debugger when using "Generate stub for method call" will throw on errors instead of returning a Response object diff --git a/src/Client.php b/src/Client.php index 532c5eef..2abad59b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -331,7 +331,7 @@ class Client /** * @param string $path either the PATH part of the xml-rpc server URL, or complete server URL (in which case you - * should use and empty string for all other parameters) + * should use an empty string for all other parameters) * e.g. /xmlrpc/server.php * e.g. http://phpxmlrpc.sourceforge.net/server.php * e.g. https://james:bond@secret.service.com:444/xmlrpcserver?agent=007 @@ -1130,17 +1130,13 @@ class Client { /// @todo log a warning if passed an unsupported method - if ($port == 0) { - $port = ($method === 'https') ? 443 : 80; - } - // Only create the payload if it was not created previously /// @todo what if the request's payload was created with a different encoding? if (empty($req->payload)) { $req->serialize($this->request_charset_encoding); } - $payload = $req->payload; + // Deflate request body and set appropriate request headers $encodingHdr = ''; if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate')) { @@ -1174,6 +1170,10 @@ class Client $acceptedEncoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n"; } + if ($port == 0) { + $port = ($method === 'https') ? 443 : 80; + } + $proxyCredentials = ''; if ($proxyHost) { if ($proxyPort == 0) { @@ -1836,19 +1836,19 @@ class Client } /** @var Value $code */ $code = $val['faultCode']; - if ($code->kindOf() != 'scalar' || $code->scalartyp() != 'int') { + if ($code->kindOf() != 'scalar' || $code->scalarTyp() != 'int') { return new Response(0, PhpXmlRpc::$xmlrpcerr['multicall_error'], PhpXmlRpc::$xmlrpcstr['multicall_error'] . ": response element $i has invalid or no faultCode", 'xmlrpcvals', $result->httpResponse()); } /** @var Value $str */ $str = $val['faultString']; - if ($str->kindOf() != 'scalar' || $str->scalartyp() != 'string') { + if ($str->kindOf() != 'scalar' || $str->scalarTyp() != 'string') { return new Response(0, PhpXmlRpc::$xmlrpcerr['multicall_error'], PhpXmlRpc::$xmlrpcstr['multicall_error'] . ": response element $i has invalid or no faultCode", 'xmlrpcvals', $result->httpResponse()); } - $response[] = new Response(0, $code->scalarval(), $str->scalarval(), 'xmlrpcvals', $result->httpResponse()); + $response[] = new Response(0, $code->scalarVal(), $str->scalarVal(), 'xmlrpcvals', $result->httpResponse()); break; default: return new Response(0, PhpXmlRpc::$xmlrpcerr['multicall_error'], diff --git a/src/Encoder.php b/src/Encoder.php index 2d593389..0491447d 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -84,10 +84,10 @@ class Encoder return $val; } } - if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') { + if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalarTyp() == 'dateTime.iso8601') { // we return a Datetime object instead of a string; since now the constructor of xml-rpc value accepts // safely string, int and DateTimeInterface, we cater to all 3 cases here - $out = $xmlrpcVal->scalarval(); + $out = $xmlrpcVal->scalarVal(); if (is_string($out)) { $out = strtotime($out); // NB: if the string does not convert into a timestamp, this will return false. @@ -103,7 +103,7 @@ class Encoder return $out; } } - return $xmlrpcVal->scalarval(); + return $xmlrpcVal->scalarVal(); case 'array': $arr = array(); @@ -348,7 +348,7 @@ class Encoder $vc = $v['faultCode']; /** @var Value $vs */ $vs = $v['faultString']; - $r = new Response(0, $vc->scalarval(), $vs->scalarval()); + $r = new Response(0, $vc->scalarVal(), $vs->scalarVal()); } else { $r = new Response($v); } @@ -369,9 +369,9 @@ class Encoder $v = $xmlRpcParser->_xh['value']; // use a known error code /** @var Value $vc */ - $vc = isset($v['faultCode']) ? $v['faultCode']->scalarval() : PhpXmlRpc::$xmlrpcerr['invalid_return']; + $vc = isset($v['faultCode']) ? $v['faultCode']->scalarVal() : PhpXmlRpc::$xmlrpcerr['invalid_return']; /** @var Value $vs */ - $vs = isset($v['faultString']) ? $v['faultString']->scalarval() : ''; + $vs = isset($v['faultString']) ? $v['faultString']->scalarVal() : ''; if (!is_int($vc) || $vc == 0) { $vc = PhpXmlRpc::$xmlrpcerr['invalid_return']; } diff --git a/src/Helper/XMLParser.php b/src/Helper/XMLParser.php index c7817d2b..839ffd28 100644 --- a/src/Helper/XMLParser.php +++ b/src/Helper/XMLParser.php @@ -606,7 +606,7 @@ class XMLParser case 'I8': case 'INT': // NB: we build the Value object with the original xml element name found, except for ex:i8. The - // `Value::scalartyp()` function will do some normalization of the data + // `Value::scalarTyp()` function will do some normalization of the data $this->_xh['vt'] = strtolower($name); $this->_xh['lv'] = 3; // indicate we've found a value if (!preg_match(PhpXmlRpc::$xmlrpc_int_format, $this->_xh['ac'])) { diff --git a/src/Request.php b/src/Request.php index 8a5fcaf0..4a68454c 100644 --- a/src/Request.php +++ b/src/Request.php @@ -360,8 +360,8 @@ class Request if ($returnType == XMLParser::RETURN_XMLRPCVALS) { $errNo_v = $v['faultCode']; $errStr_v = $v['faultString']; - $errNo = $errNo_v->scalarval(); - $errStr = $errStr_v->scalarval(); + $errNo = $errNo_v->scalarVal(); + $errStr = $errStr_v->scalarVal(); } else { $errNo = $v['faultCode']; $errStr = $v['faultString']; diff --git a/src/Server.php b/src/Server.php index db590bc5..2c9378ac 100644 --- a/src/Server.php +++ b/src/Server.php @@ -514,7 +514,7 @@ class Server if (is_object($in)) { $p = $in->getParam($n); if ($p->kindOf() == 'scalar') { - $pt = $p->scalartyp(); + $pt = $p->scalarTyp(); } else { $pt = $p->kindOf(); } @@ -1177,7 +1177,7 @@ class Server // let's accept as parameter either an xml-rpc value or string if (is_object($req)) { $methName = $req->getParam(0); - $methName = $methName->scalarval(); + $methName = $methName->scalarVal(); } else { $methName = $req; } @@ -1221,7 +1221,7 @@ class Server // let's accept as parameter either an xml-rpc value or string if (is_object($req)) { $methName = $req->getParam(0); - $methName = $methName->scalarval(); + $methName = $methName->scalarVal(); } else { $methName = $req; } @@ -1281,10 +1281,10 @@ class Server if (!$methName) { return static::_xmlrpcs_multicall_error('nomethod'); } - if ($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string') { + if ($methName->kindOf() != 'scalar' || $methName->scalarTyp() != 'string') { return static::_xmlrpcs_multicall_error('notstring'); } - if ($methName->scalarval() == 'system.multicall') { + if ($methName->scalarVal() == 'system.multicall') { return static::_xmlrpcs_multicall_error('recursion'); } @@ -1296,7 +1296,7 @@ class Server return static::_xmlrpcs_multicall_error('notarray'); } - $req = new Request($methName->scalarval()); + $req = new Request($methName->scalarVal()); foreach ($params as $i => $param) { if (!$req->addParam($param)) { $i++; // for error message, we count params from 1 diff --git a/src/Value.php b/src/Value.php index b56ea8c3..11167971 100644 --- a/src/Value.php +++ b/src/Value.php @@ -150,7 +150,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess return 0; case 2: // we're adding a scalar value to an array here -/// @todo do not re-wrap Value objects + /// @todo should we try avoiding re-wrapping Value objects? $class = get_class($this); $this->me['array'][] = new $class($val, $type); @@ -253,7 +253,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated this should be folded back into serialize() */ - protected function serializedata($typ, $val, $charsetEncoding = '') + protected function serializeData($typ, $val, $charsetEncoding = '') { $rs = ''; @@ -358,7 +358,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess $val = reset($this->me); $typ = key($this->me); - return '' . $this->serializedata($typ, $val, $charsetEncoding) . "\n"; + return '' . $this->serializeData($typ, $val, $charsetEncoding) . "\n"; } /** @@ -371,7 +371,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated use array access, e.g. isset($val[$key]) */ - public function structmemexists($key) + public function structMemExists($key) { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -387,7 +387,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated use array access, e.g. $val[$key] */ - public function structmem($key) + public function structMem($key) { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -400,7 +400,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated iterate directly over the object using foreach instead */ - public function structreset() + public function structReset() { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -415,7 +415,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated iterate directly over the object using foreach instead */ - public function structeach() + public function structEach() { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -427,7 +427,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @return mixed */ - public function scalarval() + public function scalarVal() { $b = reset($this->me); @@ -440,7 +440,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * @return string For integers, 'int' is always returned in place of 'i4'. 'i8' is considered a separate type and * returned as such */ - public function scalartyp() + public function scalarTyp() { reset($this->me); $a = key($this->me); @@ -460,7 +460,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated use array access, e.g. $val[$key] */ - public function arraymem($key) + public function arrayMem($key) { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -474,7 +474,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated use count() instead */ - public function arraysize() + public function arraySize() { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -488,7 +488,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * @deprecated use count() instead */ - public function structsize() + public function structSize() { //trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED); @@ -576,7 +576,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess return; case 1: /// @todo: should we handle usage of i4 to retrieve int (in both set/unset/isset)? After all we consider - /// 'int' to be the preferred form, as evidenced in scalartyp() + /// 'int' to be the preferred form, as evidenced in scalarTyp() reset($this->me); $type = key($this->me); if ($type != $offset && ($type != 'i4' || $offset != 'int')) { @@ -611,7 +611,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess reset($this->me); return $offset == key($this->me); } else { - return $offset == $this->scalartyp(); + return $offset == $this->scalarTyp(); } default: return false; diff --git a/src/Wrapper.php b/src/Wrapper.php index c80490a8..b1013c2e 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -822,7 +822,7 @@ class Wrapper if (!$response->faultCode()) { $mDesc = $response->value(); if ($client->return_type != 'phpvals') { - $mDesc = $mDesc->scalarval(); + $mDesc = $mDesc->scalarVal(); } }