Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gggeek/phpxmlrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Dec 8, 2021
2 parents 50ea70e + fb82ab4 commit e344025
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions demo/server/methodProviders/wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function returnObject()

$moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method_type' => 'all'));

$namespaceSignatures = $wrapper->wrapPhpClass($c, array('namespace' => 'namespacetest', 'method_type' => 'all'));

$returnObj_sig = $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));

return array_merge(
Expand All @@ -154,5 +156,6 @@ public function returnObject()
'tests.getStateName.11' => $findstate11_sig,
'tests.returnPhpObject' => $returnObj_sig,
),
$namespaceSignatures,
$moreSignatures
);
17 changes: 11 additions & 6 deletions src/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,16 @@ protected function buildWrapFunctionSource($callable, $newFuncName, $extraOption
* @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())
{
$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);
Expand All @@ -643,10 +644,14 @@ public function wrapPhpClass($className, $extraOptions = array())
) {
$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;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/5ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,15 @@ public function testWrapInexistentUrl()
$this->assertEquals(false, $func);
}

public function testServerWrappedClassWithNamespace()
{
$m = new xmlrpcmsg('namespacetest.findState', array(
new xmlrpcval(23, 'int'),
));
$v = $this->send($m);
$this->assertEquals('Michigan', $v->scalarval());
}

public function testWrappedMethod()
{
// make a 'deep client copy' as the original one might have many properties set
Expand Down

0 comments on commit e344025

Please sign in to comment.