You are here

function _services_resource_as_services in Services 6.2

Same name and namespace in other branches
  1. 7 services.resource-translation.inc \_services_resource_as_services()

Returns the given resource as a set of services methods.

Parameters

array $resource: A resource definition.

Return value

array An array of services method definitions

1 call to _services_resource_as_services()
services_get_all in ./services.module
Get all service definitions

File

./services.resource-translation.inc, line 18
Contains the necessary functionality for translating resources to services methods and vice versa.

Code

function _services_resource_as_services($resource) {
  static $controllers = array(
    'create' => 'create',
    'delete' => 'delete',
    'retrieve' => 'retrieve',
    'update' => 'update',
    'index' => 'index',
  ), $subcontrollers = array(
    'relationships' => 'related',
    'targeted actions' => 'targeted_action',
  );
  $methods = array();
  $file = isset($resource['file']) ? $resource['file'] : array();
  foreach ($controllers as $attr => $name) {
    if (isset($resource[$attr])) {
      $methods[] = _services_resource_controller_as_service($resource['name'], $name, $resource[$attr], $file);
    }
  }
  foreach ($subcontrollers as $attr => $name) {
    if (isset($resource[$attr])) {
      foreach ($resource[$attr] as $sc_name => $controller) {
        $methods[] = _services_resource_controller_as_service($resource['name'], $name . '_' . $sc_name, $controller, $file);
      }
    }
  }
  if (isset($resource['actions'])) {
    foreach ($resource['actions'] as $sc_name => $controller) {
      $methods[] = _services_resource_controller_as_service($resource['name'], 'action_' . $sc_name, $controller, $file);
    }
  }
  return $methods;
}