Example #1
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
  * @return mixed
  * @throws Zend\XmlRpc\Client\FaultException
  */
 public function call($method, $params = array())
 {
     if (!$this->skipSystemLookup() && 'system.' != substr($method, 0, 7)) {
         // Ensure empty array/struct params are cast correctly
         // If system.* methods are not available, bypass. (ZF-2978)
         $success = true;
         try {
             $signatures = $this->getIntrospector()->getMethodSignature($method);
         } catch (\Zend\XmlRpc\Exception $e) {
             $success = false;
         }
         if ($success) {
             $validTypes = array(Value::XMLRPC_TYPE_ARRAY, Value::XMLRPC_TYPE_BASE64, Value::XMLRPC_TYPE_BOOLEAN, Value::XMLRPC_TYPE_DATETIME, Value::XMLRPC_TYPE_DOUBLE, Value::XMLRPC_TYPE_I4, Value::XMLRPC_TYPE_INTEGER, Value::XMLRPC_TYPE_NIL, Value::XMLRPC_TYPE_STRING, Value::XMLRPC_TYPE_STRUCT);
             if (!is_array($params)) {
                 $params = array($params);
             }
             foreach ($params as $key => $param) {
                 if ($param instanceof Value) {
                     continue;
                 }
                 $type = Value::AUTO_DETECT_TYPE;
                 foreach ($signatures as $signature) {
                     if (!is_array($signature)) {
                         continue;
                     }
                     if (isset($signature['parameters'][$key])) {
                         $type = $signature['parameters'][$key];
                         $type = in_array($type, $validTypes) ? $type : Value::AUTO_DETECT_TYPE;
                     }
                 }
                 $params[$key] = Value::getXmlRpcValue($param, $type);
             }
         }
     }
     $request = $this->_createRequest($method, $params);
     $this->doRequest($request);
     if ($this->_lastResponse->isFault()) {
         $fault = $this->_lastResponse->getFault();
         /**
          * Exception thrown when an XML-RPC fault is returned
          */
         throw new Client\Exception\FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getReturnValue();
 }
Example #2
0
 /**
  * @group ZF-8074
  */
 public function testXmlRpcObjectsAreNotConverted()
 {
     $this->mockIntrospector();
     $this->mockedIntrospector->expects($this->exactly(1))->method('getMethodSignature')->with('date.method')->will($this->returnValue(array(array('parameters' => array('dateTime.iso8601', 'string')))));
     $expects = 'date.method response';
     $this->setServerResponseTo($expects);
     $this->assertSame($expects, $this->xmlrpcClient->call('date.method', array(Value::getXmlRpcValue(time(), Value::XMLRPC_TYPE_DATETIME), 'foo')));
 }
Example #3
0
 /**
  * Test get/setEncoding()
  */
 public function testGetSetEncoding()
 {
     $this->assertEquals('UTF-8', $this->_server->getEncoding());
     $this->assertEquals('UTF-8', Value::getGenerator()->getEncoding());
     $this->assertSame($this->_server, $this->_server->setEncoding('ISO-8859-1'));
     $this->assertEquals('ISO-8859-1', $this->_server->getEncoding());
     $this->assertEquals('ISO-8859-1', Value::getGenerator()->getEncoding());
 }
Example #4
0
 /**
  * Test encoding settings
  */
 public function testSetGetEncoding()
 {
     $this->assertEquals('UTF-8', $this->_fault->getEncoding());
     $this->assertEquals('UTF-8', Value::getGenerator()->getEncoding());
     $this->_fault->setEncoding('ISO-8859-1');
     $this->assertEquals('ISO-8859-1', $this->_fault->getEncoding());
     $this->assertEquals('ISO-8859-1', Value::getGenerator()->getEncoding());
 }
Example #5
0
    /**
     * Handle an xmlrpc call (actual work)
     *
     * @param  Zend\XmlRpc\Request $request
     * @return Zend\XmlRpc\Response
     * @throws Zend\XmlRpc\Server\Exception|Exception
     * Zend\XmlRpc\Server\Exceptions are thrown for internal errors; otherwise,
     * any other exception may be thrown by the callback
     */
    protected function _handle(Request $request)
    {
        $method = $request->getMethod();

        // Check for valid method
        if (!$this->_table->hasMethod($method)) {
            throw new Server\Exception\RuntimeException('Method "' . $method . '" does not exist', 620);
        }

        $info     = $this->_table->getMethod($method);
        $params   = $request->getParams();
        $argv     = $info->getInvokeArguments();
        if (0 < count($argv) and $this->sendArgumentsToAllMethods()) {
            $params = array_merge($params, $argv);
        }

        // Check calling parameters against signatures
        $matched    = false;
        $sigCalled  = $request->getTypes();

        $sigLength  = count($sigCalled);
        $paramsLen  = count($params);
        if ($sigLength < $paramsLen) {
            for ($i = $sigLength; $i < $paramsLen; ++$i) {
                $xmlRpcValue = Value::getXmlRpcValue($params[$i]);
                $sigCalled[] = $xmlRpcValue->getType();
            }
        }

        $signatures = $info->getPrototypes();
        foreach ($signatures as $signature) {
            $sigParams = $signature->getParameters();
            if ($sigCalled === $sigParams) {
                $matched = true;
                break;
            }
        }
        if (!$matched) {
            throw new Server\Exception\RuntimeException('Calling parameters do not match signature', 623);
        }

        $return        = $this->_dispatch($info, $params);
        $responseClass = $this->getResponseClass();
        return new $responseClass($return);
    }
Example #6
0
 public function testPassingXmlRpcObjectReturnsTheSameObject()
 {
     $xmlRpcValue = new Value\String('foo');
     $this->assertSame($xmlRpcValue, Value::getXmlRpcValue($xmlRpcValue));
 }
Example #7
0
 public function testGetXmlRpcTypeByValueThrowsExceptionOnInvalidValue()
 {
     $this->setExpectedException('Zend\XmlRpc\Exception\InvalidArgumentException');
     Value::getXmlRpcTypeByValue(fopen(__FILE__, 'r'));
 }
Example #8
0
    /**
     * @group ZF-6445
     */
    public function testMarshalBigIntegerFromNative()
    {
        $bigIntegerValue = (string)(PHP_INT_MAX + 42);

        $value = Value::getXmlRpcValue(
            $bigIntegerValue,
            Value::XMLRPC_TYPE_I8
        );

        $this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
        $this->assertSame($bigIntegerValue, $value->getValue());
    }