You are here

function _services_resource_as_services in Services 7

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

@author Services Dev Team @file Provides a CRUD functions for services.

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

File

./services.resource-translation.inc, line 7
@author Services Dev Team

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