ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
Response.php
Go to the documentation of this file.
1 <?php
2 
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4 
5 // LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6 
40 // }}}
41 
42 // dependencies {{{
43 require_once 'XML/RPC2/Exception.php';
44 require_once 'XML/RPC2/Backend/Php/Value.php';
45 require_once 'XML/RPC2/Backend/Php/Value/Struct.php';
46 // }}}
47 
62 {
63 
64  // {{{ encode()
65 
80  public static function encode($param, $encoding = 'iso-8859-1')
81  {
82  if (!$param instanceof XML_RPC2_Backend_Php_Value) {
84  }
85  $result = '<?xml version="1.0" encoding="' . $encoding . '"?>';
86  $result .= '<methodResponse><params><param><value>' . $param->encode() . '</value></param></params></methodResponse>';
87  return $result;
88  }
89 
90  // }}}
91  // {{{ encodeFault()
92 
102  public static function encodeFault($code, $message, $encoding = 'iso-8859-1')
103  {
104  $value = new XML_RPC2_Backend_Php_Value_Struct(array('faultCode' => (int) $code, 'faultString' => (string) $message));
105  $result = '<?xml version="1.0" encoding="' . $encoding . '"?>';
106  $result .= '<methodResponse><fault><value>' . $value->encode() . '</value></fault></methodResponse>';
107  return $result;
108  }
109 
110  // }}}
111  // {{{ decode()
112 
125  public static function decode(SimpleXMLElement $xml)
126  {
127  $faultNode = $xml->xpath('/methodResponse/fault');
128  if (count($faultNode) == 1) {
129  throw XML_RPC2_FaultException::createFromDecode($faultNode[0]);
130  }
131  $paramValueNode = $xml->xpath('/methodResponse/params/param/value');
132  if (count($paramValueNode) == 1) {
133  return XML_RPC2_Backend_Php_Value::createFromDecode($paramValueNode[0])->getNativeValue();
134  }
135  throw new XML_RPC2_DecodeException('Unable to decode xml-rpc response. No fault nor params/param elements found');
136  }
137 
138  // }}}
139 
140 }
141 
142 ?>