X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FWrapper.php;h=5bb956dd166dbc32fcde861bb1c9085cf4a313c1;hb=50ea70e5e917da063be3918971c0b423e48a0489;hp=cdfb41f7f6931140b887082b267f6a1d760c7388;hpb=3cc4f1933ac0c298f99cb73eae19ba698d06f838;p=plcapi.git diff --git a/src/Wrapper.php b/src/Wrapper.php index cdfb41f..5bb956d 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -1,7 +1,7 @@ errorLog('XML-RPC: ' . __METHOD__ . ': syntax for function to be wrapped is wrong'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': syntax for function to be wrapped is wrong'); return false; } if (is_string($callable[0])) { @@ -172,7 +195,7 @@ class Wrapper } else if ($callable instanceof \Closure) { // we do not support creating code which wraps closures, as php does not allow to serialize them if (!$buildIt) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': a closure can not be wrapped in generated source code'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': a closure can not be wrapped in generated source code'); return false; } @@ -184,7 +207,7 @@ class Wrapper } if (!$exists) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is not defined: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is not defined: ' . $plainFuncName); return false; } @@ -228,23 +251,23 @@ class Wrapper if (is_array($callable)) { $func = new \ReflectionMethod($callable[0], $callable[1]); if ($func->isPrivate()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is private: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is private: ' . $plainFuncName); return false; } if ($func->isProtected()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is protected: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is protected: ' . $plainFuncName); return false; } if ($func->isConstructor()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the constructor: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the constructor: ' . $plainFuncName); return false; } if ($func->isDestructor()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the destructor: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the destructor: ' . $plainFuncName); return false; } if ($func->isAbstract()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is abstract: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is abstract: ' . $plainFuncName); return false; } /// @todo add more checks for static vs. nonstatic? @@ -254,7 +277,7 @@ class Wrapper if ($func->isInternal()) { // Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs // instead of getparameters to fully reflect internal php functions ? - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is internal: ' . $plainFuncName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is internal: ' . $plainFuncName); return false; } @@ -558,7 +581,7 @@ class Wrapper } // since we are building source code for later use, if we are given an object instance, - // we go out of our way and store a pointer to it in a static class var var... + // we go out of our way and store a pointer to it in a static class var... if (is_array($callable) && is_object($callable[0])) { self::$objHolder[$newFuncName] = $callable[0]; $innerCode .= "\$obj = PhpXmlRpc\\Wrapper::\$objHolder['$newFuncName'];\n"; @@ -678,7 +701,7 @@ class Wrapper * - bool debug set it to 1 or 2 to see debug results of querying server for method synopsis * - int simple_client_copy set it to 1 to have a lightweight copy of the $client object made in the generated code (only used when return_source = true) * - * @return \closure|array|false false on failure, closure by default and array for return_source = true + * @return \closure|string[]|false false on failure, closure by default and array for return_source = true */ public function wrapXmlrpcMethod($client, $methodName, $extraOptions = array()) { @@ -710,7 +733,6 @@ class Wrapper return $results; } - } /** @@ -737,7 +759,7 @@ class Wrapper $client->setDebug($debug); $response = $client->send($req, $timeout, $protocol); if ($response->faultCode()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature from remote server for method ' . $methodName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature from remote server for method ' . $methodName); return false; } @@ -748,7 +770,7 @@ class Wrapper } if (!is_array($mSig) || count($mSig) <= $sigNum) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature nr.' . $sigNum . ' from remote server for method ' . $methodName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature nr.' . $sigNum . ' from remote server for method ' . $methodName); return false; } @@ -885,7 +907,7 @@ class Wrapper * @param string $newFuncName * @param array $mSig * @param string $mDesc - * @return array + * @return string[] keys: source, docstring */ public function buildWrapMethodSource($client, $methodName, array $extraOptions, $newFuncName, $mSig, $mDesc='') { @@ -953,7 +975,7 @@ class Wrapper $mDesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n"; } $plist = implode(', ', $plist); - $mDesc .= '* @return ' . $this->xmlrpc2PhpType($mSig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n"; + $mDesc .= '* @return {$namespace}Response|' . $this->xmlrpc2PhpType($mSig[0]) . " (an {$namespace}Response obj instance if call fails)\n*/\n"; $innerCode .= "\$res = \${$this_}client->send(\$req, $timeout, '$protocol');\n"; if ($decodeFault) { @@ -1013,7 +1035,7 @@ class Wrapper $req = new $reqClass('system.listMethods'); $response = $client->send($req, $timeout, $protocol); if ($response->faultCode()) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method list from remote server'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method list from remote server'); return false; } else { @@ -1023,7 +1045,7 @@ class Wrapper $mList = $decoder->decode($mList); } if (!is_array($mList) || !count($mList)) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve meaningful method list from remote server'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve meaningful method list from remote server'); return false; } else { @@ -1065,7 +1087,7 @@ class Wrapper } $source .= $methodWrap['source'] . "\n"; } else { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': will not create class method to wrap remote method ' . $mName); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': will not create class method to wrap remote method ' . $mName); } } } @@ -1076,7 +1098,7 @@ class Wrapper if ($allOK) { return $xmlrpcClassName; } else { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': could not create class ' . $xmlrpcClassName . ' to wrap remote server ' . $client->server); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not create class ' . $xmlrpcClassName . ' to wrap remote server ' . $client->server); return false; } } else { @@ -1106,7 +1128,12 @@ class Wrapper // (this provides for future expansion or subclassing of client obj) if ($verbatimClientCopy) { foreach ($client as $fld => $val) { - if ($fld != 'debug' && $fld != 'return_type') { + /// @todo in php 8.0, curl handles became objects, but they have no __set_state, thus var_export will + /// fail for xmlrpc_curl_handle. So we disabled copying it. + /// We should examine in depth if this change can have side effects - at first sight if the + /// client's curl handle is not set, all curl options are (re)set on each http call, so there + /// should be no loss of state... + if ($fld != 'debug' && $fld != 'return_type' && $fld != 'xmlrpc_curl_handle') { $val = var_export($val, true); $code .= "\$client->$fld = $val;\n"; }