ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {{{
43require_once 'XML/RPC2/Exception.php';
44require_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?>
$result
static decode($xml)
Decode transport XML and set the instance value accordingly.
Definition: Base64.php:115
encode()
Encode the instance into XML, for transport.
Definition: Base64.php:101
__construct($nativeValue)
Constructor.
Definition: Base64.php:77
setNativeValue($value)
nativeValue setter
Definition: Value.php:89
getNativeValue()
nativeValue property getter
Definition: Value.php:76