NXS_XMLRPC_ClassServer

Extension of the {@link NXS_XMLRPC_Server} class to easily wrap objects.

Defined (1)

The class is defined in the following location(s).

/inc-cl/apis/xmlrpc-client.php  
  1. class NXS_XMLRPC_ClassServer extends NXS_XMLRPC_Server 
  2. var $_objects; 
  3. var $_delim; 
  4.  
  5. function NXS_XMLRPC_ClassServer($delim = '.', $wait = false) 
  6. $this->NXS_XMLRPC_Server(array(), false, $wait); 
  7. $this->_delimiter = $delim; 
  8. $this->_objects = array(); 
  9.  
  10. function addMethod($rpcName, $functionName) 
  11. $this->callbacks[$rpcName] = $functionName; 
  12.  
  13. function registerObject($object, $methods, $prefix=null) 
  14. if (is_null($prefix)) 
  15. $prefix = get_class($object); 
  16. $this->_objects[$prefix] = $object; 
  17.  
  18. // Add to our callbacks array 
  19. foreach($methods as $method) 
  20. if (is_array($method)) 
  21. $targetMethod = $method[0]; 
  22. $method = $method[1]; 
  23. else 
  24. $targetMethod = $method; 
  25. $this->callbacks[$prefix . $this->_delimiter . $method]=array($prefix, $targetMethod); 
  26.  
  27. function call($methodname, $args) 
  28. if (!$this->hasMethod($methodname)) { 
  29. return new NXS_XMLRPC_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); 
  30. $method = $this->callbacks[$methodname]; 
  31.  
  32. // Perform the callback and send the response 
  33. if (count($args) == 1) { 
  34. // If only one paramater just send that instead of the whole array 
  35. $args = $args[0]; 
  36.  
  37. // See if this method comes from one of our objects or maybe self 
  38. if (is_array($method) || (substr($method, 0, 5) == 'this:')) { 
  39. if (is_array($method)) { 
  40. $object=$this->_objects[$method[0]]; 
  41. $method=$method[1]; 
  42. } else { 
  43. $object=$this; 
  44. $method = substr($method, 5); 
  45.  
  46. // It's a class method - check it exists 
  47. if (!method_exists($object, $method)) { 
  48. return new NXS_XMLRPC_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); 
  49.  
  50. // Call the method 
  51. $result = $object->$method($args); 
  52. } else { 
  53. // It's a function - does it exist? 
  54. if (!function_exists($method)) { 
  55. return new NXS_XMLRPC_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); 
  56.  
  57. // Call the function 
  58. $result = $method($args); 
  59. return $result;