You are here

function _services_process_resource in Services 7

Same name and namespace in other branches
  1. 6.2 services.module \_services_process_resource()
1 call to _services_process_resource()
services_process_resources in ./services.module

File

./services.module, line 461
@author Services Dev Team

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];
    }
  }
}