Пример #1
0
 /**
  * __toString() test
  */
 public function test__toString()
 {
     $argv = array('string', true);
     $this->_request->setMethod('do.Something');
     $this->_request->setParams($argv);
     $xml = $this->_request->__toString();
     try {
         $sx = new SimpleXMLElement($xml);
     } catch (Exception $e) {
         $this->fail('Invalid XML returned');
     }
     $result = $sx->xpath('//methodName');
     $count = 0;
     while (list(, $node) = each($result)) {
         ++$count;
     }
     $this->assertEquals(1, $count, $xml);
     $result = $sx->xpath('//params');
     $count = 0;
     while (list(, $node) = each($result)) {
         ++$count;
     }
     $this->assertEquals(1, $count, $xml);
     try {
         $methodName = (string) $sx->methodName;
         $params = array((string) $sx->params->param[0]->value->string, (bool) $sx->params->param[1]->value->boolean);
     } catch (Exception $e) {
         $this->fail('One or more inconsistencies parsing generated XML: ' . $e->getMessage());
     }
     $this->assertEquals('do.Something', $methodName);
     $this->assertSame($argv, $params, $xml);
 }
Пример #2
0
 /**
  * __toString() test
  */
 public function test__toString()
 {
     $argv = array('string', true);
     $this->_request->setMethod('do.Something');
     $this->_request->setParams($argv);
     $xml = $this->_request->__toString();
     $this->_testXmlRequest($xml, $argv);
 }
Пример #3
0
 public function testHandleFunction()
 {
     $this->_server->addFunction('Zend_XmlRpc_Server_testFunction');
     $request = new Zend_XmlRpc_Request();
     $request->setMethod('Zend_XmlRpc_Server_testFunction');
     $request->setParams(array(array('value1'), 'key'));
     $response = $this->_server->handle($request);
     $this->assertFalse($response instanceof Zend_XmlRpc_Fault);
     $this->assertEquals('key: value1', $response->getReturnValue());
 }
Пример #4
0
 /**
  * Multicall - boxcar feature of XML-RPC for calling multiple methods
  * in a single request.
  *
  * Expects a an array of structs representing method calls, each element
  * having the keys:
  * - methodName
  * - params
  *
  * Returns an array of responses, one for each method called, with the value
  * returned by the method. If an error occurs for a given method, returns a
  * struct with a fault response.
  *
  * @see http://www.xmlrpc.com/discuss/msgReader$1208
  * @param  array $methods
  * @return array
  */
 public function multicall($methods)
 {
     $responses = array();
     foreach ($methods as $method) {
         $fault = false;
         if (!is_array($method)) {
             $fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
         } elseif (!isset($method['methodName'])) {
             $fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
         } elseif (!isset($method['params'])) {
             $fault = $this->_server->fault('Missing params', 603);
         } elseif (!is_array($method['params'])) {
             $fault = $this->_server->fault('Params must be an array', 604);
         } else {
             if ('system.multicall' == $method['methodName']) {
                 // don't allow recursive calls to multicall
                 $fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
             }
         }
         if (!$fault) {
             try {
                 $request = new Zend_XmlRpc_Request();
                 $request->setMethod($method['methodName']);
                 $request->setParams($method['params']);
                 $response = $this->_server->handle($request);
                 if ($response instanceof Zend_XmlRpc_Fault || $response->isFault()) {
                     $fault = $response;
                 } else {
                     $responses[] = $response->getReturnValue();
                 }
             } catch (Exception $e) {
                 $fault = $this->_server->fault($e);
             }
         }
         if ($fault) {
             $responses[] = array('faultCode' => $fault->getCode(), 'faultString' => $fault->getMessage());
         }
     }
     return $responses;
 }
Пример #5
0
 /**
  * multicall() test
  *
  * Call as method call 
  *
  * Expects:
  * - methods: 
  * 
  * Returns: array 
  */
 public function testMulticall()
 {
     $struct = array(array('methodName' => 'system.listMethods', 'params' => array()), array('methodName' => 'system.methodHelp', 'params' => array('system.multicall')));
     $request = new Zend_XmlRpc_Request();
     $request->setMethod('system.multicall');
     $request->addParam($struct);
     $response = $this->_server->handle($request);
     $this->assertTrue($response instanceof Zend_XmlRpc_Response, $response->__toString());
     $returns = $response->getReturnValue();
     $this->assertTrue(is_array($returns));
     $this->assertEquals(2, count($returns));
     $this->assertTrue(is_array($returns[0]), var_export($returns[0], 1));
     $this->assertTrue(is_string($returns[1]), var_export($returns[1], 1));
 }
Пример #6
0
 /**
  * Send an XML-RPC request to the service (for a specific method)
  * 
  * @param string $method Name of the method we want to call
  * @param array $params Array of parameters for the method
  * @param boolean $asResponseObject Return it as a response object instead of PHP native?
  * @throws Zend_Http_Client_FaultException
  */
 public function call($method, $params = array(), $asResponseObject = false)
 {
     $request = new Zend_XmlRpc_Request();
     $request->setMethod($method);
     $request->setParams($params);
     $this->doRequest($request);
     if ($asResponseObject) {
         return $this->_lastResponse;
     } else {
         if ($this->_lastResponse->isFault()) {
             $fault = $this->_lastResponse->getFault();
             throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode());
         }
         return $this->_lastResponse->getReturnValue();
     }
 }
Пример #7
0
$r = null;
$request = null;
$serializer = null;
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $request = new Zend\XmlRpc\Request();
    $request->setMethod('test');
    $request->setParams($args);
    $r = $request->saveXml();
}
$end = microtime(true);
printf("Zend\\XmlRpc\\Request (ZF2): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $request = new Zend_XmlRpc_Request();
    $request->setMethod('test');
    $request->setParams($args);
    $r = $request->saveXml();
}
$end = microtime(true);
printf("Zend_XmlRpc_Request (ZF1): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $serializer = new fXmlRpc\Serializer\XmlWriterSerializer();
    $r = $serializer->serialize('test', $args);
}
$end = microtime(true);
printf("fXmlRpc\\Serializer\\XmlWriterSerializer: %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $serializer = new fXmlRpc\Serializer\NativeSerializer();