50 protected static function isUTF8($text)
65 for ($i = 0; $i < $len; $i++) {
67 $byte1 = ord($text[$i]);
68 if ($byte1 >= 0 && $byte1 <= 0x7F) {
76 $byte2 = ord($text[$i]);
79 if ($byte1 >= 0xC2 && $byte1 <= 0xDF) {
80 if ($byte2 >= 0x80 && $byte2 <= 0xBF) {
90 $byte3 = ord($text[$i]);
94 if ($byte2 >= 0xA0 && $byte2 <= 0xBF &&
95 $byte3 >= 0x80 && $byte3 <= 0xBF) {
102 if ($byte1 >= 0xE1 && $byte1 <= 0xEF && $byte1 !== 0xED) {
103 if ($byte2 >= 0x80 && $byte2 <= 0xBF &&
104 $byte3 >= 0x80 && $byte3 <= 0xBF) {
105 $codepoint = (($byte1 & 0x0F) << 12) + (($byte2 & 0x3F) << 6) + ($byte3 & 0x3F);
106 if (($codepoint >= 0xE000 && $codepoint <= 0xF8FF) ||
107 ($codepoint >= 0xFDD0 && $codepoint <= 0xFDEF) ||
108 $codepoint == 0xFFFE || $codepoint == 0xFFFF) {
117 if ($byte1 == 0xED) {
118 if ($byte2 >= 0x80 && $byte2 <= 0x9F &&
119 $byte3 >= 0x80 && $byte3 <= 0xBF) {
129 $byte4 = ord($text[$i]);
132 if ($byte1 == 0xF0) {
133 if ($byte2 >= 0x90 && $byte2 <= 0xBF &&
134 $byte3 >= 0x80 && $byte3 <= 0xBF &&
135 $byte4 >= 0x80 && $byte4 <= 0xBF) {
136 $codepoint = (($byte1 & 0x07) << 18) +
137 (($byte2 & 0x3F) << 12) +
138 (($byte3 & 0x3F) << 6) +
141 if ($codepoint == 0x1FFFE || $codepoint == 0x1FFFF || $codepoint >= 0x2FFFE) {
150 if ($byte1 >= 0xF1 && $byte1 <= 0xF3) {
151 if ($byte2 >= 0x80 && $byte2 <= 0xBF &&
152 $byte3 >= 0x80 && $byte3 <= 0xBF &&
153 $byte4 >= 0x80 && $byte4 <= 0xBF) {
154 $codepoint = (($byte1 & 0x07) << 18) +
155 (($byte2 & 0x3F) << 12) +
156 (($byte3 & 0x3F) << 6) +
159 if ($codepoint < 0xE0000 || $codepoint >= 0xEFFFE) {
168 if ($byte1 == 0xF4) {
169 if ($byte2 >= 0x80 && $byte2 <= 0x8F &&
170 $byte3 >= 0x80 && $byte3 <= 0xBF &&
171 $byte4 >= 0x80 && $byte4 <= 0xBF) {
188 protected static function isBinaryString($text)
190 if (!static::isUTF8($text)) {
198 "\x00\x01\x02\x03\x04\x05\x06\x07\x08" .
201 "\x11\x12\x13\x14\15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" .
206 if (strcspn($text, $restrictedChars) !== strlen($text)) {
260 switch (gettype($value)) {
264 return new \fpoirotte\XRL\Types\Nil(null);
267 return new \fpoirotte\XRL\Types\Boolean($value);
271 return new \fpoirotte\XRL\Types\I4($value);
272 }
catch (\InvalidArgumentException $e) {
274 return new \fpoirotte\XRL\Types\I8($value);
277 return new \fpoirotte\XRL\Types\Double($value);
281 if (static::isBinaryString($value)) {
282 return new \fpoirotte\XRL\Types\Base64($value);
284 return new \fpoirotte\XRL\Types\StringType($value);
287 $newValue = array_map(
"static::convert", $value);
289 return new \fpoirotte\XRL\Types\ArrayType($newValue);
290 }
catch (\InvalidArgumentException $e) {
292 return new \fpoirotte\XRL\Types\Struct($newValue);
301 if ($value instanceof \
fpoirotte\XRL\Types\AbstractType) {
305 if ($value instanceof \GMP) {
307 '\\fpoirotte\\XRL\\Types\\I4',
308 '\\fpoirotte\\XRL\\Types\\I8',
309 '\\fpoirotte\\XRL\\Types\\BigInteger',
311 foreach ($candidates as $candidate) {
313 return new $candidate($value);
314 }
catch (\InvalidArgumentException $e) {
319 if ($value instanceof \DateTime) {
320 return new \fpoirotte\XRL\Types\DateTimeIso8601($value);
323 if (($value instanceof \DOMNode) ||
324 ($value instanceof \XMLWriter) ||
325 ($value instanceof \SimpleXMLElement)) {
326 return new \fpoirotte\XRL\Types\Dom($value);
330 return new \fpoirotte\XRL\Types\Struct(
332 'faultCode' =>
new \
fpoirotte\XRL\Types\IntType($value->getCode()),
333 'faultString' =>
new \
fpoirotte\XRL\Types\StringType(
334 get_class($value).
': '.$value->getMessage()
340 if (is_object($value) && (
341 ($value instanceof \Serializable) ||
342 method_exists($value,
'__sleep'))) {
343 $value = serialize($value);
346 if (static::isBinaryString($value)) {
347 return new \fpoirotte\XRL\Types\Base64($value);
349 return new \fpoirotte\XRL\Types\StringType($value);
352 throw new \InvalidArgumentException(
'Unconvertible type');
358 $newParams = array_map(
'static::convert', $request->getParams());
359 return $this->encoder->encodeRequest(
367 return $this->encoder->encodeError($error);
373 return $this->encoder->encodeResponse(static::convert($response));
encodeResponse($response)
Interface for an XML-RPC encoder.
An exception that is used to represent XML-RPC errors.
__construct(\fpoirotte\XRL\EncoderInterface $encoder)
encodeError(\Exception $error)
An XML-RPC encoder that transparently converts PHP types to their XML-RPC counterpart.
encodeRequest(\fpoirotte\XRL\Request $request)
A class that represents an XML-RPC request.