Skip to content

Commit

Permalink
issue [#1016350] voxpelli, heyrocker, kylebrowning Do not prefix acti…
Browse files Browse the repository at this point in the history
…ons in the xmlrpc server
  • Loading branch information
Kyle Browning authored and Kyle Browning committed May 4, 2011
1 parent 579a090 commit cc7005a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 73 deletions.
81 changes: 8 additions & 73 deletions servers/xmlrpc_server/xmlrpc_server.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* @file
* Enable XML-RPC for services module.
*
* Most of the work here is converting the REST-style resource definitions
* to XMLRPC-style procedure calls. These procedures are renamed as
* <resource>.<method>. So the node resource's retrieve method has an XMLRPC
* procedure name of node.retrieve. Actions prepend 'action_' to the procedure
* name. So the login action of the user resource becomes user.action_login.
* Resource definitions get converted to RPC-style procedure names, but
* otherwise this is really just a wrapper around the core xmlrpc server.
* These procedures are renamed as <resource>.<method>. So the node
* resource's retrieve method has an XMLRPC procedure name of node.retrieve,
* the user resource's login action has an XMLRPC procedure name of
* user.login, etc.
*/

/**
* Implementation of hook_server_info().
*/
Expand Down Expand Up @@ -42,7 +43,7 @@ function xmlrpc_server_xmlrpc() {
if (!empty($resources)) {
// Translate all resources
foreach ($resources as $name => $def) {
foreach (_xmlrpc_server_resources_as_procedures($def) as $method) {
foreach (services_resources_as_procedures($def) as $method) {
$callbacks[$method['method']] = 'xmlrpc_server_call_wrapper';
}
}
Expand Down Expand Up @@ -90,69 +91,3 @@ function xmlrpc_server_call_wrapper() {
}
}
}

/**
* Convert a resource to XMLRPC-style methods.
*
* @param array $resource
* A resource definition.
*
* @return array
* An array of XMLRPC method definitions
*/
function _xmlrpc_server_resources_as_procedures($resource) {
static $controllers = array(
'create' => 'create',
'delete' => 'delete',
'retrieve' => 'retrieve',
'update' => 'update',
'index' => 'index',
), $subcontrollers = array(
'relationships' => 'related',
'targeted actions' => 'targeted_action',
);

$methods = array();

foreach ($controllers as $attr => $name) {
if (isset($resource[$attr])) {
$methods[] = _xmlrpc_server_resource_controller_as_procedure($resource['name'], $name, $resource[$attr]);
}
}

foreach ($subcontrollers as $attr => $name) {
if (isset($resource[$attr])) {
foreach ($resource[$attr] as $sc_name => $controller) {
$methods[] = _xmlrpc_server_resource_controller_as_procedure($resource['name'], $name .'_'. $sc_name, $controller);
}
}
}

if (isset($resource['actions'])) {
foreach ($resource['actions'] as $sc_name => $controller) {
$methods[] = _xmlrpc_server_resource_controller_as_procedure($resource['name'], 'action_'. $sc_name, $controller);
}
}

return $methods;
}

/**
* Helper function for _xmlrpc_server_resources_as_procedures() that turns a resource
* controller into an XMLRPC method.
*
* @param $resource
* The resource being converted (node, user, etc.)
* @param $name
* The method name (retrieve, create, etc.)
* @param $controller
* Associative array defining the method's properties and callbacks.
*
*/
function _xmlrpc_server_resource_controller_as_procedure($resource, $name, $controller) {
$method = array_merge($controller, array(
'method' => $resource .'.'. $name,
));

return $method;
}
51 changes: 51 additions & 0 deletions services.module
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,54 @@ function services_controller_get($name, $endpoint) {
}
}
}

/**
* Convert a resource to RPC-style methods.
*
* @param array $resource
* A resource definition.
*
* @return array
* An array of RPC method definitions
*/
function services_resources_as_procedures($resource) {
static $controllers = array('create', 'retrieve', 'update', 'delete', 'index');
static $subcontrollers = array('actions', 'relationships', 'targeted actions');

$methods = array();

foreach ($controllers as $name) {
if (isset($resource[$name])) {
$methods[] = _services_resource_controller_as_procedure($resource['name'], $name, $resource[$name]);
}
}

foreach ($subcontrollers as $name) {
if (isset($resource[$name])) {
foreach ($resource[$name] as $sc_name => $controller) {
$methods[] = _services_resource_controller_as_procedure($resource['name'], $sc_name, $controller);
}
}
}

return $methods;
}
/**
* Helper function for _services_resources_as_procedures() that turns a resource
* controller into an RPC method.
*
* @param $resource
* The resource being converted (node, user, etc.)
* @param $name
* The method name (retrieve, create, etc.)
* @param $controller
* Associative array defining the method's properties and callbacks.
*
*/
function _services_resource_controller_as_procedure($resource, $name, $controller) {
$method = array_merge($controller, array(
'method' => $resource . '.' . $name,
));

return $method;
}

0 comments on commit cc7005a

Please sign in to comment.