12 namespace fpoirotte\XRL;
48 protected static function isUTF8($text)
52 return (
bool) preg_match(
54 [\x09\x0A\x0D\x20-\x7E] # ASCII
55 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
56 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
57 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
58 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
59 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
60 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
61 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
106 switch (gettype($value)) {
110 return new \fpoirotte\XRL\Types\Nil(null);
113 return new \fpoirotte\XRL\Types\Boolean($value);
117 return new \fpoirotte\XRL\Types\I4($value);
118 }
catch (\InvalidArgumentException $e) {
120 return new \fpoirotte\XRL\Types\I8($value);
123 return new \fpoirotte\XRL\Types\Double($value);
127 if (static::isUTF8($value)) {
128 return new \fpoirotte\XRL\Types\String($value);
130 return new \fpoirotte\XRL\Types\Base64($value);
133 $newValue = array_map(
"static::convert", $value);
135 return new \fpoirotte\XRL\Types\ArrayType($newValue);
136 }
catch (\InvalidArgumentException $e) {
138 return new \fpoirotte\XRL\Types\Struct($newValue);
145 if (get_resource_type($value) ===
'GMP integer') {
147 return new \fpoirotte\XRL\Types\I4($value);
148 }
catch (\InvalidArgumentException $e) {
151 return new \fpoirotte\XRL\Types\I8($value);
152 }
catch (\InvalidArgumentException $e) {
154 return new \fpoirotte\XRL\Types\BigInteger($value);
159 throw new \InvalidArgumentException(
'Unconvertible type');
163 if ($value instanceof \fpoirotte\XRL\Types\AbstractType) {
167 if ($value instanceof \GMP) {
169 return new \fpoirotte\XRL\Types\I4($value);
170 }
catch (\InvalidArgumentException $e) {
173 return new \fpoirotte\XRL\Types\I8($value);
174 }
catch (\InvalidArgumentException $e) {
176 return new \fpoirotte\XRL\Types\BigInteger($value);
179 if ($value instanceof \DateTime) {
180 return new \fpoirotte\XRL\Types\DateTimeIso8601($value);
183 if (($value instanceof \DOMNode) ||
184 ($value instanceof \XMLWriter) ||
185 ($value instanceof \SimpleXMLElement)) {
186 return new \fpoirotte\XRL\Types\Dom($value);
190 return new \fpoirotte\XRL\Types\Struct(
192 'faultCode' =>
new \fpoirotte\XRL\Types\Int($value->getCode()),
193 'faultString' =>
new \fpoirotte\XRL\Types\String(
194 get_class($value).
': '.$value->getMessage()
200 if (!($value instanceof \
Serializable) && !method_exists($value,
'__sleep')) {
201 throw new \InvalidArgumentException(
'Could not serialize object');
208 $newParams = array_map(
'static::convert', $request->getParams());
209 return $this->encoder->encodeRequest(
210 new \fpoirotte\XRL\
Request($request->getProcedure(), $newParams)
217 return $this->encoder->encodeError($error);
223 return $this->encoder->encodeResponse(static::convert($response));
encodeResponse($response)
Interface for customized serializing.
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.