X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=lib%2FXmlRpcServer.php;h=c8c1ac40a9930f7161d934f01bf0fe5e1b4aa191;hp=e77910ff7387b176b895c86475a8714e4599e187;hb=ad5f896b03adaa073134a00108a9cdf00720673a;hpb=ebf03950ffaea849b931adf83b6c20ac9fb7ef33 diff --git a/lib/XmlRpcServer.php b/lib/XmlRpcServer.php index e77910f..c8c1ac4 100644 --- a/lib/XmlRpcServer.php +++ b/lib/XmlRpcServer.php @@ -65,7 +65,8 @@ class XmlRpcServer extends HttpResponse * @param string $namespace * @param string $encoding */ - public function __construct($namespace) { + public function __construct($namespace) + { $this->namespace = $namespace; self::initialize(); } @@ -73,7 +74,8 @@ class XmlRpcServer extends HttpResponse /** * Destructor */ - public function __destruct() { + public function __destruct() + { if (self::$refcnt && !--self::$refcnt) { xmlrpc_server_destroy(self::$xmlrpc); } @@ -85,7 +87,8 @@ class XmlRpcServer extends HttpResponse * @param string $namespace * @return XmlRpcServer */ - public static function factory($namespace) { + public static function factory($namespace) + { return new XmlRpcServer($namespace); } @@ -94,9 +97,10 @@ class XmlRpcServer extends HttpResponse * * @param array $options */ - public static function run(array $options = null) { + public static function run(array $options = null) + { self::initialize(false, true); - HttpResponse::setContentType("text/xml; charset=". self::$encoding); + self::setContentType("text/xml; charset=". self::$encoding); echo xmlrpc_server_call_method(self::$xmlrpc, self::$xmlreq, null, array("encoding" => self::$encoding) + (array) $options); } @@ -106,11 +110,13 @@ class XmlRpcServer extends HttpResponse * * @param string $method * @param array $params - * @param array $options + * @param array $request_options + * @param array $response_options */ - public static function test($method, array $params, array $options = null) { - self::$xmlreq = xmlrpc_encode_request($method, $params); - self::run(); + public static function test($method, array $params, array $request_options = null, array $response_options = null) + { + self::$xmlreq = xmlrpc_encode_request($method, $params, $request_options); + self::run($response_options); } /** @@ -119,8 +125,10 @@ class XmlRpcServer extends HttpResponse * @param int $code * @param string $msg */ - public static function error($code, $msg) { - echo xmlrpc_encode(array("faultCode" => $code, "faultString" => $msg)); + public static function error($code, $msg, array $options = null) + { + echo xmlrpc_encode(array("faultCode" => $code, "faultString" => $msg), + array("encoding" => self::$encoding) + (array) $options); } /** @@ -131,7 +139,8 @@ class XmlRpcServer extends HttpResponse * @param mixed $dispatch * @param array $spec */ - public function registerMethod($name, $callback, $dispatch = null, array $spec = null) { + public function registerMethod($name, $callback, $dispatch = null, array $spec = null) + { if (!is_callable($callback, false, $cb_name)) { throw new Exception("$cb_name is not a valid callback"); } @@ -155,7 +164,8 @@ class XmlRpcServer extends HttpResponse * * @param XmlRpcRequestHandler $handler */ - public function registerHandler(XmlRpcRequestHandler $handler) { + public function registerHandler(XmlRpcRequestHandler $handler) + { $this->handler = $handler; foreach (get_class_methods($handler) as $method) { @@ -172,21 +182,24 @@ class XmlRpcServer extends HttpResponse } } - private function method($method, $namespace = null) { + private function method($method, $namespace = null) + { if (!strlen($namespace)) { $namespace = strlen($this->namespace) ? $this->namespace : "xmlrpc"; } return $namespace .".". strtolower($method[6]) . substr($method, 7); } - private function dispatch($method, array $params = null) { + private function dispatch($method, array $params = null) + { if (array_key_exists($method, self::$handle)) { return call_user_func(self::$handle[$method], $params); } throw new Exception("Unknown XMLRPC method: $method"); } - private static function initialize($server = true, $data = false) { + private static function initialize($server = true, $data = false) + { if ($data) { if (!self::$xmlreq && !(self::$xmlreq = http_get_request_body())) { throw new Exception("Failed to fetch XMLRPC request body"); @@ -219,7 +232,8 @@ class XmlRpcServer extends HttpResponse * } * */ -interface XmlRpcRequestHandler { +interface XmlRpcRequestHandler +{ public function getNamespace(); public function getIntrospectionData(array &$spec = null); } @@ -227,10 +241,13 @@ interface XmlRpcRequestHandler { /** * XmlRpcRequestHandlerStub */ -abstract class XmlRpcRequestHandlerStub implements XmlRpcRequestHandler { - public function getNamespace() { +abstract class XmlRpcRequestHandlerStub implements XmlRpcRequestHandler +{ + public function getNamespace() + { } - public function getIntrospectionData(array &$spec = null) { + public function getIntrospectionData(array &$spec = null) + { } }