You are here

function _xmlrpc_example_server_add in xmlrpc 8

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.

The following code for the server is optional if the callbacks already exist. A server may implement methods associated to callbacks like node_load(), config() or any other existing function (php functions as well).

If the callbacks associated to the methods don't exist they must be created. This implementation requires two specific callbacks:

Parameters

int $num1: The first number to be summed.

int $num2: The second number to be summed.

Return value

int|object 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 133
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.
  $config = \Drupal::config('xmlrpc_example.server');
  $max = $config
    ->get('max');
  $min = $config
    ->get('min');
  if ($sum > $max) {
    return xmlrpc_error(10001, t('Result is over the upper limit (@max) defined by the server.', [
      '@max' => $max,
    ]));
  }
  if ($sum < $min) {
    return xmlrpc_error(10002, t('Result is below the lower limit defined by the server (@min).', [
      '@min' => $min,
    ]));
  }

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