protected function RESTServer::getControllerArgumentsFromSources in Services 7.3
array $controller Controller definition array $sources Array of sources for arguments. Consists of following elements: 'path' - path requested 'params' - GET variables 'data' - parsed POST data 'headers' - request headers
Return value
array
2 calls to RESTServer::getControllerArgumentsFromSources()
- MockRESTServer::protectedGetControllerArgumentsFromSources in servers/
rest_server/ tests/ rest_server_mock_classes.inc - RESTServer::getControllerArguments in servers/
rest_server/ includes/ RESTServer.inc - Parses controller arguments from request
File
- servers/
rest_server/ includes/ RESTServer.inc, line 304 - Class for handling REST calls.
Class
- RESTServer
- @file Class for handling REST calls.
Code
protected function getControllerArgumentsFromSources($controller, $sources) {
$arguments = array();
if (!isset($controller['args'])) {
return array();
}
foreach ($controller['args'] as $argument_number => $argument_info) {
// Fill in argument from source
if (isset($argument_info['source'])) {
$argument_source = $argument_info['source'];
if (is_array($argument_source)) {
$argument_source_keys = array_keys($argument_source);
$source_name = reset($argument_source_keys);
$argument_name = $argument_source[$source_name];
// Path arguments can be only integers. i.e.'path' => 0 and not 'path' => '0'.
if ($source_name == 'path') {
$argument_name = (int) $argument_name;
}
if (isset($sources[$source_name][$argument_name])) {
$arguments[$argument_number] = $sources[$source_name][$argument_name];
}
}
else {
if (isset($sources[$argument_source])) {
$arguments[$argument_number] = $sources[$argument_source];
}
}
// Convert to specific data type.
if (isset($argument_info['type']) && isset($arguments[$argument_number])) {
switch ($argument_info['type']) {
case 'array':
$arguments[$argument_number] = (array) $arguments[$argument_number];
break;
}
}
}
// When argument isn't set, insert default value if provided or
// throw a exception if the argument isn't optional.
if (!isset($arguments[$argument_number])) {
if (!isset($argument_info['optional']) || !$argument_info['optional']) {
// Send 401 on error for backward compatibility.
// To override this behavior with the more appropriate http status
// code 400 Bad Request, add this to settings.php:
// $conf['services_deprecated_missing_arg_code'] = 400;
//
// @see See https://www.drupal.org/node/2880909
return services_error(t('Missing required argument @arg', array(
'@arg' => $argument_info['name'],
)), variable_get('services_deprecated_missing_arg_code', 401));
}
// Set default value or NULL if default value is not set.
$arguments[$argument_number] = isset($argument_info['default value']) ? $argument_info['default value'] : NULL;
}
}
return $arguments;
}