setMethod ($Method); $this->registerFunction ('listFunctions', array ($this, 'rpcListFunctions'), array ()); } // }}} // {{{ setMethod /** * Set Type of this RPC-Handler * * @param enum $Method * * @access public * @return bool **/ public function setMethod ($Method) { switch ($Method) { case self::METHOD_XMLRPC: $this->Method = $Method; return true; } return false; } // }}} // {{{ registerFunction /** * Register a function-call * * @param string $Name * @param mixed $Callback * @param array $Parameters * * @access protected * @return bool **/ protected function registerFunction ($Name, $Callback, $Parameters) { // Check if the callback is valid if (!is_callable ($Callback)) return false; // Register the callback $lName = strtolower ($Name); if (!is_object ($Func = twIf_RPC_Helper_Method::newInstance ($Name, $Callback, $Parameters))) return false; $this->Functions [$lName] = $Func; return true; } // }}} // {{{ getFunctions /** * Retrive handles of all registered RPC-Functions * * @access public * @return array **/ public function getFunctions () { return $this->Functions; } // }}} // {{{ rpcListFunction /** * List all defined RPC-Functions * * @access public * @return array **/ public function rpcListFunctions () { $out = array (); if (is_array ($Functions = $this->getFunctions ())) foreach ($Functions as $Function) { $Definition = array ( 'name' => $Function->getName (), 'parameters' => array (), ); if (is_array ($Params = $Function->getParameters ())) foreach ($Params as $Key=>$Param) $Definition ['parameters'][] = (strlen ($Param ['Caption']) > 0 ? $Param ['Caption'] : $Key); $out [] = $Definition; } return $out; } // }}} // {{{ getXMLRPCDispatchClass /** * Decide which class to use as dispatcher * * @access protected * @return object **/ protected function getXMLRPCDispatchClass () { if (!is_object ($this->Dispatcher)) $this->Dispatcher = new twIf_RPC_Helper_Dispatch ($this); return $this->Dispatcher; } // }}} // {{{ generate /** * Generate a RPC-Server with the given parameters * * @access public * @return bool **/ public function generate () { switch ($this->Method) { case self::METHOD_XMLRPC: return $this->generateXMLRPC (); } return false; } // }}} // {{{ generateXMLRPC /** * Generate a XML-RPC-Server * * @access private * @return bool **/ private function generateXMLRPC () { require_once ('XML/RPC2/Server.php'); $Server = XML_RPC2_Server::create (null, array ( 'callHandler' => $this->getXMLRPCDispatchClass (), 'backend' => 'Php', 'encoding' => 'UTF-8', 'autoDocument' => false, 'autoDocumentExternalLinks' => false, 'signatureChecking' => false, )); $Server->handleCall (); } // }}} public function raiseError ($Code, $Message) { # TODO: Implement this # For XML: Throw exceptions as required } } ?>