Explorar o código

Adding Zend_XmlRpc_Server::sendArgumentsToAllMethods() to allow to pass to all methods or just to
constructor


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17774 44c647ce-9c0f-0410-b52a-842ac1e357ba

lars %!s(int64=16) %!d(string=hai) anos
pai
achega
90685deedc
Modificáronse 2 ficheiros con 41 adicións e 1 borrados
  1. 26 1
      library/Zend/XmlRpc/Server.php
  2. 15 0
      tests/Zend/XmlRpc/ServerTest.php

+ 26 - 1
library/Zend/XmlRpc/Server.php

@@ -171,6 +171,13 @@ class Zend_XmlRpc_Server extends Zend_Server_Abstract
     );
 
     /**
+     * Send arguments to all methods or just constructor?
+     *
+     * @var bool
+     */
+    protected $_sendArgumentsToAllMethods = true;
+
+    /**
      * Constructor
      *
      * Creates system.* methods.
@@ -499,6 +506,24 @@ class Zend_XmlRpc_Server extends Zend_Server_Abstract
     }
 
     /**
+     * Send arguments to all methods?
+     *
+     * If setClass() is used to add classes to the server, this flag defined
+     * how to handle arguments. If set to true, all methods including constructor
+     * will receive the arguments. If set to false, only constructor will receive the
+     * arguments
+     */
+    public function sendArgumentsToAllMethods($flag = null)
+    {
+        if ($flag === null) {
+            return $this->_sendArgumentsToAllMethods;
+        }
+
+        $this->_sendArgumentsToAllMethods = (bool)$flag;
+        return $this;
+    }
+
+    /**
      * Map PHP type to XML-RPC type
      *
      * @param  string $type
@@ -534,7 +559,7 @@ class Zend_XmlRpc_Server extends Zend_Server_Abstract
         $info     = $this->_table->getMethod($method);
         $params   = $request->getParams();
         $argv     = $info->getInvokeArguments();
-        if (0 < count($argv)) {
+        if (0 < count($argv) and $this->sendArgumentsToAllMethods()) {
             $params = array_merge($params, $argv);
         }
 

+ 15 - 0
tests/Zend/XmlRpc/ServerTest.php

@@ -180,6 +180,7 @@ class Zend_XmlRpc_ServerTest extends PHPUnit_Framework_TestCase
     public function testSettingClassWithArguments()
     {
         $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'argv-argument');
+        $this->assertTrue($this->_server->sendArgumentsToAllMethods());
         $request = new Zend_XmlRpc_Request();
         $request->setMethod('test.test4');
         $response = $this->_server->handle($request);
@@ -191,6 +192,20 @@ class Zend_XmlRpc_ServerTest extends PHPUnit_Framework_TestCase
             $response->getReturnValue());
     }
 
+    public function testSettingClassWithArgumentsOnlyPassingToConstructor()
+    {
+        $this->_server->setClass('Zend_XmlRpc_Server_testClass', 'test', 'a1', 'a2');
+        $this->_server->sendArgumentsToAllMethods(false);
+        $this->assertFalse($this->_server->sendArgumentsToAllMethods());
+
+        $request = new Zend_XmlRpc_Request();
+        $request->setMethod('test.test4');
+        $request->setParams(array('foo'));
+        $response = $this->_server->handle($request);
+        $this->assertNotType('Zend_XmlRpc_Fault', $response);
+        $this->assertSame(array('test1' => 'a1', 'test2' => 'a2', 'arg' => array('foo')), $response->getReturnValue());
+    }
+
     /**
      * fault() test
      */