示例#1
0
 /**
  * Constructs a new XML-RPC client view
  * @param zibo\xmlrpc\form\ClientForm $form The form of the client
  * @param zibo\library\xmlrpc\Request $request
  * @param zibo\library\xmlrpc\Response $response
  * @param string $responseString
  * @param float $time Time spent on the request in seconds
  * @return null
  */
 public function __construct(ClientForm $form, Request $request = null, Response $response = null, $responseString = null, $time = null)
 {
     parent::__construct(self::TEMPLATE);
     $this->set('form', $form);
     $this->set('time', $time);
     $this->set('requestString', null);
     $this->set('responseString', null);
     if ($request) {
         $this->set('requestString', String::addLineNumbers(trim($request->getXmlString())));
     }
     if ($responseString && !$response) {
         $this->set('responseString', String::addLineNumbers(trim($responseString)));
     } elseif ($response) {
         $this->set('responseString', String::addLineNumbers(trim($response->getXmlString())));
         $errorCode = $response->getErrorCode();
         if ($errorCode) {
             $this->set('error', $errorCode . ': ' . $response->getErrorMessage());
         } else {
             $parser = new ParameterParser();
             $result = $parser->unparse($response->getValue(), true);
             $this->set('result', $result);
         }
     }
     $this->addStyle(self::STYLE);
 }
示例#2
0
 /**
  * Invokes the provided request on the XML-RPC server
  * @param Request $request XML-RPC request
  * @return Response The response from the server
  */
 public function invoke(Request $request)
 {
     $requestXml = $request->getXmlString();
     $connection = @fsockopen($this->host, $this->port, $errno, $errstr);
     if (!$connection) {
         throw new ConnectionException($this->host, $this->port, $errstr, $errno);
     }
     $contentLength = strlen($requestXml);
     $headers = array("POST {$this->path} HTTP/1.0", "User-Agent: Zibo", "Host: {$this->host}", "Connection: close", "Content-Type: text/xml", "Content-Length: {$contentLength}");
     fwrite($connection, implode("\r\n", $headers));
     fwrite($connection, "\r\n\r\n");
     fwrite($connection, $requestXml);
     $response = '';
     while (!feof($connection)) {
         $response .= fgets($connection, 1024);
     }
     fclose($connection);
     #strip headers off of response
     $responseXml = substr($response, strpos($response, "\r\n\r\n") + 4);
     $response = Response::fromXMLString($responseXml);
     return $response;
 }
示例#3
0
 public function testGetXmlString()
 {
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<methodResponse>' . "\n" . '    <params>' . "\n" . '        <param>' . "\n" . '            <value>' . "\n" . '                <string>South Dakota</string>' . "\n" . '            </value>' . "\n" . '        </param>' . "\n" . '    </params>' . "\n" . '</methodResponse>';
     $response = new Response(new Value('South Dakota'));
     $this->assertXmlStringEqualsXmlString($xml, $response->getXmlString());
 }
 /**
  * Gets the result value from the provided response
  * @param Response $response Response to get the value from
  * @return mixed The value of the provided response
  */
 protected function getValueFromResponse(Response $response)
 {
     if (!$response->getErrorCode()) {
         return array($response->getValue());
     }
     $error = array('faultCode' => $response->getErrorCode(), 'faultString' => $response->getErrorMessage());
     return $error;
 }