You are here

function _xmlrpc_example_server_add in Examples for Developers 7

Same name and namespace in other branches
  1. 6 xmlrpc_example/xmlrpc_example.module \_xmlrpc_example_server_add()

This is the callback for the xmlrpc_example.add method.

Sum the two arguments and return value or an error if the result is out of the configured limits.

Parameters

int|float $num1: The first number to be summed.

int|float $num2: The second number to be summed.

Return value

int|float The sum of the arguments, or error if it is not in server defined bounds.

See also

xmlrpc_error()

Related topics

1 string reference to '_xmlrpc_example_server_add'
xmlrpc_example_xmlrpc in xmlrpc_example/xmlrpc_example.module
Implements hook_xmlrpc().

File

xmlrpc_example/xmlrpc_example.module, line 230
Module file for xmlrpc_example module.

Code

function _xmlrpc_example_server_add($num1, $num2) {
  $sum = $num1 + $num2;

  // If result is not within maximum and minimum limits,
  // return corresponding error.
  $max = variable_get('xmlrpc_example_server_max', 10);
  $min = variable_get('xmlrpc_example_server_min', 0);
  if ($sum > $max) {
    return xmlrpc_error(10001, t('Result is over the upper limit (@max) defined by the server.', array(
      '@max' => $max,
    )));
  }
  if ($sum < $min) {
    return xmlrpc_error(10002, t('Result is below the lower limit defined by the server (@min).', array(
      '@min' => $min,
    )));
  }

  // Otherwise return the result.
  return $sum;
}