X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FWrapper.php;h=8b5ddb46e70bc2de999994e4e9cb6293c7f3df14;hb=acc91a7e16e2e2f09fb5b192e89ac4007a40973f;hp=a45100b37900f3c508f8b4996f7c7b8a3674e82e;hpb=ce870f0f42cc46ba985167056d47966a8e8fd100;p=plcapi.git diff --git a/src/Wrapper.php b/src/Wrapper.php index a45100b..8b5ddb4 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])) { @@ -170,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; } @@ -182,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; } @@ -226,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? @@ -252,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; } @@ -396,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\\'; @@ -593,8 +622,8 @@ class Wrapper * @param array $extraOptions see the docs for wrapPhpMethod for basic options, plus * - string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on whether $className is a class name or object instance * - string method_filter a regexp used to filter methods to wrap based on their names - * - string prefix used for the names of the xmlrpc methods created - * + * - string prefix used for the names of the xmlrpc methods created. + * - string namespace use when classes with actual namespaces should only have one namespace. e.g. \Some\Namespace\Api is needed as my.Api set this to "my". Works in conjunction with prefix! * @return array|false false on failure */ public function wrapPhpClass($className, $extraOptions = array()) @@ -602,6 +631,7 @@ class Wrapper $methodFilter = isset($extraOptions['method_filter']) ? $extraOptions['method_filter'] : ''; $methodType = isset($extraOptions['method_type']) ? $extraOptions['method_type'] : 'auto'; $prefix = isset($extraOptions['prefix']) ? $extraOptions['prefix'] : ''; + $namespace = isset($extraOptions['namespace']) ? $extraOptions['namespace'] : ''; $results = array(); $mList = get_class_methods($className); @@ -614,10 +644,14 @@ class Wrapper ) { $methodWrap = $this->wrapPhpFunction(array($className, $mName), '', $extraOptions); if ($methodWrap) { - if (is_object($className)) { - $realClassName = get_class($className); - }else { - $realClassName = $className; + if ($namespace) { + $realClassName = $namespace; + } else { + if (is_object($className)) { + $realClassName = get_class($className); + }else { + $realClassName = $className; + } } $results[$prefix."$realClassName.$mName"] = $methodWrap; } @@ -672,7 +706,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()) { @@ -731,7 +765,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; } @@ -742,7 +776,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; } @@ -785,7 +819,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? @@ -879,7 +913,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='') { @@ -947,7 +981,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) { @@ -1007,7 +1041,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 { @@ -1017,7 +1051,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 { @@ -1059,7 +1093,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); } } } @@ -1070,7 +1104,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 { @@ -1100,7 +1134,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"; }