Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function serialize($method, array $params = [])
 {
     $toBeVisited = [&$params];
     while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
         $type = gettype($value);
         if ($type === 'array') {
             // Zend converts non-zero-indexed arrays to structs
             if (array_keys($value) !== range(0, count($value) - 1) && array_keys($value) == range(1, count($value))) {
                 $value = array_values($value);
             }
             foreach ($value as &$child) {
                 $toBeVisited[] =& $child;
             }
         } elseif ($type === 'object') {
             if ($value instanceof \DateTime) {
                 $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->format('Ymd\\TH:i:s'), \Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
             } elseif ($value instanceof Base64) {
                 $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->getDecoded(), \Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
             } else {
                 $value = get_object_vars($value);
             }
         } elseif ($type === 'resource') {
             throw new InvalidTypeException($value);
         }
         array_shift($toBeVisited);
     }
     $request = new \Zend_XmlRpc_Request($method, $params);
     try {
         return $request->saveXml();
     } catch (\Exception $e) {
         throw new SerializerException($e->getMessage(), $e->getCode(), $e);
     }
 }
Esempio n. 2
0
 protected function _mockXmlRpcClient($method, $retval, $params = array())
 {
     $this->_xmlRpcMock = $this->getMock('Zend_XmlRpc_Client', array('setSkipSystemLookup', 'call'), array('http://foo'));
     $this->_xmlRpcMock->expects($this->once())->method('setSkipSystemLookup')->with(true);
     $params = array_merge($params, array('apikey' => $this->_gravatarXmlRpc->getApiKey()));
     $this->_xmlRpcMock->expects($this->once())->method('call')->with('grav.' . $method, array(Zend_XmlRpc_Value::getXmlRpcValue($params, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT)))->will($this->returnValue($retval));
     $this->_gravatarXmlRpc->setXmlRpcClient($this->_xmlRpcMock);
 }
 public function model_saved($observer)
 {
     $event = $observer->getEvent();
     $order = $event->getOrder();
     if ($this->new_order) {
         $customer_id = (string) $order->getCustomerId();
         if ($customer_id == '0') {
             $customer_id = '';
         }
         $this->affiliate_call('order_placed', array(Zend_XmlRpc_Value::getXmlRpcValue($_GET, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT), Zend_XmlRpc_Value::getXmlRpcValue($_COOKIE, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT), (string) $order->getRealOrderId(), (string) ($order->getData('subtotal') - $order->getData('discount_amount')), $order->getData('customer_email'), $order->getCustomerName(), $customer_id));
     }
     if ($order->getStatus() == "complete") {
         $this->affiliate_call('order_shipped', array((string) $order->getRealOrderId()));
     }
     return $this;
 }
 /**
  * Load a response from an XML response
  *
  * Attempts to load a response from an XMLRPC response, autodetecting if it 
  * is a fault response.
  * 
  * @param string $response 
  * @return boolean True if a valid XMLRPC response, false if a fault 
  * response or invalid input
  */
 public function loadXml($response)
 {
     if (!is_string($response)) {
         $this->_fault = new Zend_XmlRpc_Fault(650);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     // cast to default encoding
     $response = iconv('', $this->getEncoding(), $response);
     try {
         $xml = @new SimpleXMLElement($response);
     } catch (Exception $e) {
         // Not valid XML
         $this->_fault = new Zend_XmlRpc_Fault(651);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     if (!empty($xml->fault)) {
         // fault response
         $this->_fault = new Zend_XmlRpc_Fault();
         $this->_fault->setEncoding($this->getEncoding());
         $this->_fault->loadXml($response);
         return false;
     }
     if (empty($xml->params)) {
         // Invalid response
         $this->_fault = new Zend_XmlRpc_Fault(652);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     try {
         $valueXml = $xml->params->param->value->asXML();
         $valueXml = preg_replace('/<\\?xml version=.*?\\?>/i', '', $valueXml);
         $value = Zend_XmlRpc_Value::getXmlRpcValue(trim($valueXml), Zend_XmlRpc_Value::XML_STRING);
     } catch (Zend_XmlRpc_Value_Exception $e) {
         $this->_fault = new Zend_XmlRpc_Fault(653);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     $this->setReturnValue($value->getValue());
     return true;
 }
 /**
  * Serialize fault to XML
  *
  * @return string
  */
 public function saveXml()
 {
     // Create fault value
     $faultStruct = array('faultCode' => $this->getCode(), 'faultString' => $this->getMessage());
     $value = Zend_XmlRpc_Value::getXmlRpcValue($faultStruct);
     $generator = Zend_XmlRpc_Value::getGenerator();
     $generator->openElement('methodResponse')->openElement('fault');
     $value->generateXml();
     $generator->closeElement('fault')->closeElement('methodResponse');
     return $generator->flush();
 }
Esempio n. 6
0
<?php

header('Content-Type: text/plain');
set_include_path(realpath('../src/ZendFramework/library'));
require_once 'Zend/Http/Client.php';
require_once 'Zend/XmlRpc/Client.php';
require_once 'Zend/XmlRpc/Request.php';
require_once 'Zend/XmlRpc/Generator/XmlWriter.php';
$generator = new Zend_XmlRpc_Generator_XmlWriter();
//require_once('Zend/XmlRpc/Generator/DomDocument.php');
//$generator = new Zend_XmlRpc_Generator_DomDocument();
Zend_XmlRpc_Value::setGenerator($generator);
$httpClient = new Zend_Http_Client();
$httpClient->setAdapter('Zend_Http_Client_Adapter_Test');
$httpClient->getAdapter()->addResponse(new Zend_Http_Response(200, array(), new Zend_XmlRpc_Response('OK')));
$client = new Zend_XmlRpc_Client('http://localhost/', $httpClient);
for ($i = 8; $i > 0; $i--) {
    $client->call("test-{$i}", array('one', 'two'));
    echo "memory_usage " . memory_get_usage() . " bytes \n";
}
Esempio n. 7
0
 /**
  * Return response as XML
  *
  * @return string
  */
 public function saveXml()
 {
     $value = $this->_getXmlRpcReturn();
     $generator = Zend_XmlRpc_Value::getGenerator();
     $generator->openElement('methodResponse')->openElement('params')->openElement('param');
     $value->generateXml();
     $generator->closeElement('param')->closeElement('params')->closeElement('methodResponse');
     return $generator->flush();
 }
Esempio n. 8
0
    /**
     * Handle an xmlrpc call (actual work)
     *
     * @param Zend_XmlRpc_Request $request
     * @return Zend_XmlRpc_Response
     * @throws Zend_XmlRpcServer_Exception|Exception
     * Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise,
     * any other exception may be thrown by the callback
     */
    protected function _handle(Zend_XmlRpc_Request $request)
    {
        $method = $request->getMethod();

        // Check for valid method
        if (!$this->_table->hasMethod($method)) {
            require_once 'Zend/XmlRpc/Server/Exception.php';
            throw new Zend_XmlRpc_Server_Exception('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 = Zend_XmlRpc_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) {
            require_once 'Zend/XmlRpc/Server/Exception.php';
            throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623);
        }

        $return        = $this->_dispatch($info, $params);
        $responseClass = $this->getResponseClass();
        return new $responseClass($return);
    }
Esempio n. 9
0
 /**
  * Create XML request
  *
  * @return string
  */
 public function saveXml()
 {
     $args = $this->_getXmlRpcParams();
     $method = $this->getMethod();
     $generator = Zend_XmlRpc_Value::getGenerator();
     $generator->openElement('methodCall')->openElement('methodName', $method)->closeElement('methodName');
     if (is_array($args) && count($args)) {
         $generator->openElement('params');
         foreach ($args as $arg) {
             $generator->openElement('param');
             $arg->generateXml();
             $generator->closeElement('param');
         }
         $generator->closeElement('params');
     }
     $generator->closeElement('methodCall');
     return $generator->flush();
 }
Esempio n. 10
0
 /**
  * Retrieve method parameters as XMLRPC values
  *
  * @return array
  */
 protected function _getXmlRpcParams()
 {
     $params = array();
     if (is_array($this->_xmlRpcParams)) {
         foreach ($this->_xmlRpcParams as $param) {
             $value = $param['value'];
             $type = isset($param['type']) ? $param['type'] : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
             $params[] = Zend_XmlRpc_Value::getXmlRpcValue($value, $type);
         }
     }
     return $params;
 }
Esempio n. 11
0
require_once __DIR__ . '/../vendor/autoload.php';
$start = 0;
$limit = 40;
$r = null;
$xml = file_get_contents(__DIR__ . '/response.xml');
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $s = new SimpleXmlElement($xml);
    $r = Zend\XmlRpc\AbstractValue::getXmlRpcValue($s->params->param->value->asXml(), Zend\XmlRpc\AbstractValue::XML_STRING);
}
$end = microtime(true);
printf("Zend\\XmlRpc\\AbstractValue (ZF2): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $s = new SimpleXmlElement($xml);
    $r = Zend_XmlRpc_Value::getXmlRpcValue($s->params->param->value->asXml(), Zend_XmlRpc_Value::XML_STRING);
}
$end = microtime(true);
printf("Zend_XmlRpc_Value (ZF1): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
$parser = new fXmlRpc\Parser\XmlReaderParser();
for ($a = 0; $a < $limit; ++$a) {
    $r = $parser->parse($xml);
}
$end = microtime(true);
printf("fXmlRpc\\Parser\\XmlReaderParser: %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
$parser = new fXmlRpc\Parser\NativeParser();
for ($a = 0; $a < $limit; ++$a) {
    $r = $parser->parse($xml);
}
Esempio n. 12
0
 /**
  * sendToBitcashメソッド
  *
  * bitcashサーバーと通信をする
  * ├カード認証
  * └決済実行
  *
  * @param array $orderingData 注文データ
  * @param string $card_number カード番号(ひらがな16文字)
  *
  * @return array $result ビットキャッシュからの戻り値
  *
  */
 function sendToBitcash($orderingData, $cardNumber)
 {
     if (!$orderingData or !$cardNumber) {
         return FALSE;
     }
     $ComXmlRpcClientOBJ = new ComXmlRpcClient(self::BITCASH_URL);
     try {
         $ComXmlRpcClientOBJ->setSkipSystemLookup(true);
         $proxy = $ComXmlRpcClientOBJ->getProxy("Settlement");
         /* ■■■■■■■■■
          * バリデートロジック
          * ■■■■■■■■■
          * ビットキャッシュ側にカード、金額データを送信して
          * チェックを行う。
          */
         $validateParam["SHOP_ID"] = self::BITCASH_SHOP_ID;
         $validateParam["SHOP_PASSWD"] = self::BITCASH_SHOP_PASS;
         $validateParam["CARD_NUMBER"] = $cardNumber;
         $validateParam["RATING"] = self::BITCASH_RATING;
         $validateParam["PRICE"] = $orderingData["pay_total"];
         $validateParam["ORDER_ID"] = $orderingData["id"];
         $validateParam = Zend_XmlRpc_Value::getXmlRpcValue($validateParam, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
         $validateResult = $proxy->validate_card($validateParam);
         if (!$validateResult) {
             $this->_errorMsg = "validate_card_false_result";
             return false;
         } else {
             if ($validateResult["faultCode"]) {
                 $this->_errorMsg = "validate_card_fault_code";
                 return false;
             }
         }
         /* 返り値の取得
          *
          *
          * 1.ERRORの場合 例)カード情報が違う
          * Array
          *   ( [STATUS] => FAIL
          *     [ERROR]  => Array( [0] => 354:bad_card_number )
          *     [LOG_ID] => 43634282                            //バリデーション時の入出力ID
          *   )
          *
          * 2.OKの場合
          * Array
          *   ([BALANCE] => 100000     //バリデーション実行正常終了時のクレジット数(引き落とし前のクレジット数)
          *    [BCS_ID]  => 1581403990 //バリデーション正常終了時に発行されるセッション番号(決済実行時に使用)
          *    [ERROR]   => Array()
          *    [STATUS]  => OK
          *    [LOG_ID]  => 43634465   //バリデーション時の入出力ID
          *   )
          */
         // 有効ではない
         if ($validateResult["ERROR"]) {
             $this->_errorMsg = $validateResult["ERROR"][0];
             return false;
         }
         // 有効ではない
         if ("OK" != $validateResult["STATUS"]) {
             $this->_errorMsg = "validate_card_bad_status";
             return false;
         }
         /* ■■■■■■
          * 決済ロジック
          * ■■■■■■
          * STATUSがOKで帰ってきたらまたbitcashにデータの送信。決済を行う。
          */
         $param["SHOP_ID"] = self::BITCASH_SHOP_ID;
         $param["SHOP_PASSWD"] = self::BITCASH_SHOP_PASS;
         $param["CARD_NUMBER"] = $cardNumber;
         $param["BCS_ID"] = $validateResult["BCS_ID"];
         $param["PRICE"] = $orderingData["pay_total"];
         $param["ORDER_ID"] = $orderingData["id"];
         $param = Zend_XmlRpc_Value::getXmlRpcValue($param, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
         $result = $proxy->do_settlement($param);
         if (!$result) {
             $this->_errorMsg = "do_settlement_false_result";
             return false;
         } else {
             if ($result["faultCode"]) {
                 $this->_errorMsg = "do_settlement_fault_code";
                 return false;
             }
         }
         /* 返り値の取得
          *
          * 1.ERRORの場合 例)BCS_ID(バリデート時に生成されるID)がない場合
          * Array
          *   ( [STATUS] => FAIL
          *     [ERROR] => Array([0] => 304:no_bcs_id)
          *     [LOG_ID] => 43641701                     //決済時の入出力ID
          *   )
          *
          * 2.OKの場合
          * Array
          *   ( [SALES_ID] => 28293032 //決済実行正常終了時の販売ID
          *     [BALANCE] => 99900     //決済実行正常終了時の残りクレジット数。
          *     [ERROR] => Array()
          *     [STATUS] => OK
          *     [LOG_ID] => 43641640   //決済時の入出力ID
          *   )
          */
         // 有効ではない
         if ($result["ERROR"]) {
             $this->_errorMsg = $result["ERROR"][0];
             return false;
         }
         // 有効ではない
         if ("OK" != $result["STATUS"]) {
             $this->_errorMsg = "do_settlement_bad_status";
             return false;
         }
         return $result;
     } catch (Zend_XmlRpc_Client_HttpException $e) {
         // HTTP通信エラー
         $SendMailOBJ = SendMail::getInstance();
         $mailElements["subject"] = "ビットキャッシュHTTP通信エラー";
         $mailElements["text_body"] = "注文ID:" . $orderingData["id"] . "\nカード番号:" . $cardNumber . "\n金額:" . $orderingData["pay_total"] . "\n" . $e;
         $SendMailOBJ->debugMailTo($mailElements);
         return FALSE;
     } catch (Zend_XmlRpc_Client_FaultException $e) {
         // RPC実行エラー
         $SendMailOBJ = SendMail::getInstance();
         $mailElements["subject"] = "ビットキャッシュRPC実行エラー";
         $mailElements["text_body"] = "注文ID:" . $orderingData["id"] . "\nカード番号:" . $cardNumber . "\n金額:" . $orderingData["pay_total"] . "\n" . $e;
         $SendMailOBJ->debugMailTo($mailElements);
         return FALSE;
     }
 }
Esempio n. 13
0
 /**
  * Executes XML-RPC request by proxying local XML-RPC client.
  *
  * @see Zend_XmlRpc_Client
  * @param string $method
  * @param array $params
  * @return mixed
  */
 protected function _call($method, $params = array())
 {
     $params = array_merge($params, array('apikey' => $this->getApiKey()));
     $xmlRpcClient = $this->getXmlRpcClient();
     $xmlRpcClient->setSkipSystemLookup(true);
     //We will manually prepare params.
     try {
         $retval = $xmlRpcClient->call('grav.' . $method, array(Zend_XmlRpc_Value::getXmlRpcValue($params, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT)));
         return $retval;
     } catch (Zend_XmlRpc_Client_FaultException $ex) {
         require_once 'NP/Service/Gravatar/XmlRpc/Exception.php';
         throw new NP_Service_Gravatar_XmlRpc_Exception($ex->getMessage());
     }
 }
Esempio n. 14
0
 /**
  * Convert an array of PHP variables into XML-RPC native types represented by Zend_XmlRpc_Value objects
  * If method name is given, try to use the _methodSignatures data member for type hinting,
  * if not, auto convert the PHP variable types into XML-RPC types
  *
  * @param array $params Array of PHP varaibles and/or Zend_XmlRpc_Value objects
  *                      The parameter is passed by reference
  * @param string $methodName If set, the type hinting will be according to the parameters of this method
  * @return array|null Array of Zend_XmlRpc_Value objects
  */
 protected function _convertParams(&$params, $methodName = null)
 {
     if (!is_array($params)) {
         $params = null;
         return;
     }
     $paramsTypeHinting = $this->_getMethodParams($methodName);
     /** @todo what we do if count($paramsTypeHinting) differ than count($params) ? maybe nothing */
     foreach ($params as $i => &$param) {
         if (!$param instanceof Zend_XmlRpc_Value) {
             // Need to convert the parameter to Zend_XmlRpc_Value object
             // If there is type hinting for this method, we use it, otherwise
             // the convertion is done according to the PHP type
             if (isset($paramsTypeHinting[$i])) {
                 $param = Zend_XmlRpc_Value::getXmlRpcValue($param, $paramsTypeHinting[$i]);
             } else {
                 $param = Zend_XmlRpc_Value::getXmlRpcValue($param);
             }
         }
     }
 }
 *   $this->_xmlWriter->flush(true);   
 */
// installed framework
set_include_path(realpath('../src/ZendFramework/library'));
// required classes
require_once 'Zend/XmlRpc/Generator/XmlWriter.php';
require_once 'Zend/XmlRpc/Value.php';
// be sure to use the leaky generator
$generator = new Zend_XmlRpc_Generator_XmlWriter();
Zend_XmlRpc_Value::setGenerator($generator);
// test a thousand times
for ($i = 1000; $i > 0; $i--) {
    // make a thousand stars
    $bug = str_pad('', 1000, '*');
    // factorize value
    $bug = Zend_XmlRpc_Value::getXmlRpcValue($bug, Zend_XmlRpc_Value::XMLRPC_TYPE_STRING);
    // save value, this leaks!
    $bug = $bug->saveXml();
    // report sometimes
    if ($i % 100 === 0) {
        $mem = floor(memory_get_usage() / 1024);
        echo "KB {$mem}\n";
    }
    // print once
    if ($i === 1) {
        echo htmlentities($bug);
    }
    // clean
    unset($bug);
}
?>
 public function testPassingXmlRpcObjectReturnsTheSameObject()
 {
     $xmlRpcValue = new Zend_XmlRpc_Value_String('foo');
     $this->assertSame($xmlRpcValue, Zend_XmlRpc_Value::getXmlRpcValue($xmlRpcValue));
 }
Esempio n. 17
0
 /**
  * Sets XML generator instance
  *
  * @param Zend_XmlRpc_Generator_GeneratorAbstract $generator
  * @return void
  */
 public static function setGenerator(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
 {
     self::$_generator = $generator;
 }
Esempio n. 18
0
 /**
  * Handle an xmlrpc call (actual work)
  *
  * @param Zend_XmlRpc_Request $request
  * @return Zend_XmlRpc_Response
  * @throws Zend_XmlRpcServer_Exception|Exception 
  * Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise, 
  * any other exception may be thrown by the callback
  */
 protected function _handle(Zend_XmlRpc_Request $request)
 {
     $method = $request->getMethod();
     // Check for valid method
     if (!isset($this->_table[$method])) {
         throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 620);
     }
     $info = $this->_table[$method];
     $params = $request->getParams();
     $argv = $info->getInvokeArguments();
     if (0 < count($argv)) {
         $params = array_merge($params, $argv);
     }
     // Check calling parameters against signatures
     $matched = false;
     $sigCalled = array();
     foreach ($params as $param) {
         $value = Zend_XmlRpc_Value::getXmlRpcValue($param);
         $sigCalled[] = $value->getType();
     }
     $signatures = $info->getPrototypes();
     foreach ($signatures as $signature) {
         $sigParams = $signature->getParameters();
         $tmpParams = array();
         foreach ($sigParams as $param) {
             $tmpParams[] = $param->getType();
         }
         if ($sigCalled === $tmpParams) {
             $matched = true;
             break;
         }
     }
     if (!$matched) {
         throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623);
     }
     if ($info instanceof Zend_Server_Reflection_Function) {
         $func = $info->getName();
         $return = call_user_func_array($func, $params);
     } elseif ($info instanceof Zend_Server_Reflection_Method && $info->system) {
         // System methods
         $return = $info->invokeArgs($this, $params);
     } elseif ($info instanceof Zend_Server_Reflection_Method) {
         // Get class
         $class = $info->getDeclaringClass()->getName();
         if ('static' == $info->isStatic()) {
             // for some reason, invokeArgs() does not work the same as
             // invoke(), and expects the first argument to be an object.
             // So, using a callback if the method is static.
             $return = call_user_func_array(array($class, $info->getName()), $params);
         } else {
             // Object methods
             try {
                 $object = $info->getDeclaringClass()->newInstance();
             } catch (Exception $e) {
                 throw new Zend_XmlRpc_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName(), 621);
             }
             $return = $info->invokeArgs($object, $params);
         }
     } else {
         throw new Zend_XmlRpc_Server_Exception('Method missing implementation ' . get_class($info), 622);
     }
     $response = new ReflectionClass($this->_responseClass);
     return $response->newInstance($return);
 }
Esempio n. 19
0
 /**
  * Test get/setEncoding()
  */
 public function testGetSetEncoding()
 {
     $this->assertEquals('UTF-8', $this->_server->getEncoding());
     $this->assertEquals('UTF-8', Zend_XmlRpc_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', Zend_XmlRpc_Value::getGenerator()->getEncoding());
 }
Esempio n. 20
0
 public function testFactoryThrowsWhenInvalidTypeSpecified()
 {
     try {
         Zend_XmlRpc_Value::getXmlRpcValue('', 'bad type here');
         $this->fail();
     } catch (Exception $e) {
         $this->assertRegexp('/given type is not/i', $e->getMessage());
     }
 }
Esempio n. 21
0
 /**
  * Serialize fault to XML
  *
  * @return string
  */
 public function saveXML()
 {
     // Create fault value
     $faultStruct = array('faultCode' => $this->getCode(), 'faultString' => $this->getMessage());
     $value = Zend_XmlRpc_Value::getXmlRpcValue($faultStruct);
     $valueDOM = new DOMDocument('1.0', $this->getEncoding());
     $valueDOM->loadXML($value->saveXML());
     // Build response XML
     $dom = new DOMDocument('1.0', 'ISO-8859-1');
     $r = $dom->appendChild($dom->createElement('methodResponse'));
     $f = $r->appendChild($dom->createElement('fault'));
     $f->appendChild($dom->importNode($valueDOM->documentElement, 1));
     return $dom->saveXML();
 }
 /**
  * @group ZF-6445
  */
 public function testMarschalBigIntegerFromCryptObjectThrowsException()
 {
     try {
         Zend_XmlRpc_Value::getXmlRpcValue(new Zend_Crypt_Math_BigInteger());
         $this->fail('expected Zend_XmlRpc_Value_Exception has not been thrown');
     } catch (Zend_XmlRpc_Value_Exception $exception) {
         if (strpos($exception->getMessage(), 'Zend_Crypt_Math_BigInteger') === false) {
             $this->fail('caught Zend_XmlRpc_Value_Exception does not contain expected text');
         }
     }
 }
Esempio n. 23
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(Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY, Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64, Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN, Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME, Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE, Zend_XmlRpc_Value::XMLRPC_TYPE_I4, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER, Zend_XmlRpc_Value::XMLRPC_TYPE_NIL, Zend_XmlRpc_Value::XMLRPC_TYPE_STRING, Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT);
             if (!is_array($params)) {
                 $params = array($params);
             }
             foreach ($params as $key => $param) {
                 if ($param instanceof Zend_XmlRpc_Value) {
                     continue;
                 }
                 $type = Zend_XmlRpc_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 : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
                     }
                 }
                 $params[$key] = Zend_XmlRpc_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
          * @see Zend_XmlRpc_Client_FaultException
          */
         #require_once 'Zend/XmlRpc/Client/FaultException.php';
         throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getReturnValue();
 }
 /**
  * @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(Zend_XmlRpc_Value::getXmlRpcValue(time(), Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME), 'foo')));
 }
Esempio n. 25
0
 public function testGetXmlRpcTypeByValueThrowsExceptionOnInvalidValue()
 {
     $this->setExpectedException('Zend_XmlRpc_Value_Exception');
     Zend_XmlRpc_Value::getXmlRpcTypeByValue(fopen(__FILE__, 'r'));
 }
Esempio n. 26
0
 /**
  * Retrieve method parameters as XMLRPC values
  * 
  * @return array
  */
 protected function _getXmlRpcParams()
 {
     $params = array();
     foreach ($this->_xmlRpcParams as $param) {
         $value = $param['value'];
         $type = isset($param['type']) ? $param['type'] : null;
         $params[] = Zend_XmlRpc_Value::getXmlRpcValue($value);
     }
     return $params;
 }