public function testDateTime() { $encoded = Xmlrpc::encodeRequest('formatDateTime', array('from' => new DateTime('2014-01-01'), 'until' => new DateTime('2014-12-31'))); $decoded = Xmlrpc::decodeRequest($encoded, $methodName); $this->assertEquals('DateTime', get_class($decoded[0]['from'])); $this->assertEquals('DateTime', get_class($decoded[0]['until'])); }
/** * @param \Blar\Events\Event $event Event. */ public function responseReceivedCallback($event) { $response = $event->getTarget(); $decoded = Xmlrpc::decodeResponse($response->getBody()); if (Xmlrpc::isFault($decoded)) { throw new Exception($decoded['faultString'], $decoded['faultCode']); } $response->setBody($decoded); }
/** * @param string $xml * @return string */ public function execute($xml = NULL) { if (is_null($xml)) { $xml = file_get_contents('php://input'); } try { return xmlrpc_server_call_method($this->getHandle(), $xml, array(), Xmlrpc::getDefaultOptions()); } catch (Exception $exception) { return Xmlrpc::encodeResponse(array('faultCode' => $exception->getCode(), 'faultString' => $exception->getMessage())); } }
/** * @param mixed $values * @return mixed */ public static function encodeValues($values) { array_walk_recursive($values, function (&$value) { if ($value instanceof DateTimeInterface) { $value = $value->format(DateTime::ISO8601); Xmlrpc::setType($value, 'datetime'); } if (!ctype_print($value)) { Xmlrpc::setType($value, 'base64'); } }); return $values; }
/** * @param string $methodName * @param array $arguments * @return mixed * @throws \Exception */ public function __call($methodName, $arguments) { if ($this->getNamespace()) { $methodName = $this->getNamespace() . '.' . $methodName; } $methodCall = Xmlrpc::encodeRequest($methodName, $arguments); $request = $this->createRequest(); $request->setUrl($this->getEndpoint()); $request->setBody($methodCall); $response = $request->send(); $data = Xmlrpc::decodeResponse($response->getBody()); if (Xmlrpc::isFault($data)) { throw new Exception($data['faultString'], $data['faultCode']); } return $data; }