Example #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);
 }
 /**
  * Get a XML-RPC request for the provided method and parameters
  * @param string $method full name of the method
  * @param string $parameters submitted parameters in string format, ready to be parsed
  * @return zibo\library\xmlrpc\Request the request for the XML RPC server
  * @throws zibo\library\validation\exception\ValidationException when the parameters could not be parsed
  */
 private function getXmlrpcRequest($method, $parameters)
 {
     $request = new Request($method);
     if (!$parameters) {
         return $request;
     }
     $parser = new ParameterParser();
     try {
         $parameters = $parser->parse($parameters);
     } catch (ZiboException $exception) {
         $error = new ValidationError(self::TRANSLATION_ERROR_PARAMETERS, 'Could not parse the parameters: %error%', array('error' => $exception->getMessage()));
         $validationException = new ValidationException();
         $validationException->addErrors(ClientForm::FIELD_PARAMETERS, array($error));
         throw $validationException;
     }
     foreach ($parameters as $parameter) {
         $request->addParameter($parameter);
     }
     return $request;
 }