@@ -36,6 +36,9 @@ class Wrapper
3636 /** @var string */
3737 protected static $ prefix = 'xmlrpc ' ;
3838
39+ /** @var null|string set to a namespaced class. If empty, static::$namespace . 'Response' will be used */
40+ protected static $ allowedResponseClass = null ;
41+
3942 /**
4043 * Given a string defining a php type or phpxmlrpc type (loosely defined: strings
4144 * accepted come from javadoc blocks), return corresponding phpxmlrpc type.
@@ -445,6 +448,7 @@ protected function buildWrapFunctionClosure($callable, $extraOptions, $plainFunc
445448 $ encoderClass = static ::$ namespace .'Encoder ' ;
446449 $ responseClass = static ::$ namespace .'Response ' ;
447450 $ valueClass = static ::$ namespace .'Value ' ;
451+ $ allowedResponseClass = static ::$ allowedResponseClass != '' ? static ::$ allowedResponseClass : $ responseClass ;
448452
449453 // validate number of parameters received
450454 // this should be optional really, as we assume the server does the validation
@@ -471,8 +475,7 @@ protected function buildWrapFunctionClosure($callable, $extraOptions, $plainFunc
471475
472476 $ result = call_user_func_array ($ callable , $ params );
473477
474- /// @todo when namespaces is under PhpXmlRpc, use root-class checking
475- if (! is_a ($ result , $ responseClass )) {
478+ if (! is_a ($ result , $ allowedResponseClass )) {
476479 // q: why not do the same for int, float, bool, string?
477480 if ($ funcDesc ['returns ' ] == Value::$ xmlrpcDateTime || $ funcDesc ['returns ' ] == Value::$ xmlrpcBase64 ) {
478481 $ result = new $ valueClass ($ result , $ funcDesc ['returns ' ]);
@@ -601,7 +604,7 @@ protected function buildWrapFunctionSource($callable, $newFuncName, $extraOption
601604 $ class = '\\' . $ class ;
602605 }
603606 $ innerCode .= " /// @var $ class \$obj \n" ;
604- $ innerCode .= " \$obj = PhpXmlRpc \\ Wrapper::getHeldObject(' $ newFuncName'); \n" ;
607+ $ innerCode .= " \$obj = " . static :: $ namespace . " Wrapper::getHeldObject(' $ newFuncName'); \n" ;
605608 $ realFuncName = '$obj-> ' . $ callable [1 ];
606609 } else {
607610 $ realFuncName = $ plainFuncName ;
@@ -611,8 +614,8 @@ protected function buildWrapFunctionSource($callable, $newFuncName, $extraOption
611614 if ($ i < (count ($ parsVariations ) - 1 ))
612615 $ innerCode .= " else \n" ;
613616 }
614- /// @todo here we should (could?) check for PhpXmlRpc/Response when dealing with a subclass namespace
615- $ innerCode .= " if (is_a( \$retVal, ' " . static :: $ namespace . "Response ')) \n return \$retVal; \n else \n" ;
617+ $ allowedResponseClass = static :: $ allowedResponseClass != '' ? static :: $ allowedResponseClass : static :: $ namespace . ' Response ' ;
618+ $ innerCode .= " if (is_a( \$retVal, ' " . $ allowedResponseClass . "')) \n return \$retVal; \n else \n" ;
616619 /// q: why not do the same for int, float, bool, string?
617620 if ($ funcDesc ['returns ' ] == Value::$ xmlrpcDateTime || $ funcDesc ['returns ' ] == Value::$ xmlrpcBase64 ) {
618621 $ innerCode .= " return new " . static ::$ namespace . "Response(new " . static ::$ namespace . "Value( \$retVal, ' {$ funcDesc ['returns ' ]}')); " ;
0 commit comments