Exemplo n.º 1
0
 public function testGetXmlRpcTypeByValueThrowsExceptionOnInvalidValue()
 {
     $this->setExpectedException('Zend_XmlRpc_Value_Exception');
     Zend_XmlRpc_Value::getXmlRpcTypeByValue(fopen(__FILE__, 'r'));
 }
Exemplo n.º 2
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;
                 }
                 if (count($signatures) > 1) {
                     $type = Zend_XmlRpc_Value::getXmlRpcTypeByValue($param);
                     foreach ($signatures as $signature) {
                         if (!is_array($signature)) {
                             continue;
                         }
                         if (isset($signature['parameters'][$key])) {
                             if ($signature['parameters'][$key] == $type) {
                                 break;
                             }
                         }
                     }
                 } elseif (isset($signatures[0]['parameters'][$key])) {
                     $type = $signatures[0]['parameters'][$key];
                 } else {
                     $type = null;
                 }
                 if (empty($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();
 }