Merge branch 'master' of github.com:gggeek/phpxmlrpc
authorgggeek <giunta.gaetano@gmail.com>
Wed, 8 Dec 2021 23:20:02 +0000 (23:20 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 8 Dec 2021 23:20:02 +0000 (23:20 +0000)
1  2 
src/Wrapper.php
tests/5ServerTest.php

diff --combined src/Wrapper.php
@@@ -581,7 -581,7 +581,7 @@@ class Wrappe
          }
  
          // since we are building source code for later use, if we are given an object instance,
 -        // we go out of our way and store a pointer to it in a static class var var...
 +        // we go out of our way and store a pointer to it in a static class var...
          if (is_array($callable) && is_object($callable[0])) {
              self::$objHolder[$newFuncName] = $callable[0];
              $innerCode .= "\$obj = PhpXmlRpc\\Wrapper::\$objHolder['$newFuncName'];\n";
       * @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);
                      ) {
                          $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;
                          }
  
              return $results;
          }
 -
      }
  
      /**
diff --combined tests/5ServerTest.php
@@@ -824,23 -824,17 +824,32 @@@ And turned it into nylon'
          ));
          $v = $this->send($m);
          $this->assertEquals('Michigan', $v->scalarval());
 +    }
 +
 +    public function testWrapInexistentMethod()
 +    {
 +        // make a 'deep client copy' as the original one might have many properties set
 +        $func = wrap_xmlrpc_method($this->client, 'examples.getStateName.notexisting', array('simple_client_copy' => 0));
 +        $this->assertEquals(false, $func);
 +    }
 +
 +    public function testWrapInexistentUrl()
 +    {
 +        $this->client->path = '/notexisting';
 +        // make a 'deep client copy' as the original one might have many properties set
 +        $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 0));
 +        $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