コード例 #1
0
ファイル: Zend1Parser.php プロジェクト: fxmlrpc/serialization
 /**
  * {@inheritdoc}
  */
 public function parse($xmlString)
 {
     $response = new \Zend_XmlRpc_Response();
     try {
         $response->loadXml($xmlString);
     } catch (\Exception $e) {
         throw new ParserException($e->getMessage(), $e->getCode(), $e);
     }
     if ($response->isFault()) {
         $fault = $response->getFault();
         throw new FaultException($fault->getMessage(), $fault->getCode());
     }
     $result = $response->getReturnValue();
     $toBeVisited = [&$result];
     while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
         $type = gettype($value);
         if ($type === 'array') {
             foreach ($value as &$element) {
                 $toBeVisited[] =& $element;
             }
             reset($value);
             // Reset all array pointers
         }
         array_shift($toBeVisited);
     }
     return $result;
 }
コード例 #2
0
ファイル: Http.php プロジェクト: fredcido/cenbrap
 /**
  * Override __toString() to send HTTP Content-Type header
  *
  * @return string
  */
 public function __toString()
 {
     if (!headers_sent()) {
         header('Content-Type: text/xml; charset=' . strtolower($this->getEncoding()));
     }
     return parent::__toString();
 }
コード例 #3
0
ファイル: Client.php プロジェクト: villos/tree_admin
 /**
  * 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
  * @throws Zend_Http_Client_FaultException
  */
 public function call($method, $params = array())
 {
     //        if ('system.' != substr($method, 0, 7)) {
     //
     //            // Ensure empty array/struct params are cast correctly
     //
     //            $signatures = $this->getIntrospector()->getMethodSignature($method);
     //            foreach ($params as $key => $param) {
     //                if (is_array($param) && empty($param)) {
     //                    $type = 'array';
     //                    foreach ($signatures as $signature) {
     //                        if (!is_array($signature)) {
     //                            continue;
     //                        }
     //                        if (array_key_exists($key + 1, $signature)) {
     //                            $type = $signature[$key + 1];
     //                            $type = (in_array($type, array('array', 'struct'))) ? $type : 'array';
     //                            break;
     //                        }
     //                    }
     //                    $params[$key] = array(
     //                        'type'  => $type,
     //                        'value' => $param
     //                    );
     //                }
     //            }
     //        }
     $request = new Zend_XmlRpc_Request($method, $params);
     $this->doRequest($request);
     if ($this->_lastResponse->isFault()) {
         $fault = $this->_lastResponse->getFault();
         throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getReturnValue();
 }
コード例 #4
0
ファイル: Http.php プロジェクト: jorgenils/zend-framework
 /**
  * Override __toString() to send HTTP Content-Type header
  * 
  * @return string
  */
 public function __toString()
 {
     if (!headers_sent()) {
         header('Content-Type: application/xml; charset=utf-8');
     }
     return parent::__toString();
 }
コード例 #5
0
ファイル: ResponseTest.php プロジェクト: nevvermind/zf2
 public function testLoadXmlThrowsExceptionWithMissingNodes3()
 {
     $sxl = new \SimpleXMLElement('<?xml version="1.0"?><methodResponse><bar>foo</bar></methodResponse>');
     $this->assertFalse($this->_response->loadXml($sxl->asXML()));
     $this->assertTrue($this->_response->isFault());
     $fault = $this->_response->getFault();
     $this->assertEquals(652, $fault->getCode());
 }
コード例 #6
0
ファイル: ResponseTest.php プロジェクト: omusico/logica
 protected function _loadXml($xml)
 {
     try {
         $this->_response->loadXml($xml);
         $this->fail('Invalid XML-RPC response should raise an exception');
     } catch (Exception $e) {
     }
 }
コード例 #7
0
ファイル: Client.php プロジェクト: josephholsten/swaplady
 /**
  * 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
  * @throws Zend_Http_Client_FaultException
  */
 public function call($method, $params = array())
 {
     $request = new Zend_XmlRpc_Request($method, $params);
     $this->doRequest($request);
     if ($this->_lastResponse->isFault()) {
         $fault = $this->_lastResponse->getFault();
         throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getReturnValue();
 }
コード例 #8
0
ファイル: ResponseTest.php プロジェクト: navassouza/zf2
 /**
  * @group ZF-12293
  */
 public function testDoesNotAllowExternalEntities()
 {
     $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml');
     $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt'));
     $this->_response->loadXml($payload);
     $value = $this->_response->getReturnValue();
     $this->assertTrue(empty($value));
     if (is_string($value)) {
         $this->assertNotContains('Local file inclusion', $value);
     }
 }
コード例 #9
0
 /**
  * __toString() test
  *
  * Call as method call 
  *
  * Returns: string 
  */
 public function test__toString()
 {
     $this->_response->setReturnValue('return value');
     $xml = $this->_response->__toString();
     try {
         $sx = new SimpleXMLElement($xml);
     } catch (Exception $e) {
         $this->fail('Invalid XML returned');
     }
     $this->assertTrue($sx->params ? true : false);
     $this->assertTrue($sx->params->param ? true : false);
     $this->assertTrue($sx->params->param->value ? true : false);
     $this->assertTrue($sx->params->param->value->string ? true : false);
     $this->assertEquals('return value', (string) $sx->params->param->value->string);
 }
コード例 #10
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();
     }
 }
