ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Base64.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/Scalar.php';
45 // }}}
46 
65 {
66 
67  // {{{ constructor
68 
77  public function __construct($nativeValue)
78  {
79  if ((is_object($nativeValue)) &&(strtolower(get_class($nativeValue)) == 'stdclass') && (isset($nativeValue->xmlrpc_type))) {
80  $scalar = $nativeValue->scalar;
81  } else {
82  if (!is_string($nativeValue)) {
83  throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Base64 from type \'%s\'.', gettype($nativeValue)));
84  }
85  $scalar = $nativeValue;
86  }
87  $tmp = new stdclass();
88  $tmp->scalar = $scalar;
89  $tmp->xmlrpc_type = 'base64';
90  $this->setNativeValue($tmp);
91  }
92 
93  // }}}
94  // {{{ encode()
95 
101  public function encode()
102  {
103  $native = $this->getNativeValue();
104  return '<base64>' . base64_encode($native->scalar) . '</base64>';
105  }
106 
107  // }}}
108  // {{{ decode()
109 
115  public static function decode($xml)
116  {
117  // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
118  // xpath is used both in an element and in one of its children
119  $xml = simplexml_load_string($xml->asXML());
120  $value = $xml->xpath('/value/base64/text()');
121  if (!array_key_exists(0, $value)) {
122  $value = $xml->xpath('/value/text()');
123  }
124  // Emulate xmlrpcext results (to be able to switch from a backend to another)
125  $result = new stdclass();
126  $result->scalar = base64_decode($value[0]);
127  $result->xmlrpc_type = 'base64';
128  return $result;
129  }
130 
131  // }}}
132 
133 }
134 
135 ?>