示例#1
0
 /**
  * Encode a normal XML-RPC response, containing the provided value
  *
  * You may supply a php-native value, or an XML_RPC2_Backend_Php_Value instance, to be returned. Usually providing a native value
  * is more convenient. However, for some types, XML_RPC2_Backend_Php_Value::createFromNative can't properly choose the xml-rpc 
  * type. In these cases, constructing an XML_RPC2_Backend_Php_Value and using it as param here is the only way to return the desired 
  * type.
  *
  * @see http://www.xmlrpc.com/spec
  * @see XML_RPC2_Backend_Php_Value::createFromNative
  * @param mixed $param The result value which the response will envelop
  * @param string $encoding encoding
  * @return string The XML payload
  */
 public static function encode($param, $encoding = 'utf-8')
 {
     if (!$param instanceof XML_RPC2_Backend_Php_Value) {
         $param = XML_RPC2_Backend_Php_Value::createFromNative($param);
     }
     $result = '<?xml version="1.0" encoding="' . $encoding . '"?>' . "\n";
     $result .= '<methodResponse><params><param><value>' . $param->encode() . '</value></param></params></methodResponse>';
     return $result;
 }
 /**
  * Encode the instance into XML, for transport
  * 
  * @return string The encoded XML-RPC value,
  */
 public function encode()
 {
     $result = '<array><data>';
     foreach ($this->getNativeValue() as $element) {
         $result .= '<value>';
         $result .= $element instanceof XML_RPC2_Backend_Php_Value ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode();
         $result .= '</value>';
     }
     $result .= '</data></array>';
     return $result;
 }
示例#3
0
 /**
  * Encode the request for transmission.
  *
  * @return string XML-encoded request (a full XML document)
  */
 public function encode()
 {
     $methodName = $this->_methodName;
     $parameters = $this->getParameters();
     $result = '<?xml version="1.0" encoding="' . $this->_encoding . '"?>' . "\n";
     $result .= "<methodCall>";
     $result .= "<methodName>{$methodName}</methodName>";
     $result .= "<params>";
     foreach ($parameters as $parameter) {
         $result .= "<param><value>";
         $result .= $parameter instanceof XML_RPC2_Backend_Php_Value ? $parameter->encode() : XML_RPC2_Backend_Php_Value::createFromNative($parameter)->encode();
         $result .= "</value></param>";
     }
     $result .= "</params>";
     $result .= "</methodCall>";
     return $result;
 }
 /**
  * Encode the instance into XML, for transport
  * 
  * @return string The encoded XML-RPC value,
  */
 public function encode()
 {
     $result = '<struct>';
     foreach ($this->getNativeValue() as $name => $element) {
         $result .= '<member>';
         $result .= '<name>';
         $result .= strtr($name, array('&' => '&amp;', '<' => '&lt;', '>' => '&gt;'));
         $result .= '</name>';
         $result .= '<value>';
         $result .= $element instanceof XML_RPC2_Backend_Php_Value ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode();
         $result .= '</value>';
         $result .= '</member>';
     }
     $result .= '</struct>';
     return $result;
 }