コード例 #11
0
ファイル: Client.php プロジェクト: jon9872/zend-framework
 /**
  * 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
  * @throws Zend_Http_Client_FaultException
  */
 public function call($method, $params = array())
 {
     if ('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) {
             foreach ($params as $key => $param) {
                 if (is_array($param) && empty($param)) {
                     $type = 'array';
                     foreach ($signatures as $signature) {
                         if (!is_array($signature)) {
                             continue;
                         }
                         if (array_key_exists($key + 1, $signature)) {
                             $type = $signature[$key + 1];
                             $type = in_array($type, array('array', 'struct')) ? $type : 'array';
                             break;
                         }
                     }
                     $params[$key] = array('type' => $type, 'value' => $param);
                 }
             }
         }
     }
     $request = new Zend_XmlRpc_Request($method, $params);
     $this->doRequest($request);
     if ($this->_lastResponse->isFault()) {
         $fault = $this->_lastResponse->getFault();
         throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getReturnValue();
 }
コード例 #12
0
ファイル: Response.php プロジェクト: cwcw/cms
 /**
  *
  */
 public function loadXML($response)
 {
     $valid = true;
     if (extension_loaded('WebServices')) {
         if (!is_string($response)) {
             $this->_fault = new Zend_XmlRpc_Fault(650);
             $this->_fault->setEncoding($this->getEncoding());
             return false;
         }
         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;
         }
         $value = rpc_decode($response);
         $this->setReturnValue($value);
     } else {
         $valid = parent::loadXML($response);
     }
     return $valid;
 }
コード例 #13
0
 public function testLoadXmlThrowsExceptionWithMissingNodes3()
 {
     $sxl = new \SimpleXMLElement('<?xml version="1.0"?><methodResponse><bar>foo</bar></methodResponse>');
     $this->setExpectedException('Zend\\XmlRpc\\Exception\\ValueException', 'Missing XML-RPC value in XML');
     $this->_response->loadXml($sxl->asXML());
 }
コード例 #14
0
 public function getServerResponseFor($nativeVars)
 {
     $response = new Zend_XmlRpc_Response();
     $response->setReturnValue($nativeVars);
     $xml = $response->saveXml();
     $response = $this->makeHttpResponseFrom($xml);
     return $response;
 }
コード例 #15
0
 public function testShouldDisallowsDoctypeInRequestXmlAndReturnFalseOnLoading()
 {
     $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml');
     $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt'));
     $this->assertFalse($this->_response->loadXml($payload));
 }
コード例 #16
0
 /**
  * Test encoding settings
  */
 public function testSetGetEncoding()
 {
     $this->assertEquals('UTF-8', $this->_response->getEncoding());
     $this->_response->setEncoding('ISO-8859-1');
     $this->assertEquals('ISO-8859-1', $this->_response->getEncoding());
 }
コード例 #17
0
ファイル: Client.php プロジェクト: blazeriaz/youguess
 /**
  * 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();
 }
コード例 #18
0
 /**
  * Send an JSON-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_Json_Client_FaultException
  */
 public function call($method, $params = array())
 {
     if (!$this->skipSystemLookup() && !empty($method)) {
         $signature = $this->getIntrospector()->getMethodSignature($method);
         foreach ($params as $key => $param) {
             if (is_int($key)) {
                 // positional parameters
                 // can't validate them
                 continue;
             }
             $keyFound = false;
             foreach ($signature["parameters"] as $parameter) {
                 if ($parameter['name'] == "{$key}") {
                     $keyFound = true;
                 }
             }
             if ($keyFound !== true) {
                 throw new Zend_Json_Client_FaultException("named parameter {$key} not found in SMD");
             }
         }
     }
     $request = new Zend_Json_Server_Request();
     $request->setVersion('2.0');
     $request->setId(1);
     $request->setMethod($method);
     $request->setParams($params);
     $this->doRequest($request);
     if ($this->_lastResponse->isError()) {
         $fault = $this->_lastResponse->getError();
         /**
          * Exception thrown when an JSON-RPC fault is returned
          * @see Zend_Json_Client_FaultException
          */
         require_once 'Zend/Json/Client/FaultException.php';
         throw new Zend_Json_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getResult();
 }