function _xmlrpc_example_server_subtract in xmlrpc 8
This is the callback for the xmlrpc_example.subtract xmlrpc method.
Return the difference of the two arguments, or an error if the result is out of the configured limits.
Parameters
int $num1: First number.
int $num2: Second number.
Return value
int|object The difference of the two arguments, or error if it is not in server defined bounds.
See also
Related topics
1 string reference to '_xmlrpc_example_server_subtract'
- xmlrpc_example_xmlrpc in xmlrpc_example/
xmlrpc_example.module - Implements hook_xmlrpc().
File
- xmlrpc_example/
xmlrpc_example.module, line 170 - Module file for xmlrpc_example module.
Code
function _xmlrpc_example_server_subtract($num1, $num2) {
$difference = $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 ($difference > $max) {
return xmlrpc_error(10001, t('Result is above the upper limit (@max) defined by the server.', [
'@max' => $max,
]));
}
if ($difference < $min) {
return xmlrpc_error(10002, t('Result is below the lower limit (@min) defined by the server.', [
'@min' => $min,
]));
}
// Otherwise return the result.
return $difference;
}