X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FWrapper.php;h=15f84ced82b59eafd070702c03a53774ee0be1b7;hb=b337d292eb5b5656d27a2fc9ab6796be300c59a3;hp=8ea8f2de42353702ca01c604943bcc0df2662e3a;hpb=9d4cfc9508b03a579dd62a28c0e9e428b5052f9b;p=plcapi.git diff --git a/src/Wrapper.php b/src/Wrapper.php index 8ea8f2d..15f84ce 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -1,12 +1,14 @@ getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': syntax for function to be wrapped is wrong'); return false; } if (is_string($callable[0])) { @@ -168,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) { - error_log('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; } @@ -180,7 +207,7 @@ class Wrapper } if (!$exists) { - error_log('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; } @@ -224,23 +251,23 @@ class Wrapper if (is_array($callable)) { $func = new \ReflectionMethod($callable[0], $callable[1]); if ($func->isPrivate()) { - error_log('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()) { - error_log('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()) { - error_log('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()) { - error_log('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()) { - error_log('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? @@ -250,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 ? - error_log('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; } @@ -394,11 +421,15 @@ class Wrapper * @param $callable * @param array $extraOptions * @param string $plainFuncName - * @param string $funcDesc + * @param array $funcDesc * @return \Closure */ protected function buildWrapFunctionClosure($callable, $extraOptions, $plainFuncName, $funcDesc) { + /** + * @param Request $req + * @return mixed + */ $function = function($req) use($callable, $extraOptions, $funcDesc) { $nameSpace = '\\PhpXmlRpc\\'; @@ -670,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()) { @@ -729,7 +760,7 @@ class Wrapper $client->setDebug($debug); $response = $client->send($req, $timeout, $protocol); if ($response->faultCode()) { - error_log('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; } @@ -740,7 +771,7 @@ class Wrapper } if (!is_array($mSig) || count($mSig) <= $sigNum) { - error_log('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; } @@ -783,7 +814,7 @@ class Wrapper * @param Client $client * @param string $methodName * @param array $extraOptions - * @param string $mSig + * @param array $mSig * @return \Closure * * @todo should we allow usage of parameter simple_client_copy to mean 'do not clone' in this case? @@ -836,7 +867,7 @@ class Wrapper break; } $pType = $mSig[$i+1]; - if ($pType == 'i4' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' || + if ($pType == 'i4' || $pType == 'i8' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' || $pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null' ) { // by building directly xmlrpc values when type is known and scalar (instead of encode() calls), @@ -877,7 +908,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='') { @@ -925,7 +956,7 @@ class Wrapper for ($i = 1; $i < $pCount; $i++) { $plist[] = "\$p$i"; $pType = $mSig[$i]; - if ($pType == 'i4' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' || + if ($pType == 'i4' || $pType == 'i8' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' || $pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null' ) { // only build directly xmlrpc values when type is known and scalar @@ -945,7 +976,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) { @@ -984,7 +1015,7 @@ class Wrapper * - string prefix * - bool simple_client_copy set it to true to avoid copying all properties of $client into the copy made in the new class * - * @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options) + * @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriate option is set in extra_options) */ public function wrapXmlrpcServer($client, $extraOptions = array()) { @@ -1005,7 +1036,7 @@ class Wrapper $req = new $reqClass('system.listMethods'); $response = $client->send($req, $timeout, $protocol); if ($response->faultCode()) { - error_log('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 { @@ -1015,7 +1046,7 @@ class Wrapper $mList = $decoder->decode($mList); } if (!is_array($mList) || !count($mList)) { - error_log('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 { @@ -1057,7 +1088,7 @@ class Wrapper } $source .= $methodWrap['source'] . "\n"; } else { - error_log('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); } } } @@ -1068,7 +1099,7 @@ class Wrapper if ($allOK) { return $xmlrpcClassName; } else { - error_log('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 { @@ -1098,7 +1129,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"; }