function _services_process_resource in Services 6.2
Same name and namespace in other branches
- 7 services.module \_services_process_resource()
Processes a resource and adds its controllers to the controllers array.
Parameters
string $name: The name of the resource.
array $resource: The resource definition.
array $controllers: An array (passed by reference) that will be populated with the controllers of the passed resources.
1 call to _services_process_resource()
- services_process_resources in ./
services.module - Processes passed resources and adds controllers to the controller array.
File
- ./
services.module, line 608 - Provides a generic but powerful API for exposing web services.
Code
function _services_process_resource($name, &$resource, &$controllers) {
$path = join($name, '/');
$resource['name'] = $path;
$keys = array(
'retrieve',
'create',
'update',
'delete',
);
foreach ($keys as $key) {
if (isset($resource[$key])) {
$controllers[$path . '/' . $key] =& $resource[$key];
}
}
if (isset($resource['index'])) {
$controllers[$path . '/index'] =& $resource['index'];
}
if (isset($resource['relationships'])) {
foreach ($resource['relationships'] as $relname => $rel) {
// Run some inheritance logic
if (isset($resource['retrieve'])) {
if (empty($rel['args']) || $rel['args'][0]['name'] !== $resource['retrieve']['args'][0]['name']) {
array_unshift($rel['args'], $resource['retrieve']['args'][0]);
}
$resource['relationships'][$relname] = array_merge($resource['retrieve'], $rel);
}
$controllers[$path . '/relationship/' . $relname] =& $resource['relationships'][$relname];
}
}
if (isset($resource['actions'])) {
foreach ($resource['actions'] as $actname => $act) {
// Run some inheritance logic
if (isset($resource['update'])) {
$up = $resource['update'];
unset($up['args']);
$resource['actions'][$actname] = array_merge($up, $act);
}
$controllers[$path . '/action/' . $actname] =& $resource['actions'][$actname];
}
}
if (isset($resource['targeted actions'])) {
foreach ($resource['targeted actions'] as $actname => $act) {
// Run some inheritance logic
if (isset($resource['update'])) {
if (empty($act['args']) || $act['args'][0]['name'] !== $resource['update']['args'][0]['name']) {
array_unshift($act['args'], $resource['update']['args'][0]);
}
$resource['targeted actions'][$actname] = array_merge($resource['update'], $act);
}
$controllers[$path . '/targeted_action/' . $actname] =& $resource['actions'][$actname];
}
}
}