Skip to content

Commit e78be9a

Browse files
committed
add Wrapper::$allowedResponseClass
1 parent 5a09060 commit e78be9a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* improved: added new methods: `Server::generatePayload($resp, $respCharset)`,
1111
`Server::printPayload($payload, $respContentType, $respEncoding)` , `HTTP::setAcceptedStatusCodes($statusCodes)`
1212
and `Wrapper::cloneClientForClosure($client)`. Made previously private method `Client::_try_multicall` protected.
13-
Added to `Wrapper` a protected member `$prefix = 'xmlrpc'`.
13+
Added to `Wrapper` protected members `$prefix = 'xmlrpc'` and `$allowedResponseClass`.
14+
Allow '*' as argument for `Wrapper::holdObject()`.
1415
All of this to help subclasses such as the Json-Rpc client, server, request and wrapper.
1516

1617
* improved: prepared the debugger for json-rpc 2.0 support, which will be in an upcoming release of the PhpJsonRpc library

src/Wrapper.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)